VisionCamera Frame Processor Plugin to label images using MLKit Vision

Overview

vision-camera-image-labeler

A VisionCamera Frame Processor Plugin to label images using MLKit Vision Image Labeling.

Installation

npm install vision-camera-image-labeler
cd ios && pod install

Add the plugin to your babel.config.js:

module.exports = {
  plugins: [
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__labelImage'],
      },
    ],

    // ...

Note: You have to restart metro-bundler for changes in the babel.config.js file to take effect.

Usage

import { labelImage } from "vision-camera-image-labeler";

// ...

const frameProcessor = useFrameProcessor((frame) => {
  'worklet';
  const labels = labelImage(frame);
}, []);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Comments
  • Fix and upgrade example app

    Fix and upgrade example app

    This PR fixes some issues that lead to the example app not running properly on Android (and maybe also on iOS?). It also includes some dependency updates and changes that were recently added to the create-react-native-library template.

    Unfortunately I don't have time to go into details about the individual changes right now, but the commits should do an okay job of highlighting all changes.

    Currently the frame processor itself isn't working (at least on Android, I couldn't test iOS) and throws an error:

    Frame Processor threw an error: Value is undefined, expected an Object
    

    Trying to console.log() the frame object throws

    Frame Processor threw an error: Exception in HostObject::get(propName:bytesPerRow): java.lang.NoSuchMethodError: no non-static method "Landroidx/camera/core/SettableImageProxy;.getPlanes()[Ljava/lang/Object;"
    

    so maybe that gives some indication what the issue is.

    I marked the PR as a draft because I'm unsure whether this is an issue with the plugin implementation, the example app or frame processors on Android in general.

    Still to do

    • [x] Fix issue described above
    • [x] ~~Complete VisionCamera setup on iOS (Set Deployment Target to >= 11.0, Swift Version to >= 5.2)~~
    • [x] Update pods for iOS (yarn pods)
    • [x] Test if example works on iOS
    opened by yfunk 17
  • Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method

    Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"

    On Android Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;" is thrown with every tick of the frameProcessor.

    Device: Pixel 4a.

    Logcat:

    2021-08-03 12:16:58.546 13182-13392/com.supervaisor.dashcam.staging E/VisionCamera: Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
    2021-08-03 12:16:58.547 13182-13283/com.supervaisor.dashcam.staging E/ReactNativeJS: Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
    2021-08-03 12:16:58.800 987-987/? W/SoloThreadMana: type=1400 audit(0.0:717094): avc: denied { search } for name="camera" dev="dm-12" ino=209 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:camera_vendor_data_file:s0 tclass=dir permissive=0
    2021-08-03 12:16:58.984 1753-2127/? D/ConnectivityService: NetReassign [no changes]
    2021-08-03 12:16:59.000 987-987/? I/chatty: uid=1000(system) [email protected] identical 3 lines
    2021-08-03 12:16:59.066 987-987/? W/SoloThreadMana: type=1400 audit(0.0:717098): avc: denied { search } for name="camera" dev="dm-12" ino=209 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:camera_vendor_data_file:s0 tclass=dir permissive=0
    2021-08-03 12:16:59.607 13182-13392/com.supervaisor.dashcam.staging I/HermesVM: JSI rethrowing JS exception: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
        
        Error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
            at __labelImage (native)
            at labelImage (JavaScript:1:48)
            at labelImage (native)
            at _f (JavaScript:1:77)
            at _f (native)
            at _f (JavaScript:1:425)
            at _f (native)
    2021-08-03 12:16:59.608 13182-13392/com.supervaisor.dashcam.staging I/chatty: uid=10390(com.supervaisor.dashcam.staging) pool-22-thread- identical 2 lines
    2021-08-03 12:16:59.608 13182-13392/com.supervaisor.dashcam.staging I/HermesVM: JSI rethrowing JS exception: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
        
        Error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
            at __labelImage (native)
            at labelImage (JavaScript:1:48)
            at labelImage (native)
            at _f (JavaScript:1:77)
            at _f (native)
            at _f (JavaScript:1:425)
            at _f (native)
    2021-08-03 12:16:59.609 13182-13392/com.supervaisor.dashcam.staging E/VisionCamera: Frame Processor threw an error: Exception in HostFunction: java.lang.NoSuchMethodError: no non-static method "Lcom/facebook/react/bridge/ReadableArray;.toArrayList()[Ljava/lang/Object;"
    
    opened by Kypsis 7
  • Implementing Custom model?

    Implementing Custom model?

    HI - I've been trying to work on implementing a custom model using this plugin - but having some issues and maybe you could assist?

    Using this- https://developers.google.com/ml-kit/vision/image-labeling/custom-models/ios

    I created a custom model with https://www.tensorflow.org/lite/tutorials/model_maker_image_classification

    I trying parsing together the implementation with the custom models/ios - but having issues.

    Appreciate the plugin and would love some insight into adding the custom models!

    opened by cmd08010 4
  • chore: attempt to fix Example app on iOS

    chore: attempt to fix Example app on iOS

    This PR attempt to fix iOS Example app build. So far I was able to fix XCode errors and build, however the Metro fails to build/detect the app right now. Further work and debug is required.

    Changes included in this PR:

    • Swift bumped from 5.0 to 5.2 and target updated to iOS 11.0 (as described in Vision Camera Troubleshooting - https://mrousavy.github.io/react-native-vision-camera/docs/guides/troubleshooting/#ios)
    • removed tvOS targets from XCode Workspace
    • File.swift moved to the XCode Workspace
    • added missing babel-plugin-module-resolver dependency
    • updated used Vision Camera to fix on of XCode errors (usePixelAspecRatio)
    • regenerated Pods

    Currently the example iOS app build correctly, but Metro fails to detect/build the React app inside.

    opened by Simek 3
  • Android build error coming from react-native-vision-camera

    Android build error coming from react-native-vision-camera

    Hi

    I was trying to build the example code from this repo and got the following error which seems to come from the react-native-vision-camera module

    > Task :react-native-vision-camera:externalNativeBuildDebug
    Build VisionCamera_armeabi-v7a
    ninja: Entering directory `Z:\Projects\vision-camera-image-labeler\example\node_modules\react-native-vision-camera\android\.cxx\cmake\debug\armeabi-v7a'
    In file included from ../../../../src/main/cpp/java-bindings/JHashMap.cpp:5:
    ../../../../src/main/cpp/java-bindings/JHashMap.h:16:8: error: redefinition of 'JHashMap'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator.h:170:8: note: previous definition is here
    ../../../../src/main/cpp/java-bindings/JHashMap.cpp:15:43: error: redefinition of 'create'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator-inl.h:230:42: note: previous definition is here
    In file included from ../../../../src/main/cpp/JSIJNIConversion.cpp:25:
    ../../../../src/main/cpp/java-bindings/JHashMap.h:16:8: error: redefinition of 'JHashMap'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator.h:170:8: note: previous definition is here
    
    > Task :react-native-vision-camera:externalNativeBuildDebug FAILED
    61 actionable tasks: 10 executed, 51 up-to-date
    
    FAILURE: Build failed with an exception.
    

    and futher in the error stack

      ../../../../src/main/cpp/java-bindings/JHashMap.h:16:8: error: redefinition of 'JHashMap'
      struct JHashMap : JavaClass<JHashMap<K, V>, JMap<K, V>> {
             ^
      ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator.h:170:8: note: previous definition is here
      struct JHashMap : JavaClass<JHashMap<K, V>, JMap<K, V>> {
             ^
      1 error generated.
      [8/10] Building CXX object CMakeFiles/VisionCamera.dir/src/main/cpp/VisionCamera.cpp.o
      [9/10] Building CXX object CMakeFiles/VisionCamera.dir/src/main/cpp/FrameProcessorRuntimeManager.cpp.o
      ninja: build stopped: subcommand failed.
    

    Any known compatibility issue between this example app and the source module?

    Thanks!

    opened by pot2mayo 2
  • Update Fix MLKit import not found need to add to current version :)

    Update Fix MLKit import not found need to add to current version :)

    https://github.com/mrousavy/vision-camera-image-labeler/commit/68a9a8301acc71b6805816af3476bc029f05accf Good afternoon @mrousavy , I'm notice that the commit above not in current version when I install package (v0.1.5), Please update in new version, Thanks man!

    opened by NguyenPhatBG 1
  • Module MLKit not found

    Module MLKit not found

    In VisionCameraImageLabeler.m Xcode complains about Module 'MLKit' not found on line 13 @import MLKit;. If you delete that import the build fails at the very end with: duplicate symbol '_OBJC_CLASS_$_CameraViewManager' in: /Users/harrysild/Library/Developer/Xcode/DerivedData/Dashcam-cujsxchigczhdvbgfkjhdhokpctr/Build/Intermediates.noindex/Dashcam.build/StagingDebug-iphoneos/Dashcam.build/Objects-normal/arm64/CameraViewManager-e2616307afa5333b3b6da1885b39637cff4d06f18eed5d8b3bc0e505c1525a74.o /Users/harrysild/Library/Developer/Xcode/DerivedData/Dashcam-cujsxchigczhdvbgfkjhdhokpctr/Build/Products/StagingDebug-iphoneos/VisionCamera/libVisionCamera.a(CameraViewManager-6de0dcf57a6e5b176e919ac2555340718db92047184fdb2efecb0f346968c41a.o) duplicate symbol '_OBJC_METACLASS_$_CameraViewManager' in: /Users/harrysild/Library/Developer/Xcode/DerivedData/Dashcam-cujsxchigczhdvbgfkjhdhokpctr/Build/Intermediates.noindex/Dashcam.build/StagingDebug-iphoneos/Dashcam.build/Objects-normal/arm64/CameraViewManager-e2616307afa5333b3b6da1885b39637cff4d06f18eed5d8b3bc0e505c1525a74.o /Users/harrysild/Library/Developer/Xcode/DerivedData/Dashcam-cujsxchigczhdvbgfkjhdhokpctr/Build/Products/StagingDebug-iphoneos/VisionCamera/libVisionCamera.a(CameraViewManager-6de0dcf57a6e5b176e919ac2555340718db92047184fdb2efecb0f346968c41a.o) ld: 2 duplicate symbols for architecture arm64

    opened by Kypsis 1
  • java.lang.IllegalStateException: Task is not yet complete

    java.lang.IllegalStateException: Task is not yet complete

    When trying to run the plugin I get Frame Processor threw an error: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete every tick of the frameProcessor on Android. Looks like async error?

    Device is Pixel 4a.

    Logcat:

    2021-08-02 19:48:28.469 22920-23204/com.supervaisor.dashcam.staging E/VisionCamera: Frame Processor threw an error: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
    2021-08-02 19:48:28.471 22920-23028/com.supervaisor.dashcam.staging E/ReactNativeJS: Frame Processor threw an error: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
    2021-08-02 19:48:29.112 987-987/? W/SoloThreadMana: type=1400 audit(0.0:711721): avc: denied { search } for name="camera" dev="dm-12" ino=209 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:camera_vendor_data_file:s0 tclass=dir permissive=0
    2021-08-02 19:48:29.312 987-987/? I/chatty: uid=1000(system) [email protected] identical 3 lines
    2021-08-02 19:48:29.379 987-987/? W/SoloThreadMana: type=1400 audit(0.0:711725): avc: denied { search } for name="camera" dev="dm-12" ino=209 scontext=u:r:hal_camera_default:s0 tcontext=u:object_r:camera_vendor_data_file:s0 tclass=dir permissive=0
    2021-08-02 19:48:29.471 22920-23204/com.supervaisor.dashcam.staging I/HermesVM: JSI rethrowing JS exception: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
        Error: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
            at __labelImage (native)
            at labelImage (JavaScript:1:48)
            at labelImage (native)
            at _f (JavaScript:1:77)
            at _f (native)
    2021-08-02 19:48:29.472 22920-23204/com.supervaisor.dashcam.staging I/chatty: uid=10390(com.supervaisor.dashcam.staging) pool-22-thread- identical 1 line
    2021-08-02 19:48:29.472 22920-23204/com.supervaisor.dashcam.staging I/HermesVM: JSI rethrowing JS exception: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
        Error: Exception in HostFunction: java.lang.IllegalStateException: Task is not yet complete
            at __labelImage (native)
            at labelImage (JavaScript:1:48)
            at labelImage (native)
            at _f (JavaScript:1:77)
            at _f (native)
    
    opened by Kypsis 1
  • Upgrading the MLKit library to the one in the official documentation

    Upgrading the MLKit library to the one in the official documentation

    opened by alexeibostan 0
  • App crash after installing plugin

    App crash after installing plugin

    Hi, After installing this Plugin my android app crashes with "Didn't find class "com.google.mlkit.vision.common.internal.Detector"" Message

    opened by netin1202 0
  • Image labs is not working in iOS

    Image labs is not working in iOS

    opened by DeepikaSharma5 0
  • Error building for Android

    Error building for Android

    Hi, I've just cloned the master branch and run the following commands on Windows:

    cd example
    yarn
    yarn run android
    

    And got the following compilation error:

    In file included from ../../../../src/main/cpp/java-bindings/JHashMap.cpp:5:
    ../../../../src/main/cpp/java-bindings/JHashMap.h:16:8: error: redefinition of 'JHashMap'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator.h:170:8: note: previous definition is here
    ../../../../src/main/cpp/java-bindings/JHashMap.cpp:15:43: error: redefinition of 'create'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator-inl.h:230:42: note: previous definition is here
    In file included from ../../../../src/main/cpp/JSIJNIConversion.cpp:25:
    ../../../../src/main/cpp/java-bindings/JHashMap.h:16:8: error: redefinition of 'JHashMap'
    ../../../../build/fbjni-0.3.0-headers.jar\fbjni/detail/Iterator.h:170:8: note: previous definition is here
    

    Not sure what to do... Thanks in advance for your help!

    opened by obasille 0
  • Image labelling not working on iOS

    Image labelling not working on iOS

    So I tested example app on iOS 15 iPhone 12 and it's not working properly. Results are always same:

    • sky
    • pattern
    • curtain

    Results have nothing to do with what's in the camera frame. From logs I get this in xcode: [WARNING]The specified colorspace format is not supported. Falling back on Libyuv.

    opened by mrados7 9
  • Error while running the example on android devices.....

    Error while running the example on android devices.....

    Hello!!!

    Was just trying to run the example - vision-camera-image-labeler on an android device, getting the below error after running the command,

    react-native run-android

    Can you please let me know what the error could be related to?

    FAILURE: Build failed with an exception.

    • What went wrong: A problem occurred configuring project ':react-native-vision-camera'.

    com.android.builder.errors.EvalIssueException: NDK at C:\xxxx\AppData\Local\Android\Sdk\ndk\20.1.5948944 did not have a source.properties file

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    • Get more help at https://help.gradle.org

    BUILD FAILED in 20s

    Error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

    FAILURE: Build failed with an exception.

    • What went wrong: A problem occurred configuring project ':react-native-vision-camera'.

    com.android.builder.errors.EvalIssueException: NDK at C:\xxxxxxxxxxxx\20.1.5948944 did not have a source.properties file

    opened by vineethdas 4
  • Question: how to initialize ImageLabeling client with different options

    Question: how to initialize ImageLabeling client with different options

    i want to initialize the labeler client with different args

    https://github.com/mrousavy/vision-camera-image-labeler/blob/cbf88a545e2aabcbc97aaf2717617ef1e0a69aa9/android/src/main/java/com/visioncameraimagelabeler/VisionCameraImageLabelerPlugin.java#L25

    but since the plugin uses callback method to receive javascript params, and do that in a frame loop. i don't how to do that,

    https://github.com/mrousavy/vision-camera-image-labeler/blob/cbf88a545e2aabcbc97aaf2717617ef1e0a69aa9/android/src/main/java/com/visioncameraimagelabeler/VisionCameraImageLabelerPlugin.java#L28

    can someone walk me through a solution for that?

    opened by rodgomesc 1
Releases(v0.1.6)
Owner
Marc Rousavy
they call me ranch cause I be dressing
Marc Rousavy
Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.

Table of Contents Introduction Cloning Repository Quick Start Gradle and Maven Building from Source Dependencies Help/Contact Introduction BoofCV is a

Peter Abeles 916 Jan 6, 2023
Roman Beskrovnyi 250 Jan 9, 2023
Creates ASCII art in Java from Images

Creates ASCII art in Java from Images. It can also save the ASCII art as image (.png) as well

Navjot Singh Rakhra 4 Jul 12, 2022
Million+ point universal gravity simulation using OpenGL and OpenCL

Universe Simulation on GPU A multi-million particle gravity simulation. The main program is org.davu.app.Space.main See each package.html for code det

David Uselmann 2 Jan 31, 2022
A VisionCamera Frame Processor Plugin to preform text detection on images using MLKit Vision Text Recognition

vision-camera-ocr A VisionCamera Frame Processor Plugin to preform text detection on images using MLKit Vision Text Recognition. Installation yarn add

Aaron Grider 133 Dec 19, 2022
:label: Tags customizadas no tab e acima da cabeça!

??️ PlayerTags Pluginzinho para adicionar tags customizadas no tablist e acima da cabeça do jogador. Por que? Por que fazer algo se já existem dezenas

null 4 Oct 9, 2022
📺 Streaming OBS video/Mjpeg into maps on item frames at a high frame rate

MakiScreen Mjpeg ?? Streaming OBS video/Mjpeg into maps on item frames at a high frame rate images taken on TotalFreedom: play.totalfreedom.me How doe

null 4 Apr 8, 2022
A client mod that changes the debug frame graphs to use a dark theme

Dark Graph A client mod that changes the debug frame graphs to use a dark theme. To access the frame graphs hold alt then press F3. If you are connect

null 3 Dec 19, 2022
Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.

Table of Contents Introduction Cloning Repository Quick Start Gradle and Maven Building from Source Dependencies Help/Contact Introduction BoofCV is a

Peter Abeles 916 Jan 6, 2023
Python wrapper around the BoofCV Computer Vision Library

PyBoof is Python wrapper for the computer vision library BoofCV. Since this is a Java library you will need to have java and javac installed. The form

Peter Abeles 44 Dec 30, 2022
MarioCash is a trust-based multi-dimensional blockchains built with a vision to connect everything and any blockchain networks.

MarioCash We will change the world by blockchain. What is mariocash? MARIOCASH is a trust-based multi-dimensional blockchains (branches) built with a

Brantley·Williams 23 Mar 10, 2022
Google's ML-Kit-Vision demo (android) for pre encoded video.

Android ML Kit Vision demo with Video Google's ML-Kit-Vision demo (android) for pre encoded video. Demos for camera preview and still image are also i

null 17 Dec 29, 2022
DnD Plugin submission using Atlas. Plugin inspired on the TrollGUI bukkit plugin

?? PunishGUI DnD Plugin submission using Atlas. Plugin inspired on the TrollGUI bukkit plugin ?? Dependencies ?? Paper 1.18 ?? Atlas ?? Commands /hell

null 1 Jan 19, 2022
An annotation processor for generating type-safe bean mappers

MapStruct - Java bean mappings, the easy way! What is MapStruct? Requirements Using MapStruct Maven Gradle Documentation and getting help Building fro

null 5.8k Dec 31, 2022
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included

Read full documentation at http://immutables.org // Define abstract value type using interface, abstract class or annotation @Value.Immutable public i

Immutables 3.2k Dec 31, 2022
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.

Derive4J: Java 8 annotation processor for deriving algebraic data types constructors, pattern matching and more! tl;dr Show me how to write, say, the

null 543 Nov 23, 2022
A streaming JsonPath processor in Java

JsonSurfer - Let's surf on Json! Why JsonSurfer Streaming No need to deserialize entire json into memory. JsonPath Selectively extract json data by th

null 256 Dec 12, 2022
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.

Derive4J: Java 8 annotation processor for deriving algebraic data types constructors, pattern matching and more! tl;dr Show me how to write, say, the

null 543 Nov 23, 2022
A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions

:>>> DEPRECATION NOTE <<<: Although still one of the most popular Markdown parsing libraries for the JVM, pegdown has reached its end of life. The pro

Mathias 1.3k Nov 24, 2022
A Java annotation processor used for automatically generating better builder codes.

BetterBuilder BetterBuilder is a Java annotation processor used for automatically generating better builder codes(builder design pattern), which can m

LEO D PEN 9 Apr 6, 2021