Best way to do OCR with Expo

I’m new to both react native and expo, hopefully I understand the concepts I’m talking about correctly, please correct me if I don’t. I’m trying to build a mobile app which performs OCR. However, I’m not quite sure what the best way to perform OCR is. I’ve found this tesseract ocr library but it seems that I need to eject from expo to use that because it relies on native code. I’ve also tried using this pure js library but that depends on util from the Node Standard Library which isn’t supported by Expo. I’ve also found the anyline library (I can’t link it because I’m a new user) but it seems that using Anyline requires payments which I’d like to avoid if possible.

Is the best path forward using the tessaract OCR library and ejecting from expo?

Seems like there’s no expo-native way to peform OCR: https://expo.canny.io/feature-requests/p/support-optical-character-recognition-ocr

1 Like

Hey curious if you found a way to do it in expo? I’m trying to OCR an image taken with a camera.

Here’s a proof of concept. Only tested on Android so far:

I just needed EAS Build and a small patch to react-native-tesseract-ocr applied with patch-package.

1 Like

Thanks man I saw this the other day and needed to try it out. Will try this now! I’ve been hesitant to get to native code it seemed tricky, I’m going to dive in!

Oh shoot this is android only. I’m going to try this one and let you know how it goes - GitHub - agoldis/react-native-mlkit-ocr: Google on-device MLKit Text Recognition for React Native</tit

1 Like

@wodin it worked! Oh my gosh it was so easy!!!

  • expo init
  • expo install react-native-mlkit-ocr expo-dev-client
  • eas build -p all --profile development
  • When the build completes, go to the build page on expo.io and then tap install, it opens a QR code
  • Scan that QR code with your device, it will download the app to it.
  • Start the downloaded app.
  • expo start --dev-client

Wowww!!

I actually use expo-camera with takePhotoAsync and then pass the URI to the mlkit lib and it works!

3 Likes

Brilliant! :smile:

Could you post those steps to the feature request to let everyone know?

Oh yes totally thanks!

1 Like

Hey hey, a side question. I now did expo install expo-gl but when I try to use it I get the error:

[Unhandled promise rejection: Invariant Violation: requireNativeComponent: "ViewManagerAdapter_ExponentGLView" was not found in the UIManager.]
at node_modules/react-native/Libraries/ReactNative/getNativeComponentAttributes.js:29:11 in getNativeComponentAttributes
at node_modules/react-native/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js:121:25 in exports.get

If I have an eas build, after every expo install that has native libs in it, do I need to make another build of custom client?

Exactly.

Basically, the dev client or standalone app has only the native dependencies you need in order to reduce the size of the app. Expo Go, is basically like a dev client with a predefined set of native dependencies already added that you cannot change.

This also makes OTA updates harder to manage, so every time you need to build a new app because of adding native code you will need to change the release channel or runtime version.

1 Like

the dev client or standalone app has only the native dependencies you need in order to reduce the size of the app.

Oh that’s spectacular! I totally don’t mind rebuilding if it means reduced size.

This also makes OTA updates harder to manage, so every time you need to build a new app because of adding native code you will need to change the release channel or runtime version.

This totally makes sense, its fair though. Maybe is there a way to include all the native modules that a non-eas build normally goes out with? Outside of expo install all the modules? lol

Major thanks for the side questions, I’m getting way hyped for eas now haha.

I think that is exactly how you’d need to do it :sweat_smile:

Haha for sure, thanks!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.