Git Product home page Git Product logo

react-native-mlkit-ocr's Introduction

react-native-mlkit-ocr

Google on-device MLKit text recognition for React Native

Installation

npm install react-native-mlkit-ocr

Post-install Steps

iOS

Run

cd ios && pod install

Usage

import MlkitOcr from 'react-native-mlkit-ocr';

// ...

const resultFromUri = await MlkitOcr.detectFromUri(uri);
const resultFromFile = await MlkitOcr.detectFromFile(path);

Example

To get started with the project, run yarn bootstrap in the root directory to install the required dependencies for each package:

yarn bootstrap

To start the packager:

yarn example start

To run the example app on Android:

yarn example android

To run the example app on iOS:

yarn example ios

Contributing

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

License

MIT

react-native-mlkit-ocr's People

Contributors

agoldis avatar brunovillanova avatar brunovillanova-appliedcognition avatar eranga-akva avatar paultranvan avatar zirho 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  avatar  avatar  avatar

react-native-mlkit-ocr's Issues

Orientation

In iOS I'm having issue that if I don't take the photo in landscape it won't read the text.

And on Android I'm having issue of it only working in portrait mode.

Is this an expected thing? Is there a way to hint orientation so I don't have to rotate photo?

Possible unhandled promise rejection

Hi, We can pick up the image from local. However, a promise rejection warning has popped up with an empty screen.

Code:
/* eslint-disable react-native/no-inline-styles */
import React, { useState, useEffect } from "react";
import {
StyleSheet,
View,
Button,
SafeAreaView,
ScrollView,
Text,
Dimensions,
ActivityIndicator,
} from 'react-native';
import {
ImagePickerResponse,
launchImageLibrary,
} from 'react-native-image-picker';
import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';

export default function App() {
const [loading, setLoading] = useState(false);
const [result, setResult] = useState(MlkitOcrResult);
const [image, setImage] = useState(ImagePickerResponse);

if (loading) {
return (



);
}
return (

{!!result?.length && (
<ScrollView
contentContainerStyle={{
alignItems: 'stretch',
padding: 20,
height: Dimensions.get('window').height,
}}
showsVerticalScrollIndicator
style={styles.scroll}
>
{result?.map((block) => {
return block.lines.map((line) => {
return (
<View
key={line.text}
style={{
backgroundColor: '#ccccccaf',
position: 'absolute',
top: fitHeight(line.bounding.top, image?.height ?? 0),
height: fitHeight(line.bounding.height, image?.height ?? 0),
left: fitWidth(line.bounding.left, image?.width ?? 0),
width: fitWidth(line.bounding.width, image?.width ?? 0),
}}
>
<Text style={{ fontSize: 10 }}>{line.text}

);
});
})}

)}

  <Button
    onPress={() => {
      setLoading(false);
      launchGallery(setResult, setImage, setLoading);
    }}
    title="Start"
  />
</SafeAreaView>

);
}

function fitWidth(value: number, imageWidth: number) {
const fullWidth = Dimensions.get('window').width;
return (value / imageWidth) * fullWidth;
}

function fitHeight(value: number, imageHeight: number) {
const fullHeight = Dimensions.get('window').height;
return (value / imageHeight) * fullHeight;
}

function launchGallery(
setResult: (result: MlkitOcrResult) => void,
setImage: (result: ImagePickerResponse) => void,
setLoading: (value: boolean) => void
) {
launchImageLibrary(
{
mediaType: 'photo',
},
async (response: ImagePickerResponse) => {
// response.uri = "../images/TextRead.png"
if (!response.uri) {
throw new Error('oh!');
}
try {
setImage(response);

    setResult(await MlkitOcr.detectFromUri(response.uri));
  } catch (e) {
    console.error(e);
  } finally {
    setLoading(false);
  }
}

);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
scroll: {
flex: 1,
width: '100%',
borderColor: '#ccc',
borderWidth: 2,
},
});

Build errors on iOS

Hello!

I have problem when i try to build on iOS.

Captura de Tela 2022-12-12 aฬ€s 15 10 45

Does anyone know what can it be?

Question: How to perform OCR on Camera's live frame data?

Really more of a question (or a feature request), but is it possible to perform OCR on the live frame data from the Camera?

In my app I was trying to get around this by repeatedly taking pictures at regular intervals and scanning them to show red bounding boxes for the text (video below). This would've worked fine, except iOS makes a loud shutter noise when you take a picture (and a shutter noise every 500ms is really really annoying).

It looks like expo-camera (which is what I'm using) doesn't access the live frame data but there are some other options out there that do, but I don't know how to get them to work with MLKit:

Thanks! Appreciate this package a ton and understand what I'm asking here might be difficult to do. If so, I'm also curious to learn more and help out.

RPReplay_Final1632580413.mov

Expo support?

I was curious if I could use this in a managed Expo app. I created a simple project here to test. I get this error after selecting an image. Any advice or is Expo support infeasible?

null is not an object (evaluating 'MlkitOcr.detectFromUri')
at node_modules/react-native-mlkit-ocr/src/index.tsx:70:33 in MLKit.detectFromUri
at node_modules/react-native-mlkit-ocr/src/index.tsx:69:17 in MLKit.detectFromUri
at App.js:85:22 in launchGallery

Not working correctly on iOS

The module works fine on Android device.
But when I try to use it on iOS it does not seem to work properly with the same pictures. detectFromUri returns only random single letters as a result of text recognition. What could be the problem?

Like this, but there are a lot of text lines in the picture.

[{"bounding":{"height":274,"left":1239,"width":402,"top":649},"cornerPoints":[{"y":649,"x":1266},{"y":691.5904541015625,"x":1640.5865478515625},{"y":922.105224609375,"x":1614.3770751953125},{"y":879.5147705078125,"x":1239.79052734375}],"lines":[{"elements":[{"bounding":{"height":274,"left":1239,"width":402,"top":649},"text":"w","cornerPoints":[{"y":649,"x":1266},{"y":691.5904541015625,"x":1640.5865478515625},{"y":922.105224609375,"x":1614.3770751953125},{"y":879.5147705078125,"x":1239.79052734375}]}],"bounding":{"top":649,"width":402,"left":1239,"height":274},"cornerPoints":[{"x":1266,"y":649},{"x":1640.5865478515625,"y":691.5904541015625},{"x":1614.3770751953125,"y":922.105224609375},{"x":1239.79052734375,"y":879.5147705078125}],"text":"w"}],"text":"w"}]

Not able to read Image from detectFromFile in iOS

I am trying to click a picture and from the picture read the text. I am trying to use the detectFromFile function its working fine in android but on iOS its giving below error. When I am using the detectFromURI the data is not correct.

error - [Error: No image path provided]

iOS - file:///private/var/mobile/Containers/Data/Application/F04C7E36-D373-45D8-A710-24B1F0E7C128/tmp/A2219846-9426-45E3-B9CF-A97D42DE2410.jpeg

Letter 'o' is not recognized

I'm working on an app to teach children how to write letters. I use a sketching library and save it as png and give that png to this library. It works with all the letters but it doesn't recognize letter o at all. Any suggestions?

translate example launchGallery fonction in js

Hi,
thank you for you code.
I try to test your example first but I do not know Typescript,
I started to "translate" your app.jsx in js but I do not understand what you do in launchGallery fonction.
here is the code : can you complete launchGallery please ?

App.zip

Thank you

Cannot build on iOS

Hello, I tried to install the package on my react native project (npm install + pod install), but the build is failing. Below is the xCode output :

image

What I am missing ? Is there another installation step ?

Cannot read property 'detectFromUri' of undefined

import MlkitOcr from 'react-native-mlkit-ocr';

const resultFromUri = await MlkitOcr.detectFromUri(data.uri);

I tried to build through xcode and run again in my iPhone 6 but still having issue

Xcode 10.3
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "0.59.10",
"react-native-mlkit-ocr": "^0.2.2",

device: IPhone 6

expo build errors for android (wrong kotlin version)

Hello!

I love this package, been working great for me in a managed expo / eas build project. But with my latest update, it only builds fine on iOS. On Android, it I get the following error: "Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15."

Unsure of how to tackle this, any pointers would be much appreciated. Is there a way to override the kotlin version manually?

My package versions:

...
    "expo": "^46.0.13",
    "react-native-mlkit-ocr": "0.2.5",
...

The build error logs:

[stderr] e: /home/expo/.gradle/caches/transforms-3/0485c57e77da2d74e4400ab5f4119067/transformed/jetified-kotlin-stdlib-jdk8-1.6.10.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] e: /home/expo/.gradle/caches/transforms-3/39ce31cacf59c39e98c8af78aab9d48a/transformed/jetified-react-native-0.69.6-release-api.jar!/META-INF/ReactAndroid_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] e: /home/expo/.gradle/caches/transforms-3/71974a8810180bf42d7354e2ae463e17/transformed/jetified-kotlin-stdlib-common-1.6.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] e: /home/expo/.gradle/caches/transforms-3/76ffa0bc7ee35e73adab5c035a9c7f86/transformed/jetified-kotlin-stdlib-jdk7-1.6.10.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] e: /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (21, 17): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (26, 17): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (35, 17): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (37, 17): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (38, 11): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (41, 15): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (42, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (48, 5): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (49, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (50, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (51, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (52, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (54, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (55, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (56, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (57, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (68, 16): Unresolved reference: forEach
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (68, 26): Cannot infer a type for this parameter. Please specify it explicitly.
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (70, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (71, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (72, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (88, 13): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (89, 13): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (90, 13): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (91, 24): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (95, 11): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (96, 11): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (97, 11): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (98, 11): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (100, 23): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (106, 12): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (107, 12): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (108, 12): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (109, 12): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
[stderr] The class is loaded from /home/expo/.gradle/caches/transforms-3/f9a6c4180d9d810f143b823eeeb39ba3/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class
[stderr] e: /home/expo/workingdir/build/app/node_modules/react-native-mlkit-ocr/android/src/main/java/com/reactnativemlkitocr/MlkitOcrModule.kt: (110, 12): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.

detectFromFile not implemented on Android

Hey, using the latest version 0.2.2 and it seems detectFromFile is not implemented in the android project just detectFromUri.
00:10:27 | WARN | Failed to do text recognition MlkitOcr.detectFromFile is not a function. (In 'MlkitOcr.detectFromFile(path)', 'MlkitOcr.detectFromFile' is undefined)

ios example xcode build failed

Could you please help me what i'm doing wrong? Thanks!

I just downloaded from the example folder and install the packages, pods then built through xcode and got these messages below :

image

I get type errors with RN 70.x

probably not related to the RN itself.
after installing the library, I get type error.

I've found an old issue and tried 0.2.2 but still get the error.
#7

I don't see d.ts file in any of release.

image

iOS armv7 build issues - looking for recommendations

The default XCode template for RN builds for both arm64 and armv7. However, Google's SDK is only available for arm64 (no 32-bit support). This is problematic as the iOS simulator must run with armv7, so limiting the architectures to arm64 prevents you from running the entire project in the simulator (even if the library itself is not used).

I thought/tried about allowing armv7 and arm64 for debug, and just arm64 for release so final builds do not raise any error, but this causes cocoapods / pod install to fail due to different values for each architecture (which makes sense since pods have to compile/define the architecture for each sub project).

So far, this leaves me with the annoying procedure of switching from arm64 to armv7 + arm64 architecture each time I need to test on a simulator.

Any ideas how this process could be improved? Thanks.

Screen Shot 2021-05-02 at 12 34 11

update podspec

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.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-mlkit-ocr/react-native-mlkit-ocr.podspec b/node_modules/react-native-mlkit-ocr/react-native-mlkit-ocr.podspec
index 334c87e..e5f67e3 100644
--- a/node_modules/react-native-mlkit-ocr/react-native-mlkit-ocr.podspec
+++ b/node_modules/react-native-mlkit-ocr/react-native-mlkit-ocr.podspec
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
   s.source_files = "ios/**/*.{h,m,mm}"
 
   s.dependency "React"
-  s.dependency "GoogleMLKit/TextRecognition", "2.6.0"
+  s.dependency "GoogleMLKit/TextRecognition", "3.2.0"
 end

This issue body was partially generated by patch-package.

Error: no content provider

I am testing this library, but when I try to detect OCR I got this error:

From file taken from the Camera (https://mrousavy.com/react-native-vision-camera):

const resultFromUri = await MlkitOcr.detectFromFile(photo.path);

I got:

Error: No content provider: /data/user/0/com.xxx.xxx/cache/mrousavy7055454057311618212.jpg
at promiseMethodWrapper (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.digitalbore.xxxx&modulesOnly=false&runModule=true:5117:45)
    at detectFromFile$ (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.digitalbore.xxxx&modulesOnly=false&runModule=true:160428:72)

From Uri:

const resultFromUri2 = await MlkitOcr.detectFromUri(uri);

I got:

Error: No content provider: https://i.ibb.co/VqnMc4X/fafa.jpg

Specification
SO: Android 11
React Native: 0.66.4

"[TypeError: Cannot read property 'detectFromUri' of null]"

Expo Version: '49'
React Native Version: '0.72'

So, I'm just trying to follow the example on README but everytime I try to scan any text using any method I get this annoying error "[TypeError: Cannot read property 'detectFromUri' of null]" or "[TypeError: Cannot read property 'detectFromFile' of null]"

I'm giving the function valid URIs but it has no effect, the error is still happening.
Idk if this makes a difference, but I'm running the app through the Expo Go App on an Android 13 device

const OCR = async ( ) => {
     try{
         const result = await MlkitOcr.detectFromUri(valid_URI);
         console.log(result);
     }
     catch(error){
         console.error(error)
      }
}

execution MlkitOcr.detectFromFile(path) or MlkitOcr.detectFromFile(path) produce an error

Hello , thanks for your help.
i try to use this library and i have an error when a try to use the principal methods :

const resultFromUri = await MlkitOcr.detectFromUri(uri);
const resultFromFile = await MlkitOcr.detectFromFile(path);

result : ---> error : [TypeError: null is not an object (evaluating 'MlkitOcr.detectFromFile')]

thanks for your help.
i use expo .

Using custom .tflite trained model

Hi,

how feasible would be to use a custom .tflite trained model? Seems like MLKit allows it. I'm using this package to scan document's MRZ lines. Already with good results, but a MRZ trained model would rock.

On another hand, on MlkitOcrModule.kt I see TextRecognizer is using latin lang by default. Would be DOCUMENT (or maybe CREDIT_CARD] more suitable for MRZ -or, at least, a little step forward-? In that case, would be lang option easier to add to detectFrom*() , maybe? (Dunno on the ios side, though).

Thanks!

Gradle kotlin issues with other libraries

Hello,

When building for production, I'm getting the following warning/error:

The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. 
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl
The Kotlin plugin was loaded in the following projects: ':react-native-mlkit-ocr', ':react-native-webview'

I also have the following in build.gradle in order for both libraries to use the same version:

kotlinVersion="1.4.32"

Build Failed with 0.72.4

Hey i am getting this error :
FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':react-native-mlkit-ocr'.

Failed to notify project evaluation listener.
Could not create task ':react-native-mlkit-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.
KotlinJvmAndroidCompilation with name 'debugAndroidTest' not found.

Error: Waiting for the text recognition module to be downloaded. Please wait

Tried to detect text by passing Uri, its taking time around 5-7 seconds and showing this message in chrome browser console

let resultFromUri = await MlkitOcr.detectFromUri(uri);

package.json:

"@react-native-firebase/app": "^15.0.0",
"@react-native-firebase/ml": "^15.0.0",
"react-native-image-picker": "^4.8.4",
"react-native-mlkit-ocr": "^0.2.5",

Error:

Possible Unhandled Promise Rejection (id: 0):
Error: Waiting for the text recognition module to be downloaded. Please wait.
Error: Waiting for the text recognition module to be downloaded. Please wait.
at Object.promiseMethodWrapper [as detectFromUri] (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:2580:36)
at detectFromUri$ (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:112555:58)
at tryCatch (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24259:19)
at Generator._invoke (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24239:26)
at Generator.next (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24290:23)
at tryCatch (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24259:19)
at invoke (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24297:22)
at http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:24321:13
at tryCallTwo (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:28716:7)
at doResolve (http://localhost:3001/index.bundle?platform=android&dev=true&minify=false&app=com.rntextdetect&modulesOnly=false&runModule=true:28880:15)

How to resolve this?

Advance Thanks for Helping

Limit scan to bounding box?

Is it possible (or does the google SDK) support a way to limit the text extraction to a bounding box? Could be useful to speed up the process and reduce the amount of junk when scanning certain things.

I'm up to provide a PR if the google SDK supports that somehow.

Build fail with error in ios

CopySwiftLibs /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app (in target 'app' from project 'app')
cd /Users/roysabah/www/automati/app/ios
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.6.sdk
builtin-swiftStdLibTool --copy --verbose --sign - --scan-executable /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app/app --scan-folder /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app/Frameworks --scan-folder /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app/PlugIns --platform iphonesimulator --toolchain /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain --destination /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app/Frameworks --strip-bitcode --strip-bitcode-tool /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip --emit-dependency-info /Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Intermediates.noindex/app.build/Debug-iphonesimulator/app.build/SwiftStdLibToolInputDependencies.dep

error: Build input file cannot be found: '/Users/roysabah/Library/Developer/Xcode/DerivedData/app-aebhwuspvfqrccddikslhrdwtozf/Build/Products/Debug-iphonesimulator/app.app/app' (in target 'app' from project 'app')

MlkitOcr.detectFromUri is null

HI there,

We try to use running expo sdk 45 and rn 0.69

import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';

const sample_image = "data:image/jpeg;base64,/9j/4QF ............."
const text = await MlkitOcr.detectFromUri(sample_image);

we catch the error is MlkitOcr.detectFromUri is null

It seems MlkitOcr is not well defined in the package react-native-mlkit-ocr

Kindly point out the mistakes we have made, many thanks

Albert

build error on RN 0.69.1 / package incomplete

when we have added the module on a fresh RN0.69.1 , do a yarn run android and you get the error mainly:

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.
How that module be integrated in a recent fresh react-native init 0.69.1 please ?

iOS builds not approved by App Store due to unpinned GoogleMLKit/TextRecognition version

There was a thread in the Expo forums on how iOS builds were being rejected by the App store due to the following error:

ITMS-90562: Invalid Bundle - The app cannot be processed because options not allowed to be embedded in bitcode are detected in the submission. It is likely that you are not building the app with the toolchain provided in Xcode. Rebuild your entire app with the latest GM Xcode and submit the app again. 

The solution was to pin the GoogleMLKit/TextRecognition pod to version 2.2.0 per Google's release notes [here](GoogleMLKit/TextRecognition pod). This solves the build issue, but the downside is that it uses MLKit's Text Recognition v1 instead of Text Recognition v2 (in beta).

Currently, I applied this solution in my project project using patch-package, but are we open to pinning the version number to 2.2.0 in the .podspec file here? It's a simple code change and I'd like to make it & contribute if possible.

Thanks!

[ios] Could not recognize image data when object is captured in portrait | landscape mode.

Hello

Our project is using this library to recognize text from an image. Everything is works as expected on android side but on iOS If I capture image in portrait mode, It does not recognize text. However, here is the catch! If I rotate an object (for instance card) or it has text to 270 degree and then I capture image or text and It will be able to recognize text from images accurately.

Following this issue: the possible solution would be to able to detect image in normal view (like portrait mode and orientation set to 6)

does anyone facing same issue on iOS? I can not use expo-image-manipulator before processing to OCR!!

iOS GoogleMLKit/TextRecognition version?

How do we know the current version of GoogleMLKit/TextRecognition being used, and how can we keep it updated?

I'm trying to diagnose an "App Hang" error log that happens from time to time from this library (or actually the MLKIT C code), and was wondering about the versions being used. Does it just use the latest and it auto-updates on any pod install?

This is what I'm getting:

0  libsystem_kernel.dylib _mach_msg_trap
1  libsystem_kernel.dylib _mach_msg
2  libdispatch.dylib      __dispatch_mach_send_and_wait_for_reply
3  libdispatch.dylib      _dispatch_mach_send_with_result_and_wait_for_reply
4  libxpc.dylib           _xpc_connection_send_message_with_reply_sync
5  Foundation             ___NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__
6  Foundation             -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]
7  Foundation             -[NSXPCConnection _sendSelector:withProxy:arg1:arg2:]
8  Foundation             __NSXPCDistantObjectSimpleMessageSend2
9  DuetActivityScheduler  <redacted>
10 BackgroundTasks        <redacted>
11 BackgroundTasks        <redacted>
12 zinspector3            MLKITx_absl::base_internal::AtomicHook<void (*)(char const*, int, char const*, char const*, char const*)>::DummyFunction(char const*, int, char const*, char const*, char const*) (zinspector3)
13 zinspector3            MLKITx_absl::base_internal::AtomicHook<void (*)(char const*, int, char const*, char const*, char const*)>::DummyFunction(char const*, int, char const*, char const*, char const*) (zinspector3)
14 zinspector3            MLKITx_absl::base_internal::AtomicHook<void (*)(char const*, int, char const*, char const*, char const*)>::DummyFunction(char const*, int, char const*, char const*, char const*) (zinspector3)

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.