Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
480 stars 153 forks source link

QR code Scanning doesn't work on some android phones #200

Open trampster opened 2 months ago

trampster commented 2 months ago

QR code scanning doesn't work on the following android phones:

The camera view shows but it never detects the QR code.

The preloaded camera app on these phones can scan these code successfully. And the same QR code can be scanned by ZXing.Net.Maui on other android and iOS phone models.

image

I have attached logs from trying to scan with the Oppo A54. There are logs from when the scan page is loaded but there is nothing apart from GC collection stats while its actually trying to scan.

OPPO A54 QR code scan logs.txt

We are using:

trampster commented 2 months ago

After doing some debugging in ZXing.Net.Maui we have discovered that on the phones that don't work a camera frame is being retrieved and sent to ZXing.Net which is returning null on the line:

var b = zxingReader.Decode(ls)?.ToBarcodeResult();

I suspect that there is something wrong with the luminance data.

I have managed to dump the raw data from PixelBufferHolder.Data from working and not working phones.

Interestingly the data on the phone that isn't working is significantly larger, 491 kB instead of 307 kB . Given that both should be 640x480 then they should be exactly the same size.

I've attached the raw YUV data from both the working and the not working phones.

WorkingYUVData.zip NotWorkingYUVData.zip

thdigalakis commented 1 month ago

Hi @trampster! Do you find any workaround for this issue?

trampster commented 1 month ago

No, we have just finished switching to BarcodeScanning.Native.Maui. It uses native scanning on each platform, and it works on all the android and iPhones we have tested on so far, including the ones that fail with ZXing.Net.Maui.

alex-kir commented 1 month ago

Hi, I created a pull_request to fix a similar issue https://github.com/Redth/ZXing.Net.Maui/pull/202 Now it works like a charm for me.

Using platform decoders does not work for Amazon devices.

trampster commented 1 month ago

Have you tried BarcodeScanning.Native.Maui on amazon devices, it doesn't require Google Play Services (I've tested with it disabled, as it bundles the code with your app). But I don't have access to an amazon device.

We have also found BarcodeScanning.Native.Maui to be a lot faster, if you look at the logs while ZXing.Net.Maui is running it causes a Garbage collection every few seconds because of the massive amounts of memory allocations it does for every single frame, I see that your merge request adds even more memory allocations.

alex-kir commented 1 month ago

I didn't try BarcodeScanning.Native.Maui but for several years I use my own solution based on Android.Gms.Vision.Barcodes.BarcodeDetector and on amazon devices detector.IsOperational always returns false. As I understand the Google.MLKit.Vision.BarCode.BarcodeScanning is just a new API for the same functionality.

Now I believe that MLKit will not work too on Amazon devices. Here is an indirect confirmation (maybe in the future I will try to get direct confirmation, but now I don't have enough time) https://developers.google.com/ml-kit/mobile-vision-migration/android#gmv GMV uses the isOperational() call in the API surface to indicate whether a module has been downloaded successfully and is ready to use. ML Kit has no such method. ML Kit throws an MlKitException.UNAVAILABLE exception if a module hasn't been downloaded. You can catch this exception and process the next frame or set a timeout and retry with the current frame.

In my merge request tempBuffer allocated only once (if need) and reused in the next frames without any GC triggering. I understand that the better solution is propagate stride outside but in this case, changes are needed in many places of the project, and can also affect user code