Git Product home page Git Product logo

vision-camera-ocr's Introduction

vision-camera-ocr

A VisionCamera Frame Processor Plugin to preform text detection on images using MLKit Vision Text Recognition.

Installation

yarn add vision-camera-ocr
cd ios && pod install

Add the plugin to your babel.config.js:

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

    // ...

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 scannedOcr = scanOCR(frame);
}, []);

Data

scanOCR(frame) returns an OCRFrame with the following data shape. See the example for how to use this in your app.

 OCRFrame = {
   result: {
     text: string, // Raw result text
     blocks: Block[], // Each recognized element broken into blocks
   ;
};

The text object closely resembles the object documented in the MLKit documents. https://developers.google.com/ml-kit/vision/text-recognition#text_structure

The Text Recognizer segments text into blocks, lines, and elements. Roughly speaking:

a Block is a contiguous set of text lines, such as a paragraph or column,

a Line is a contiguous set of words on the same axis, and

an Element is a contiguous set of alphanumeric characters ("word") on the same axis in most Latin languages, or a character in others

Contributing

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

License

MIT

vision-camera-ocr's People

Contributors

aarongrider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vision-camera-ocr's Issues

Doesn't work in iOS

I tried the project in example folder, while it works in android, it always returns empty data in iOS, and shows this error in logs.

VisionCamera.captureOutput(_:didOutput:from:): The Frame Processor took so long to execute that a frame was dropped.

Issue with frameProcessor - TypeError: Cannot read property 'scanOCR' of undefined

I'm trying to use this frame processor, everything works fine, it scans the text, but, when i try to use the text, reanimated asks me to run the code on runOnJS, when i simply type.
import { runOnJS } from "react-native-reanimated";
The app crashes with this error.
TypeError: Cannot read property 'scanOCR' of undefined

This is the import order on the component:

import 'react-native-reanimated';
import { runOnJS } from "react-native-reanimated";
import { scanOCR } from "vision-camera-ocr";

Package Json

"react": "17.0.2",
"react-native": "0.65.1",
"vision-camera-ocr": "^1.0.0",
"react-native-vision-camera": "^2.12.0",
"react-native-reanimated": "^2.3.0-beta.2",

Build FAILURE

Hi !

I did exactly what you advised, completed the installation, and modified my babel.config.js, but my build crashes with this error:
`Execution failed for task ':tasks'.

Could not create task ':vision-camera-ocr:compileDebugAndroidTestKotlin'.
Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.`

If someone have any advice,
Thanks.

Cannot build android app

Hi,After installing the vision camera & vision camera OCR with the dependency package react-native reanimated, React-native reanimated throws a compile time error.

CMake Error at CMakeLists.txt:208 (find_package):
Could not find a package configuration file provided by
"react-native-reanimated" with any of the following names:

  react-native-reanimatedConfig.cmake
  react-native-reanimated-config.cmake

Add the installation prefix of "react-native-reanimated" to
CMAKE_PREFIX_PATH or set "react-native-reanimated_DIR" to a directory
containing one of the above files.  If "react-native-reanimated" provides a
separate development package or SDK, be sure it has been installed.

Screenshot 2023-10-04 at 10 18 34 AM

iOS build fail - How to update MLKitCommon version 8.0 in vision-camera-ocr?

My ios build is failing with this library. Android works fine.


"react-native": "0.70.6",
 "react-native-vision-camera": "^2.15.2",
    "vision-camera-ocr": "^1.0.0"
[!] CocoaPods could not find compatible versions for pod "MLKitCommon":
  In Podfile:
    MLKitCommon (from `MLKitCommon.podspec.json`)

    MLKitVision (from `MLKitVision.podspec.json`) was resolved to 4.2.0, which depends on
      MLKitCommon (~> 8.0)

    vision-camera-ocr (from `../node_modules/vision-camera-ocr`) was resolved to 1.0.0, which depends on
      GoogleMLKit/TextRecognition (= 2.2.0) was resolved to 2.2.0, which depends on
        GoogleMLKit/MLKitCore (= 2.2.0) was resolved to 2.2.0, which depends on
          MLKitCommon (~> 3.0.0)

pod file

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

target 'InstallerApp' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  pod 'FirebaseAppCheckInterop', :modular_headers => true
  pod 'FirebaseAuthInterop', :modular_headers => true
  pod 'FirebaseCoreExtension', :modular_headers => true
  pod 'GTMSessionFetcher', :modular_headers => true
  pod 'MLKitVision', :podspec => 'MLKitVision.podspec.json'
  pod 'MLKitCommon', :podspec => 'MLKitCommon.podspec.json'
  
  $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => FlipperConfiguration.enabled,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'InstallerAppTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Could you please suggest a workaround ?

Thanks

Expo ios build fails

Hi !
I'm having an issue when building an ios version with Expo SDK 48 (managed) and the eas build command (no issues with android after patching the gradle version).
The build fails at the "Run fastlane" section with this error :

The following build commands failed:
	SwiftEmitModule normal arm64 Emitting\ module\ for\ vision_camera_ocr (in target 'vision-camera-ocr' from project 'Pods')
(1 failure)
Exit status: 65

Does someone have an idea on how to fix this ?

V3 Vision Camera Update Patch File

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

updated code to align with vision camera V3. also added some missing data for the bounding box frame

actual patch file:
vision-camera-ocr+1.0.0.patch

Here is the diff that solved my problem:

diff --git a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
index 8ae6279..c15268d 100644
--- a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
+++ b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
@@ -14,8 +14,12 @@ import com.google.mlkit.vision.text.Text
 import com.google.mlkit.vision.text.TextRecognition
 import com.google.mlkit.vision.text.latin.TextRecognizerOptions
 import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
+import com.mrousavy.camera.frameprocessor.Frame
+import com.mrousavy.camera.types.Orientation
+import androidx.annotation.NonNull
+import androidx.annotation.Nullable
 
-class OCRFrameProcessorPlugin: FrameProcessorPlugin("scanOCR") {
+class OCRFrameProcessorPlugin(options: Map<String, Any>?): FrameProcessorPlugin(options) {
 
     private fun getBlockArray(blocks: MutableList<Text.TextBlock>): WritableNativeArray {
         val blockArray = WritableNativeArray()
@@ -88,6 +92,8 @@ class OCRFrameProcessorPlugin: FrameProcessorPlugin("scanOCR") {
         if (boundingBox != null) {
             frame.putDouble("x", boundingBox.exactCenterX().toDouble())
             frame.putDouble("y", boundingBox.exactCenterY().toDouble())
+            frame.putInt("left", boundingBox.left)
+            frame.putInt("top", boundingBox.top)
             frame.putInt("width", boundingBox.width())
             frame.putInt("height", boundingBox.height())
             frame.putInt("boundingCenterX", boundingBox.centerX())
@@ -96,7 +102,7 @@ class OCRFrameProcessorPlugin: FrameProcessorPlugin("scanOCR") {
         return frame
     }
 
-    override fun callback(frame: ImageProxy, params: Array<Any>): Any? {
+    override fun callback(frame: Frame, arguments: Map<String, Any>?): Any? {
 
         val result = WritableNativeMap()
 
diff --git a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/VisionCameraOcrPackage.kt b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/VisionCameraOcrPackage.kt
index beac2a1..1ec616a 100644
--- a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/VisionCameraOcrPackage.kt
+++ b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/VisionCameraOcrPackage.kt
@@ -8,8 +8,16 @@ import com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
 
 
 class VisionCameraOcrPackage : ReactPackage {
+
+    companion object {
+        init {
+          FrameProcessorPluginRegistry.addFrameProcessorPlugin("scanOCR") { options ->
+            OCRFrameProcessorPlugin(options)
+          }
+        }
+      }
+
     override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
-        FrameProcessorPlugin.register(OCRFrameProcessorPlugin())
         return emptyList()
     }
 
diff --git a/node_modules/vision-camera-ocr/lib/typescript/index.d.ts b/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
index 47f1816..a3b6c3f 100644
--- a/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
+++ b/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
@@ -2,6 +2,8 @@ import type { Frame } from 'react-native-vision-camera';
 declare type BoundingFrame = {
     x: number;
     y: number;
+    top: number;
+    left: number;
     width: number;
     height: number;
     boundingCenterX: number;
@@ -41,4 +43,5 @@ export declare type OCRFrame = {
  * Scans OCR.
  */
 export declare function scanOCR(frame: Frame): OCRFrame;
-export {};
+export { };
+
diff --git a/node_modules/vision-camera-ocr/src/index.tsx b/node_modules/vision-camera-ocr/src/index.tsx
index b4eeb76..9bb679f 100644
--- a/node_modules/vision-camera-ocr/src/index.tsx
+++ b/node_modules/vision-camera-ocr/src/index.tsx
@@ -1,9 +1,13 @@
 /* eslint-disable no-undef */
-import type { Frame } from 'react-native-vision-camera';
+import { Frame, VisionCameraProxy } from 'react-native-vision-camera';
+
+const plugin = VisionCameraProxy.initFrameProcessorPlugin('scanOCR')
 
 type BoundingFrame = {
   x: number;
   y: number;
+  top: number;
+  left: number;
   width: number;
   height: number;
   boundingCenterX: number;
@@ -46,8 +50,8 @@ export type OCRFrame = {
  * Scans OCR.
  */
 
-export function scanOCR(frame: Frame): OCRFrame {
+export function scanOCR(frame: Frame) {
   'worklet';
-  // @ts-ignore
-  return __scanOCR(frame);
+  if (!plugin) {throw new Error('Failed to load Frame Processor Plugin "scanFaces"!')}
+  return plugin.call(frame) 
 }

This issue body was partially generated by patch-package.

Text Recognition Bounds Units

Hello.
Currently I am using Text Recognition using react-native-camera library and it returns bounds for x, y coordinates which I can filter for limiting scan area, it works perfectly fine.

But vision-camera-ocr is giving me different coordinates for scanning in the same location in the camera. I have try to use pixel density for converting corner points to dp but that also seems wrong bounds.

Can anybody provide me the information about how can i filter the bounds for limiting the scan area or frame processors give the coordinates in which units.

I am stuck with this for many days, any help would be appreciated.

How to Reduce the size of camera source in mobile.

Text detection previews full screen to scan text. I want a small rectangle for text detection.
I want to reduce the area of camera preview and also i want to capture only the text within the area by the camera.
I have reduced the camera preview area. but the camera is capturing the full area and recognizing text..... I want only that text to be recognized which is within the preview.

Class 'OCRFrameProcessorPlugin' is not abstract and does not implement abstract base class member

I'm getting a build error with the latest vision-camera-ocr

RN-Vision-Camera 3.0.0-rc5
React Native 0.72.4

FULL DETAILS of the build failure, including information about my build environment:
https://scans.gradle.com/s/ygeaopffvyqfs

e: /home/matthew/dev/stackbayapp/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt: (18, 1): Class 'OCRFrameProcessorPlugin' is not abstract and does not implement abstract base class member public abstract fun callback(p0: Frame, p1: ReadableNativeMap?): Any? defined in com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
e: /home/matthew/dev/stackbayapp/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt: (18, 53): Too many arguments for public constructor FrameProcessorPlugin() defined in com.mrousavy.camera.frameprocessor.FrameProcessorPlugin
e: /home/matthew/dev/stackbayapp/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt: (99, 5): 'callback' overrides nothing
e: /home/matthew/dev/stackbayapp/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/VisionCameraOcrPackage.kt: (12, 30): Unresolved reference: register

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':vision-camera-ocr:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details

Cannot build on M1 - iOS Simulator

I can't build for iOS Simulator on Apple M1 chip, building for real iPhone device works without a problem.

When trying to build for simulator it will give this error:

Screenshot 2022-03-22 at 21 35 43

I think that it's something with libraries used with vision-camera-ocr setting - EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 on xcode project.

I have tried to remove arm64 exclusion but then I get this error:

building for iOS Simulator, but linking in object file built for iOS

Android failing in 3.8.0

I am getting this error in Android app using the ocrFrameprocessor

FATAL EXCEPTION: mrousavy/VisionCamera.video
Process: com.automanagermobile.app, PID: 10010
com.facebook.jni.CppException: Compiling JS failed: 1:1:invalid empty parentheses '( )' Buffer size 3 starts with: 280a29
	at com.mrousavy.camera.frameprocessor.FrameProcessor.call(Native Method)
	at com.mrousavy.camera.core.VideoPipeline._init_$lambda$0(VideoPipeline.kt:115)
	at com.mrousavy.camera.core.VideoPipeline.$r8$lambda$EMriwS_FKhtjTFtppM84Z5V8tiI(Unknown Source:0)
	at com.mrousavy.camera.core.VideoPipeline$$ExternalSyntheticLambda0.onImageAvailable(Unknown Source:2)
	at android.media.ImageReader$1.run(ImageReader.java:916)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:223)
	at android.os.Looper.loop(Looper.java:324)
	at android.os.HandlerThread.run(HandlerThread.java:67)

My Camera is initated like this:

const ocrFrameProcessor = useFrameProcessor((frame) => {
      'worklet';
      const scannedOcr = scanOCR(frame);
      runOnJS(setOcr)(scannedOcr);
    }, []);
    
    if (device == null)
      return <Text text="You need to accept camera permission requests to use this feature" />
    return (
      <Screen preset="fixed" safeAreaEdges={["top", "bottom"]} contentContainerStyle={$container}>
        <Camera
          style={[StyleSheet.absoluteFill]}
          frameProcessor={ocrFrameProcessor}
          device={device}
          isActive={true}
          pixelFormat="yuv"
          format={format}
          fps={5}
          onLayout={(event: LayoutChangeEvent) => {
            setPixelRatio(
              event.nativeEvent.layout.width /
                PixelRatio.getPixelSizeForLayoutSize(
                  event.nativeEvent.layout.width
                )
            );
          }}
          // codeScanner={codeScanner}
        />
      </Screen>
    )
  }

adding top and left to bounding frame return

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

adding top and left to bounding frame return

Here is the diff that solved my problem:

diff --git a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
index 8ae6279..1e22c03 100644
--- a/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
+++ b/node_modules/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt
@@ -88,6 +88,8 @@ class OCRFrameProcessorPlugin: FrameProcessorPlugin("scanOCR") {
         if (boundingBox != null) {
             frame.putDouble("x", boundingBox.exactCenterX().toDouble())
             frame.putDouble("y", boundingBox.exactCenterY().toDouble())
+            frame.putInt("left", boundingBox.left)
+            frame.putInt("top", boundingBox.top)
             frame.putInt("width", boundingBox.width())
             frame.putInt("height", boundingBox.height())
             frame.putInt("boundingCenterX", boundingBox.centerX())
diff --git a/node_modules/vision-camera-ocr/lib/typescript/index.d.ts b/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
index 47f1816..a3b6c3f 100644
--- a/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
+++ b/node_modules/vision-camera-ocr/lib/typescript/index.d.ts
@@ -2,6 +2,8 @@ import type { Frame } from 'react-native-vision-camera';
 declare type BoundingFrame = {
     x: number;
     y: number;
+    top: number;
+    left: number;
     width: number;
     height: number;
     boundingCenterX: number;
@@ -41,4 +43,5 @@ export declare type OCRFrame = {
  * Scans OCR.
  */
 export declare function scanOCR(frame: Frame): OCRFrame;
-export {};
+export { };
+
diff --git a/node_modules/vision-camera-ocr/src/index.tsx b/node_modules/vision-camera-ocr/src/index.tsx
index b4eeb76..608828a 100644
--- a/node_modules/vision-camera-ocr/src/index.tsx
+++ b/node_modules/vision-camera-ocr/src/index.tsx
@@ -4,6 +4,8 @@ import type { Frame } from 'react-native-vision-camera';
 type BoundingFrame = {
   x: number;
   y: number;
+  top: number;
+  left: number;
   width: number;
   height: number;
   boundingCenterX: number;

This issue body was partially generated by patch-package.

Japanese Text Identification

Hi, I'm trying to do a OCR App made in React Native, and I met vision-camera-ocr. It's working fine with Latin letters! But I would like to extract japanese characteres (katakana, hirakana, kanji). I found that vision-camera-ocr uses Google's MLKit v2, but I do not know how to implement the identification for the languages' cited.

Thanks for now!

TypeError: undefined is not a function, js engine: hermes

I installed correctly react-native-reanimated and I have the exact issue of:

https://github.com/mrousavy/react-native-vision-camera/issues/798

but can't find a way to fix it, even moving around the import of react-native-reanimated.

The full stack is:

Error: ENOENT: no such file or directory, open '/Users/francescoclementi/Documents/development/parkingmgmt-native/http:/localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.parkingmgmtnative&modulesOnly=false&runModule=true'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at getCodeFrame (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:919:18)
    at Server._symbolicate (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:992:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Server._processRequest (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:403:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/francescoclementi/Documents/development/parkingmgmt-native/http:/localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.parkingmgmtnative&modulesOnly=false&runModule=true'
}
Error: ENOENT: no such file or directory, open '/Users/francescoclementi/Documents/development/parkingmgmt-native/http:/localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.parkingmgmtnative&modulesOnly=false&runModule=true'
    at Object.openSync (fs.js:476:3)
    at Object.readFileSync (fs.js:377:35)
    at getCodeFrame (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:919:18)
    at Server._symbolicate (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:992:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Server._processRequest (/Users/francescoclementi/Documents/development/parkingmgmt-native/node_modules/metro/src/Server.js:403:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/francescoclementi/Documents/development/parkingmgmt-native/http:/localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.parkingmgmtnative&modulesOnly=false&runModule=true'
}
 ERROR  TypeError: undefined is not a function, js engine: hermes
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

ReferenceError: Property '__scanOCR' doesn't exist, js engine: hermes

I get this error
ReferenceError: Property '__scanOCR' doesn't exist, js engine: hermes
whenever I load my app with the package installed. I have added the right code to the babel.config.js, it looks like this:

module.exports = function(api) {
  api.cache(true);
  return {
    
     presets: ['babel-preset-expo'],
     plugins: [
       [
          'react-native-reanimated/plugin',
         {
           globals: ['__scanOCR'],
         },
       ],
     ]
  };
};

I am using a expo dev client if that is relevent. I would appreciate any and all help thanks in advance.

Compatibility with react-native-vision-camera 3.0.0+

React Native Vison Camera team has released the versione 3.0.0 in early September 2023. This new version comes with serveral update including the use of react-native-reanimated 3+ (previous version of vision camera were still using the version 2 of react native reanimated).

I'm opening this issue in order to request and track the porting of ´vision-camera-ocr´ from version 2.* to version 3.*.

Property '__scanOCR' doesn't exist

Hi,
i am trying to get start with video-camera-ocr project, but with no luck. When I wan't to use scanOCR(frame) function, I always get error: Property '__scanOCR' doesn't exist. I am using yarn to install.

versions:

iOS: 16.0.3
xCode: 14.0.1

my dependencies:

"react-native": "0.70.3",
"react-native-reanimated": "^2.11.0",
"react-native-vision-camera": "^2.15.1",
"vision-camera-ocr": "^1.0.0",

my babel.config.js:

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

Whole error:

Property '__scanOCR' doesn't exist

ReferenceError: Property '__scanOCR' doesn't exist
    at scanOCR (/Users/Developer/test/node_modules/vision-camera-ocr/src/index.tsx (49:7):1:33)
    at scanOCR (native)
    at _f (/Users/Developer/test/components/ScanScreen.js (36:45):1:77)
    at _f (native)
    at _f (/Users/Developer/test/node_modules/react-native-vision-camera/src/hooks/useFrameProcessor.ts (28:21):1:425)
    at _f (native)

reanimated::REAIOSErrorHandler::raiseSpec()
    REAIOSErrorHandler.mm:18
reanimated::ErrorHandler::raise()::'lambda'()::operator()()
decltype(static_cast<reanimated::ErrorHandler::raise()::'lambda'()&>(fp)()) std::__1::__invoke<reanimated::ErrorHandler::raise()::'lambda'()&>(reanimated::ErrorHandler::raise()::'lambda'()&)
void std::__1::__invoke_void_return_wrapper<void, true>::__call<reanimated::ErrorHandler::raise()::'lambda'()&>(reanimated::ErrorHandler::raise()::'lambda'()&)
std::__1::__function::__alloc_func<reanimated::ErrorHandler::raise()::'lambda'(), std::__1::allocator<reanimated::ErrorHandler::raise()::'lambda'()>, void ()>::operator()()
std::__1::__function::__func<reanimated::ErrorHandler::raise()::'lambda'(), std::__1::allocator<reanimated::ErrorHandler::raise()::'lambda'()>, void ()>::operator()()
std::__1::__function::__value_func<void ()>::operator()() const
std::__1::function<void ()>::operator()() const
invocation function for block in vision::VisionCameraScheduler::scheduleOnUI(std::__1::function<void ()>)
C663D847-B94F-3FB0-9254-32EDBC55315E
C663D847-B94F-3FB0-9254-32EDBC55315E
C663D847-B94F-3FB0-9254-32EDBC55315E
C663D847-B94F-3FB0-9254-32EDBC55315E
C663D847-B94F-3FB0-9254-32EDBC55315E
_pthread_wqthread
start_wqthread

I tried just clone example from this repository, same problem...
I tried other preprocessors (for example Image labeler and it's OK).

Thank you.

Ambiguity in BoundingFrame Type

Hey, hey! Love the plugin! 🙏

It looks like right now that for the type definition of BoundingFrame (code link) we have the x and y elements alluded to as the top and left coordinates, respectively. This is mainly due to the fact that we also have boundingCenterX and boundingCenterY included in the object.

But according to getFrame in Android (code link) we are setting x and y to be the exactCenter coordinates.

This appears to almost be a copy of what we are storing for boundingCenter*, and since the Rect object in Kotlin offer left and top properties (doc link) would it make more sense to swap to using those for x and y, respectively?


Edit: It's also worth noting that on iOS we appear to handle the calculation of x and y manually, thus converting them to be top and left, respectively (code link).

ios cannot compile

xcode15
react-native-vision-camera : 3.1.0
vision-camera-ocr: 1.0

This library needs to be updated

Does not work on iOS 14 (but OK on 15+)

The result is always empty on iOS 14. This is even true for the bundled example project.
I did try everything on a fresh project though. I mixed a few versions but nothing changes the outcome. Everything just fine on iOS 15.7, but just no results on 14.8.1.

It could also be an issue with MLKit itself. I did quite some research but didn't find anything related to MLKit + iOS 14.

Example is not working properly

I've been using a camera before, and I'm going to introduce vision-camera-ocr for a new function.
But I tried to follow the example, but it didn't work.

If you run like this, runOnJS says it can't find it, but it doesn't work.

What is the problem and how do I solve it?

[package information]

  • react-native-vision-camera : 3.0.0
  • vision-camera-ocr : 1.0.0
  • react-native-reanimated : 3.5.1
  • react-native-worklets-core : 0.2.0

[code]


import {Camera, useCameraDevices, useFrameProcessor} from 'react-native-vision-camera';
import {runOnJS} from 'react-native-reanimated'
import { OCRFrame, scanOCR } from 'vision-camera-ocr';


const App = () => {
  const camera = useRef<any>(null); // 카메라 화면
  const devices = useCameraDevices();
  const device = devices.back; // 후면 카메라 사용
  const [ocr, setOcr] = React.useState<OCRFrame>();

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const data = scanOCR(frame);
    runOnJS(setOcr)(data);
  }, []);

  ...

  return(
    <Camera
      ref={camera}
      style={{
        height: '100%',
        width: windowWidth,
      }}
      device={device}
      isActive={showCamera}
      photo={true}
      fps={240}
      frameProcessor={frameProcessor}
    />
  )
}

[babel.config.js]

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    ['babel-plugin-styled-components'],
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanOCR'],
      },
    ],
  ],
};

Can't build on Ios

Version:
"react": "18.2.0",
"react-native": "0.72.7",
"@ismaelmoreiraa/vision-camera-ocr": "^2.1.1",
"react-native-worklets-core": "^0.2.4",

Bug:
The following build commands failed:
SwiftEmitModule normal arm64 Emitting\ module\ for\ VisionCameraOcr (in target 'VisionCameraOcr' from project 'Pods')
(1 failure)

Anybody known how to fix this bug?

Two specific errors when using ^ in the react-native-vision-camera library

When I use the react-native-vision-camera lib without the ^, I have the following error:

...
C/C++: VisionCamera: Frame Processors enabled!
C/C++: VisionCamera: Frame Processors enabled!
C/C++: VisionCamera: Frame Processors enabled!
C/C++: VisionCamera: Frame Processors enabled!
C/C++: VisionCamera: Frame Processors enabled!
C/C++: ninja: error: manifest 'build.ninja' still dirty after 100 tries
Task :react-native-vision-camera:buildCMakeDebug[arm64-v8a] FAILED
FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-vision-camera:buildCMakeDebug[arm64-v8a]'.
    com.android.ide.common.process.ProcessException: ninja: Entering directory `C:\Users\gabri\Documents\project_developed\elastrifuelcontrol\node_modules\react-native-vision-camera\android.cxx\Debug\2m423d6n\arm64-v8a'

And when using the lib with ^, there are the following errors:

Task :ismaelmoreiraa_vision-camera-ocr:compileDebugKotlin FAILED
e: .../node_modules/@ismaelmoreiraa/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt:17:28 Unresolved reference: parsers
e: .../node_modules/@ismaelmoreiraa/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt:19:53 No value passed for parameter 'p0'
e: .../node_modules/@ismaelmoreiraa/vision-camera-ocr/android/src/main/java/com/visioncameraocr/OCRFrameProcessorPlugin.kt:123:27 Unresolved reference: Orientation

follow my package.json:

"dependencies": {
"@ismaelmoreiraa/vision-camera-ocr": "^2.0.0",
"@types/react": "~18.2.14",
"expo": "^49.0.13",
"expo-file-system": "~15.4.4",
"expo-font": "~11.4.0",
"expo-image-picker": "~14.3.2",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"native-base": "^3.4.28",
"react": "18.2.0",
"react-native": "0.72.6",
"react-native-reanimated": "^3.3.0",
"react-native-safe-area-context": "4.6.3",
"react-native-svg": "13.9.0",
"react-native-vision-camera": "^3.3.1",
"react-native-worklets-core": "^0.2.2",
"typescript": "^5.1.3"
},

Help me 🙌

vision-camera-ocr not working on XCode 15 Beta 8

I am trying to compile IOS app with vision-camera-ocr V1.0.0 on XCode 15 Beta 8.
Application crash with below error on startup
objc[3093]: Swift class extensions and categories on Swift classes are not allowed to have +load methods

Crash report is attached:
Report.docx

App is working well on

  1. Xcode 14.3.1 with vision-camera-ocr
  2. Xcode 15 Beta 8 without vision-camera-ocr

Looks like there is something in vision-camera-ocr that is not compatible with XCode 15

React Native V0.71.12

Output of npx react-native info
System:
OS: macOS 13.4.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 30.71 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
Yarn: Not Found
npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, watchOS 10.0
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9477386
Xcode: 15.0/15A5229m - /usr/bin/xcodebuild
Languages:
Java: 11.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

ScanOCR is returning `undefined`

Hi @aarongrider,

My project suddenly started to fail when attempting to OCR vision camera frames. It throws Frame Processor threw an error: Cannot read property 'result' of undefined... my code (removed all not related code to the issue):

import 'react-native-reanimated';
import {runOnJS} from 'react-native-reanimated';
import {scanOCR} from 'vision-camera-ocr';
import {
  Camera,
  useCameraDevices,
  useFrameProcessor,
} from 'react-native-vision-camera';

const frameProcessor = useFrameProcessor(frame => {
  'worklet';
  const result = scanOCR(frame).result;
  if (result.text.length > 0) {
    runOnJS(processText)(result.text);
  }
}, []);

scanOCR(frame) is returning undefined instead of a OCR result... the weird thing is i haven't changed my code at all from when it was working.

I ran the example project on the repo and it has the same issue.

my dependencies:

"react-native": "0.70.0",
"react-native-reanimated": "^2.10.0",
"react-native-vision-camera": "^2.14.1",
"vision-camera-ocr": "^1.0.0",

my babel.config.js:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanOCR'],
      },
    ],
  ],
};

if you need the complete component code let me know. As im new to React Native I don't have the knowledge to check the library to find the issue

Thanks for the awesome library!

Cannot recognise texts when the orientation is not portrait

I've installed the plugin correctly and it works pretty well if the orientation of the device is 'portrait'. However, when I either turn the text or device, it doesn't recognise the texts. Although I played a bit with the orientation property of the camera, no improvements achieved so far. When I looked into the pod of VisionCameraOCR, I came across with a todo as:
` @objc
public static func callback(_ frame: Frame!, withArgs _: [Any]!) -> Any! {

    guard (CMSampleBufferGetImageBuffer(frame.buffer) != nil) else {
      print("Failed to get image buffer from sample buffer.")
      return nil
    }

    let visionImage = VisionImage(buffer: frame.buffer)
    
    // TODO: Get camera orientation state
    visionImage.orientation = .up`

I'd highly appreciate any advices or hints. Thanks in advance!

The text is recognized in reverse (iOS 15.5)

When the text is recognized by the front camera, the text is read in reverse.(e.g." >>>>wOaHMMO3Ya>>")
Isn't there any way to make text recognizable as human readable? (e.g. "PMKORJU<<BYEON<<<")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.