googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.5k stars 2.92k forks source link

[Feature request] Add cropRect support for InputImage.fromMediaImage (or similar API to check barcode preview bounds) #491

Open G00fY2 opened 2 years ago

G00fY2 commented 2 years ago

What's your feature request? Please describe. We are using the ML Kit barcode-scanning library in conjunction with CameraX ImageAnalysis.Analyzer. There is currently no sufficient way to limit the area in which ML Kit should search for the barcode (basically making sure the barcode result is inside the preview bounds). E.g. even if [cropRect ](https://developer.android.com/reference/android/media/Image#getCropRect()) is set, ML Kit will scan the whole image for barcodes. This way the users can't point the camera at a specific barcode without scanning all barcodes which are visible to the camera.

Mobile environment Android 12 androidx.camera:camera-camera2 1.0.2 com.google.mlkit:barcode-scanning 17.0.2

Additional context

234 was closed without any updates for over 15 month.

There is no sample to achieve such a common usecase in the vision-quickstart sample project.

In the material-showcase sample project the logic about detecting if the result is inside the overlay starts here: https://github.com/googlesamples/mlkit/blob/5c35770350546244957e35f845e36c077bf21ffd/android/material-showcase/app/src/main/java/com/google/mlkit/md/barcodedetection/BarcodeProcessor.kt#L58

But this requires a custom GraphicOverlay class which on the other hand depends on a complex CameraSource class which are all build on top of the deprecated default Android Camera framework.

There are suggestions on SO which rely on complex and errorprone bitmap preprocessing.

So in the end there is no developer friendly and reliable way of checking the barcode bounds with the CameraX previous bounds.

zhouyiself commented 2 years ago

Specifying area is not supported currently, can you try to filter out the result instead that not located in your interested area?

RowanH commented 2 years ago

@zhouyiself Hi ! Here's our use case - you might have 10 codes in close proximity (imagine a shelf full of boxes with QR codes on them). Flagship phones are so fast at scanning you get back say 5-6 codes very quickly if the phone has some of those QR codes visible. The user only wants the code in the center of the scan area, even though 5 other codes may be visible on the camera view.

There's no way of saying these other 5 codes we don't want, so we have to tell our users, on Android to make sure the phone is very close to the QR code then gradually move the phone back until the QR code scans.

I have an app with both iOS and Android versions, and the android version has a usability flaw as a result of this. I would greatly appreciate if this feature could be added. [ iOS there is the option, and we use it, to crop part of the camera view]

I'm sure there's dozens to hundreds of other developers out there that would love this...

mujehoxe commented 2 years ago

Well i would like it, because it would reduce the calculation and therefore the energy usage, because we are required to process lots of codes every day.

vikassable commented 1 year ago

Any update here, we would really appreciate this functionality, thank you!

RowanH commented 1 year ago

Certainly the need is definitely present within our app, at this point I'm close to rewriting that part and looking for alternatives to MLKit..

hr-roberthoffmann commented 1 year ago

@RowanH Dear Rowan, did you found any alternatives or a solution with MLKit? Have the same problem. Thank you very much!

jcho0216 commented 3 months ago

any updates yall ?