UNPKG

react-native-object-detection

Version:
31 lines (28 loc) 882 B
import { NativeModules } from 'react-native'; const { ObjectDetectionModule } = NativeModules; export interface DetectedObject { frame: { left: number; top: number; right: number; bottom: number; }; trackingID: number | null; labels: Array<{ text: string; confidence: number; }>; } /** * Starts object detection on the provided image * @param imagePath - The path to the image file (can be local or remote URL) * @returns Promise that resolves with an array of detected objects * @throws Error if image loading or detection fails */ export const startObjectDetection = (imagePath: string): Promise<DetectedObject[]> => { return new Promise((resolve, reject) => { ObjectDetectionModule.startObjectDetection(imagePath) .then((objects: DetectedObject[]) => resolve(objects)) .catch((error: Error) => reject(error)); }); };