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

Barcode Scanning with CameraX not working on Android 10 #167

Closed ruippoliveira closed 3 years ago

ruippoliveira commented 3 years ago

I'm trying tu use this demo do test the Barcode Scanning on a Samsung Tablet with Android 10. The app read the QrCode at LivePreviewActivity, but if i chose the CameraX option the app don't return anything. I tested the same code on a Samsung tablet with Android 8 and this bug don't happens.

My log is filled with: Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)

ai-plays commented 3 years ago

Hi ruippoliveira,

To help use debug this, could you help provide a bit more information.

  1. Could you share the barcode image that you can use to reproduce the issue?
  2. What resolution you are using?
  3. Does any of the other features (e.g. Object Detection, PoseDetection, TextRecognition...) work in CameraX case?
  4. What is exact the version of your Android 10?(I tried on my Pixel 3XL with QQ1A. It works fine)

Thanks

mikkelvp commented 3 years ago

I have the same issue on a OnePlus 7T Pro with Oxygen OS 10.0.9.HD01BA Other features working fine with CameraX.

Screenshots

LivePreviewActivity ![Screenshot_20201021-104119](https://user-images.githubusercontent.com/9072378/96697610-65d8fa80-138c-11eb-9014-60545b8058cc.jpg) CameraXLivePreviewActivity ![Screenshot_20201021-103923](https://user-images.githubusercontent.com/9072378/96697628-68d3eb00-138c-11eb-8b5d-5f799ed63296.jpg)

ruippoliveira commented 3 years ago

Hi Steve,

  1. It doesn't work with any qr code that i try. But I will attach some images.
  2. you can see in the screenshots attached
  3. Yes, the other features work with cameraX. Only Barcode Scanning doesn't work.
  4. Tablet: Samsung SM-T500 ; Android: 10 ; One Ui Core: 2.5

Samsung SM-T500 , Android 10, Camera X Screenshot_20201021-103252_MLKit-Vision

Samsung SM-T500 , Android 10, Live Preview Screenshot_20201021-105017_MLKit-Vision

Samsung SM-T585, Android 8, Camera X Screenshot_20201021-103417_MLKit-Vision

ai-plays commented 3 years ago

Hi mikkelvp and ruippoliveira,

With the images you provided, I cannot reproduce the issue.

We still need more information to debug this:

  1. Are you using the barcode thin client or thick client? (If you didn't modify the vision quickstart at all, it is using the thick client)
  2. Could you help try if barcode detection fails in all barcode format or just some? Here are all the supported formats: https://developers.google.com/ml-kit/vision/barcode-scanning#key_capabilities
  3. Is the barcode scanner (Android 10, CameraX) always failing that it never detected successfully, not even once?
  4. ruippoliveira, the barcode is a bit small in your image. Could you try if moving it closer to camera would work?
  5. Is there any log that you think might be related? Please share.

I also looped in more teammates to help take a look at this issue.

Thanks.

zhouyiself commented 3 years ago

If possible, could you help attach a bug report as well? https://developer.android.com/studio/debug/bug-report

zhouyiself commented 3 years ago

Also, can you try using same resolution in LivePreviewActivity and CameraXLivePreviewActivity, and then compare? It can be set from the Settings page (gear icon at the right top corner)

mikkelvp commented 3 years ago
  1. Thick client. Tried with thin too - no difference.
  2. No barcodes regardless of format are recognized.
  3. The barcodes list in the success listener is always empty.
  4. Nothing relevant is showing in logs.

Changing resolution does not change output.

ruippoliveira commented 3 years ago

Hi steven,

  1. I didn't modify the vision quickstart at all, so I'm is using the thick client
  2. I tried with different types and sizes of barcodes and it never worked.
  3. It never worked. The barcodes list always return empty.
  4. I tried woth bigger ones and the result it's the same
  5. Looking for logs I can't see any clue of what happens.

Thanks.

ruippoliveira commented 3 years ago

Hi zhouyiself,

The app never crash. It simply doesn't return any barcode information. I changed the resolutions and the problem persists.

Thanks

ai-plays commented 3 years ago

Hi all,

We got some clue and keep investigating on it. Will keep you posted.

Thanks!

omarmiatello commented 3 years ago

Same issue after libraries update. Tried on OnePlus 6T / Android 10

Is working with:

implementation "androidx.camera:camera-core:1.0.0-beta07"
implementation "androidx.camera:camera-camera2:1.0.0-beta07"
implementation "androidx.camera:camera-view:1.0.0-alpha14"
implementation "androidx.camera:camera-extensions:1.0.0-alpha14"
implementation "androidx.camera:camera-lifecycle:1.0.0-beta07"

Is not working with:

implementation "androidx.camera:camera-core:1.0.0-beta11"
implementation "androidx.camera:camera-camera2:1.0.0-beta11"
implementation "androidx.camera:camera-view:1.0.0-alpha18"
implementation "androidx.camera:camera-extensions:1.0.0-alpha18"
implementation "androidx.camera:camera-lifecycle:1.0.0-beta11"
callmemaxi commented 3 years ago

I'm also facing the same issue.

As for workaround. I'm converting ImageProxy to bitmap, then passing it to the detector.

MarioNoll commented 3 years ago

We are facing this issue in our app as well. Confirmed devices from our user reports:

The last working cameraX version is 1.0.0-beta-07, using a newer version does not produce barcode results for the mentioned devices. We have a One Plus 6 where we can reproduce the issue, let me know if we can support debugging in any way.

As for workaround. I'm converting ImageProxy to bitmap, then passing it to the detector.

@callmemaxi Could you share the details of how you are creating the bitmap? I tried your workaround by creating a Bitmap as described here but still don't get any results.

callmemaxi commented 3 years ago

Hi @looploooop,

I'm creating the bitmap using getBitmap(ImageProxy image) method from mlkit samples.

Then converting the bitmap to InputImage using

val image = InputImage.fromBitmap(bitmap!!, 0)

Wrakor commented 3 years ago

Can confirm this issue, happening on my OnePlus 7T Pro (Android 10). I was going crazy trying to understand why it was not working! Using the lib versions suggested by @omarmiatello solved it, barcode scanning is now working.

cs-googler commented 3 years ago

Hi, BarcodeScanning with CameraX input may not work on some devices with the latest CameraX library. You can use an earlier version(pre camera-camera2:1.0.0-beta08) of camera-camera2 to bypass this issue. We will soon publish this in the Known issue session of our dev site as well. The fix for this issue will be shipped with the next mlkit barcode sdk release in Mid Dec 2020.

polivmi1 commented 3 years ago

@cs-googler do you know if the fix was already released? I am trying latest 1.0.0-rc01 and latest com.google.mlkit:barcode-scanning:16.1.0, which is not working and there isn't any update regarding this issue on the https://developers.google.com/ml-kit/known-issues Thank you. I believe, that we should re-open this issue until fixed?

polivmi1 commented 3 years ago

@cs-googler is there any update? I don't think this issue is resolved.

ruippoliveira commented 3 years ago

@polivmi1 the issue was solved for me when I update barcode scanning to version "16.1.0"

polivmi1 commented 3 years ago

@ruippoliveira I have tried with that and with 16.1.1, but after the update I wasn't able to scan: https://i.pinimg.com/originals/25/1d/93/251d93a54dc555a11e2971b23db3fe74.jpg Before with Camera 1.0 instead of CameraX it worked. With some other barcodes I have no problem even after upgrade.

CharcoalChen commented 3 years ago

@polivmi1 Could you help to check whether the images returned by CameraX ImageAnalysis has problem or not? You can use YuvToRgbConverter.kt to convert the image and save it as Bitmap. That possibly can help us to clarify the issue happened in CameraX side or the afterward bar-code analysis. Could you please also provide which resolution was run okay with Camera1 and which resolution was run failed with CameraX? If the resolutions are different, you might also try to interchange the resolutions to know whether this issue only happens on specific resolution on the device.

polivmi1 commented 3 years ago

@CharcoalChen Thanks! With Camera 1 I used the google default sample CameraSource, which has preview resolution of 1280x960. With CameraX using the default FILL_CENTER, the default 640x480. I am not able to set resolution on the LifecycleCameraController to check different and will have to rewrite the code to use the previous classes which allow it. Is that still being implemented? Related article https://dev-victor-cold.medium.com/wow-this-is-really-what-i-was-missing-in-camerax-f618804daedd The saved image looks fine (is rotated, but I do rotate it based on imageInfo before processing).

polivmi1 commented 3 years ago

I can confirm that using the older API that allows setting camera target resolution and setting it to the same as used with Camera 1 works. I think that the default resolution with LifecycleCameraController should be fixed or allowed custom, because otherwise the barcodes won't be recognized.

CharcoalChen commented 3 years ago

@polivmi1 Thanks for providing the information. As you mentioned in the previous two comments, the saved image looks fine, therefore, the image provided by LifecycleCameraController's ImageAnalysis should have no problem. But the barcode inside it can't be recognized. This part of issue might still need to be clarified in mlkit side.

About the article you mentioned above, there has been a response and also a doc CameraX: Learn how to use CameraController for it. LifecycleCameraController is a high-level, all-in-one API that provides a way to easily access and manipulate core camera features. But not all settings API are included. Otherwise, it might make the API become complicated. I guess if the bar code inside the 640x480 image can be recognized successfully, then, the LifecycleCameraController's resolution setting might not be a problem for your application any more. If you still need the target resolution setting API to be included in LifecycleCameraController, please submit a feature request on here. Thanks.

cs-googler commented 3 years ago

@polivmi1 this might be a different issue as we have many developers confirmed that this issue was solved with the latest barcode scanning sdk. Could you provide more details for MLKit to fix your specific issue?

  1. The device model you are using
  2. The resolution setting that doesn't work with cameraX + barcode scanning

If there is a bug/something we can do better in ML Kit, we will need to reproduce your issue on our side in order to fix it for you.

polivmi1 commented 3 years ago

@cs-googler

  1. This was with Samsung S10 and Moto G5 Plus.
  2. The resolution is the default used by LifecycleCameraController, which is 640x480 and can't be set. That is too small to recognize some of the barcodes, so not using LifecycleCameraController and setting higher resolution 1280x960 helps with the barcode recognition.
cs-googler commented 3 years ago

Thanks! @polivmi1 From your description, it seems to be a cameraX not being flexible enough issue to me. For Barcode scanning and other ML vision features, we do require resolution number for the image to be recognized. Check the general guidance here. I will try to file this as an internal feature request to the camerax team.

LouisCAD commented 3 years ago

@cs-googler Why not a public issue so we can follow it instead?

orlandev commented 2 years ago

https://github.com/orlandev/qr-scanner-module

In this module I use CameraX and MlKit to read the Qr code and use them in the applications I work on. Until version 9 of Android it works correctly but from version 10 it starts to fail.

W/System.err: java.io.IOException: There is no back-facing camera. 2022-05-27 17:14:35.612 8666-8666/com.ondev.qrscanner W/System.err: at com.ondev.qrscannermodule.camera.CameraSource.createCamera(CameraSource.kt:176) 2022-05-27 17:14:35.612 8666-8666/com.ondev.qrscanner W/System.err: at com.ondev.qrscannermodule.camera.CameraSource.start$qrscanner_debug(CameraSource.kt:92) 2022-05-27 17:14:35.612 8666-8666/com.ondev.qrscanner W/System.err: at com.ondev.qrscannermodule.camera.CameraSourcePreview.startIfReady(CameraSourcePreview.kt:67) 2022-05-27 17:14:35.612 8666-8666/com.ondev.qrscanner W/System.err: at com.ondev.qrscannermodule.camera.CameraSourcePreview.access$startIfReady(CameraSourcePreview.kt:32) 2022-05-27 17:14:35.612 8666-8666/com.ondev.qrscanner W/System.err: at com.ondev.qrscannermodule.camera.CameraSourcePreview$SurfaceCallback.surfaceCreated(CameraSourcePreview.kt:133)