We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch vision-camera-ocr@1.0.0 for the project I'm working on.
vision-camera-ocr@1.0.0
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.
The text was updated successfully, but these errors were encountered:
Thanks for the patch, it helped me
Sorry, something went wrong.
No branches or pull requests
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
vision-camera-ocr@1.0.0
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:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: