npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@infinitered/react-native-mlkit-object-detection

v5.0.0

Published

Expo module for MLKit Object Detection

Readme

@infinitered/react-native-mlkit-object-detection

Check the friendly docs here! 📖

Getting Started

This is an expo module that lets you use the MLKit Object Detection library in your Expo app.

Installation

Install like any other npm package:

#yarn
yarn add @infinitered/react-native-mlkit-object-detection

#npm
npm install @infinitered/react-native-mlkit-object-detection

Basic Usage

1. Set up the model context provider

Use the useObjectDetectionModels hook to load your models, and useObjectDetectionProvider to get the provider component. This will make the models available via React context.

/// App.tsx
import {
  ObjectDetectionConfig,
  CustomObjectDetectorOptions,
  useObjectDetectionModels,
  useObjectDetectionProvider,
} from "@infinitered/react-native-mlkit-object-detection";

// Define your custom models if needed (see "Using a Custom Model" for more details)
const MODELS: ObjectDetectionConfig = {
  furnitureDetector: {
    model: require("./assets/models/furniture-detector.tflite"),
  },
// You can add multiple custom models
  birdDetector: {
    model: require("./assets/models/bird-detector.tflite"),
// and override the default options
    options: {
      shouldEnableClassification: true,
      shouldEnableMultipleObjects: true,
      detectorMode: "singleImage",
      classificationConfidenceThreshold: 0.5,
      maxPerObjectLabelCount: 3
    }
  },
};

// Export this type so we can use it with our hooks later
export type MyModelsConfig = typeof MODELS;

function App() {
// Load the models
  const models = useObjectDetectionModels<MyModelsConfig>({
    assets: MODELS,
    loadDefaultModel: true, // whether to load the default model
    defaultModelOptions: {
      shouldEnableMultipleObjects: true,
      shouldEnableClassification: true,
      detectorMode: "singleImage",
    },
  });

// Get the provider component
  const { ObjectDetectionModelProvider } = useObjectDetectionProvider(models);

  return (
    <ObjectDetectionModelProvider>
      {/* Rest of your app */}
    </ObjectDetectionModelProvider>
  );
}

2. Use the models in your components

The models are made available through the context system. You can access them in your components using the same hook

// MyComponent.tsx
import {
  useObjectDetection,
  ObjectDetectionObject,
} from "@infinitered/react-native-mlkit-object-detection";
import React, { useEffect, useState } from "react";
import { View } from "react-native";
import type { MyModelsConfig } from "./App";

type Props = {
  imagePath: string;
};

function MyComponent({ imagePath }: Props) {
// Get the model from context
  const detector = useObjectDetection<MyModelsConfig>("birdDetector");

  const [detectedObjects, setDetectedObjects] = useState<ObjectDetectionObject[]>([]);

  useEffect(() => {
    async function detectObjects(imagePath: string) {
      if (!detector) return;

      try {
        const detectionResults = await detector.detectObjects(imagePath);
        setDetectedObjects(detectionResults);
      } catch (error) {
        console.error("Error detecting objects:", error);
      }
    }

    // Call detectObjects with your image path
    if (imagePath) {
      detectObjects(imagePath);
    }

  }, [detector, imagePath]);

  return (
    <View>
      {detectedObjects.map((detectedObject, index) => (
        <View key={index}>
          {/* Render your detection results */}
          {JSON.stringify(detectedObject)}
        </View>
      ))}
    </View>
  );
}

Model Options

The ObjectDetectorOptions and CustomObjectDetectorOptions interfaces support the following options:

interface ObjectDetectorOptions {
  shouldEnableClassification?: boolean; // Enable object classification
  shouldEnableMultipleObjects?: boolean; // Allow detection of multiple objects
  detectorMode?: "singleImage" | "stream"; // Detection mode
}

interface CustomObjectDetectorOptions extends ObjectDetectorOptions {
  classificationConfidenceThreshold?: number; // Minimum confidence for classification
  maxPerObjectLabelCount?: number; // Maximum number of labels per object
}

Detection Results

The detectObjects method returns an array of ObjectDetectionObject objects. Each object contains the following properties:

interface ObjectDetectionObject {
  frame: {
    origin: { x: number; y: number };
    size: { x: number; y: number };
  };
  labels: Array<{
    text: string;
    confidence: number;
    index: number;
  }>;
  trackingID?: number;
}