-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add text recognition module #235
New issue
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
Conversation
🦋 Changeset detectedLatest commit: 055879a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| suspend fun getInputImage( | ||
| imagePath: String | ||
| ): InputImage { | ||
| try { | ||
| val bitmap = BitmapFactory.decodeStream(withContext(Dispatchers.IO) { | ||
| URL(imagePath).openStream() | ||
| }) | ||
|
|
||
| return InputImage.fromBitmap(bitmap, 0) | ||
| } catch (e: Exception) { | ||
| throw Exception("RNMLKitTextRecognition: Could not load image from $imagePath", e) | ||
| } | ||
| } | ||
|
|
||
| class RNMLKitTextRecognitionModule : Module() { | ||
| override fun definition() = ModuleDefinition { | ||
| Name("RNMLKitTextRecognition") | ||
|
|
||
| AsyncFunction("recognizeText") { imagePath: String, promise: Promise -> | ||
| runBlocking { | ||
| val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS) | ||
|
|
||
| val image: InputImage = getInputImage(imagePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, the build.gradle pulls in implementation project(path: ':infinitered-react-native-mlkit-core')
I might have missed it, but I don't believe the core image/label classes are being used it at all. I would expect to see some import form
import red.infinite.reactnativemlkit.core....
Compared to the Swift code (in most modules, not just this one) it seems like we don't construct the RNMLKitImage the same way.
Anyway, I'm not sure it's wrong, just opening it up for discussion:
- Should we be using the MLKitCore reusables here? Are they needed or give any benefit?
- If not, can be get away with cleaning up the
build.gradledependency? - Also if not, is there feature parity between ios/android with the returned data (it certainly seems to have it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point - I think this module followed image labeling, which doesn't use the shared utilities either. We should use those for consistency, IMO. I'll push an update.
I think the end result is roughly the same without it, but it would be good to get all these libraries working the same. I'll also file an issue to migrate image labeling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frankcalise
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last change we missed! Can you update the root README to list the module and point to what would be the new doc page that will be hosted?
frankcalise
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🚢
|
@all-contributors please add @dccarmo for code and documentation |
|
I've put up a pull request to add @dccarmo! 🎉 |
|
@all-contributors please add @coolsoftwaretyler for code and documentation |
|
I've put up a pull request to add @coolsoftwaretyler! 🎉 |
This PR will supersede #221 - it rebases against
main, which includes important fixes for Expo 53+, and fixes Android builds from the prior PR.Closes #210
It also implements fixes for the feedback we gave: updates the types to reflect the Google API more closely, reverts image picker changes.
Android
text-recognition-android-works.mp4
iOS
text-recognition-ios-works.MP4