4

I am working with Expo, React Native and I want to to be able to detect text from images. Is there an package i can work with to achieve this?

I am using Expo camera module to snap the picture and supply the URI to the text detector I have tried using react-native-text-detector but I am getting the error that the function detectFromUri is not defined. I have also tried with tesserect.js but it fails on import with "unable to resolve variable location".

await this.camera.takePictureAsync(options).then(photo => {
       photo.exif.Orientation = 1;
                //console.log(photo.uri);
        const visionResp = await RNTextDetector.detectFromUri(photo.uri);
        if (!(visionResp && visionResp.length > 0)) {
            throw "UNMATCHED";
        }
        console.log(visionResp);
});

I am expecting the visionResp to log the results returned from the detection but instead i get undefined is not an object (evaluating '_reactNativeTextDetector.default.detectFromUri')

hong developer
  • 13,291
  • 4
  • 38
  • 68
daRula
  • 143
  • 2
  • 12

1 Answers1

6

Is your project created with expo-cli?

If yes, Expo is not supporting OCR currently. There is a feature request on canny.io but you can't know for sure when it will become available. Your only choice is to use an OCR service like this one.Internet connectivity will be required.

If not, (and the project is created with react-native-cli) you should be able to successfully use react-native-text-detector. Just make sure you link the package correctly. Docs here

charlietango
  • 428
  • 2
  • 11
  • I created it using create-react-native-app – daRula Apr 17 '19 at 09:07
  • That project is no longer maintained - `expo-cli` took its place. This means you are bound to Expo and you won't be able to use use react-native-text-decorator unless you eject. – charlietango Apr 17 '19 at 09:12
  • You are welcome. If you are not forced to use expo and you didn't put too much work into the project, you can try creating a new project with `react-native-cli`. Keep in mind you'll need XCode/Android studio to build the app. – charlietango Apr 17 '19 at 09:17