googlesamples / googlesamples/mlkit

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

Open
#491 8 comments 0 reactions 1 assignee Claimed by @zhouyiself View on GitHub
Dominant language
Kotlin
Stars
4.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

**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](https://github.com/googlesamples/mlkit/tree/master/android/vision-quickstart).

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](https://github.com/googlesamples/mlkit/blob/master/android/material-showcase/app/src/main/java/com/google/mlkit/md/camera/GraphicOverlay.kt) which on the other hand [depends on](https://github.com/googlesamples/mlkit/blob/5c35770350546244957e35f845e36c077bf21ffd/android/material-showcase/app/src/main/java/com/google/mlkit/md/camera/GraphicOverlay.kt#L81) a complex [CameraSource class](https://github.com/googlesamples/mlkit/blob/master/android/material-showcase/app/src/main/java/com/google/mlkit/md/camera/CameraSource.kt) which are **all build on top of the deprecated** default Android Camera framework.

There are [suggestions on SO](https://stackoverflow.com/questions/63390243/is-there-a-way-to-crop-image-imageproxy-before-passing-to-mlkits-analyzer) 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.