@masumdev/rn-camera-ai
Core camera preview component, permission handling, zero-JS overlay renderer, lifecycle hooks, and projection math engine.
@masumdev/rn-camera-ai forms a modular, production-ready computer vision and on-device AI ecosystem for React Native and Expo alongside optional adapter packages (@masumdev/rn-camera-ai-tflite and @masumdev/rn-camera-ai-mlkit). Install only the adapters your app uses, unifying hardware preview, on-device inference, and zero-JS-thread overlays.
Building production-grade real-time computer vision applications in React Native traditionally presents three severe architectural hurdles:
cover crop vs. contain letterbox) and front-camera selfie mirroring.@masumdev/rn-camera-ai solves these challenges by cleanly separating hardware preview, inference processing, and overlay rendering into decoupled, modular layers.
The monorepo ecosystem divides responsibilities across two dedicated packages and native runtime drivers:
┌────────────────────────────────────────────────────────────────────────┐│ Application Layer ││ (Expo Prebuild / React Native Mobile App) │└───────────────────┬────────────────────────────────┬───────────────────┘ │ │ ▼ ▼┌──────────────────────────────────────┐ ┌──────────────────────────────┐│ @masumdev/rn-camera-ai │ │ @masumdev/rn-camera-ai-tflite││ (Core Library) │ │ (Inference Adapter) ││ - CameraAI Component │ │ - TFLiteObjectDetector ││ - DetectionOverlay (Zero-JS Worklet)│◄─┼─ - TFLiteFaceRecognizer ││ - 468 Face Mesh Wireframe Overlay │ │ (BlazeFace + Mesh + MobileFaceNet)│ - Normalized Math Engine [0..1] │ │ - Hardware Delegate Fallback││ - Pluggable CameraProcessor API │ │ - 4-Tensor SSD/EffDet Parser│└──────────────────────────────────────┘ └──────────────────────────────┘ ▲ ▲ │ │┌───────────────────┴────────────────────────────────┴───────────────────┐│ Native Driver & Nitro Acceleration ││ - react-native-vision-camera v5 (Nitro camera preview & FrameOutput) ││ - react-native-vision-camera-worklets + react-native-worklets ││ - react-native-fast-tflite v3 (Nitro C++ TensorFlow Lite runtime) ││ - react-native-nitro-image (HybridFrameConverter & GPU/CPU resize) │└────────────────────────────────────────────────────────────────────────┘Native Driver & Nitro Acceleration:
react-native-vision-camera (v5) manages low-level camera hardware, camera device enumeration, focus, exposure, and zero-latency preview/frame-output streaming.react-native-vision-camera-worklets and react-native-worklets allocate dedicated background worklet runtimes that execute frame outputs without blocking JavaScript execution.react-native-fast-tflite (v3) provides direct Nitro C++ bindings to TensorFlow Lite, executing neural network tensors with ArrayBuffer zero-copy overhead.react-native-nitro-image (HybridFrameConverter) handles upright frame conversion, resizing, and pixel format normalization (RGBA/BGRA to packed RGB uint8 buffers).Core Camera & Overlay Package (@masumdev/rn-camera-ai):
<CameraAI /> preview component.<DetectionOverlay /> using SharedValue<DetectionResult[]> for 60 FPS zero-JS-thread overlay rendering.Inference Adapter Package (@masumdev/rn-camera-ai-tflite):
CameraProcessor contract..tflite model binaries from asset bundles, local filesystem URIs, or remote URLs.android-gpu OpenCL/OpenGL ES/NNAPI) with automatic fallback to CPU.boxes, classes, scores, num_detections) into normalized coordinates.BlazeFace + FaceMesh + MobileFaceNet 192-D embeddings) with live biometric enrollment.In standard React Native architectures, pushing detection updates from a frame processor into JavaScript triggers a React state update (setState(detections)). This causes a full React render pass and style recalculation on every camera frame (15–60 times per second), choking the JS event loop:
Traditional Approach (JS Thread Bottleneck):[ Camera Frame ] ──> [ Frame Output ] ──(scheduleOnRN)──> [ React State Update ] ──> [ React Re-render ] ──> [ Screen Repaint ] ▲ High JS Thread Lag!With @masumdev/rn-camera-ai, detection results can be piped directly into a React Native Reanimated SharedValue:
Zero-JS-Thread Architecture:[ Camera Frame ] ──> [ Frame Processor Worklet ] ──> [ Reanimated SharedValue ] ──> [ UI Thread Direct Repaint ] │ └──> JS Thread remains 100% idle!Bounding boxes and labels are mapped directly on the UI thread via useAnimatedStyle, delivering buttery-smooth 60 FPS overlay tracking even under heavy CPU or network load.
Inference engines evolve rapidly. @masumdev/rn-camera-ai does not hardcode TensorFlow Lite or any specific vendor library. Instead, it defines a lean, universal CameraProcessor interface:
export interface CameraProcessor { readonly id?: string; readonly name?: string; readonly status: 'idle' | 'loading' | 'ready' | 'error'; readonly targetFps?: number; processFrame(frame: unknown): DetectionResult[]; initialize?(): Promise<void> | void; dispose?(): void;}Any machine learning engine — TensorFlow Lite, ONNX Runtime, MediaPipe, MLKit, or a custom C++ JSI module — can be plugged into <CameraAI processor={customProcessor} /> seamlessly.
[0..1]All bounding boxes across the system are represented in normalized relative coordinates between 0.0 and 1.0:
export interface BoundingBox { x: number; // Top-left horizontal coordinate [0, 1] y: number; // Top-left vertical coordinate [0, 1] width: number; // Width fraction [0, 1] height: number; // Height fraction [0, 1]}Because coordinates are independent of the sensor’s physical pixel count ($1920 \times 1080$, $1280 \times 720$, etc.) and the device’s display resolution ($390 \times 844$, $1080 \times 2400$, etc.), projection math remains completely decoupled. The library’s math engine handles:
cover crop vs. contain letterbox)x* = 1 - x - width)On Android, GPU delegates can fail on budget chipsets or corrupted vendor drivers. @masumdev/rn-camera-ai-tflite automatically catches GPU initialization exceptions and falls back gracefully to multi-threaded CPU inference without crashing the host application.
@masumdev/rn-camera-ai
Core camera preview component, permission handling, zero-JS overlay renderer, lifecycle hooks, and projection math engine.
@masumdev/rn-camera-ai-tflite
TensorFlow Lite adapter: Object Detection, 192-D Face Recognition, 468-Point 3D Face Mesh, and Hybrid Liveness Detection.
@masumdev/rn-camera-ai-mlkit
Google ML Kit v2 on-device OCR adapter supporting zero-copy YUV frames, Block/Line/Word granularity, and NIK/Email/Phone/URL extraction.