Skip to content
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

Inconsistent scanning of dense QR codes? #352

Closed
joel-speedwell opened this issue Sep 15, 2021 · 7 comments
Closed

Inconsistent scanning of dense QR codes? #352

joel-speedwell opened this issue Sep 15, 2021 · 7 comments

Comments

@joel-speedwell
Copy link

joel-speedwell commented Sep 15, 2021

Hello,

I'm not sure if this is the right place to create this issue. I am trying to scan a dense QR code, similar to this: https://i.stack.imgur.com/BDY0Q.png

However MLKit is very inconsistent with picking up this style of QR code. I have compared performance with Apple's built-in QR code detection and the latter performs a lot better. I'm not sure if MLKit's built-in barcode scanning model is not optimized for this style of QR code?

Just wanted to ask if anyone has any suggestions.

Thanks.

EDIT: I have also been testing with a proprietary library that produces much better results: https://www.dynamsoft.com/codepool/read-qr-codes-with-high-density.html

@miworking3
Copy link
Collaborator

miworking3 commented Sep 15, 2021

According to ML Kit's guideline

For ML Kit to accurately read barcodes, input images must contain barcodes that are represented by sufficient pixel data.

The specific pixel data requirements are dependent on both the type of barcode and the amount of data that's encoded in it, since many barcodes support a variable size payload. In general, the smallest meaningful unit of the barcode should be at least 2 pixels wide, and for 2-dimensional codes, 2 pixels tall.

...
Denser formats, such as PDF417, need greater pixel dimensions for ML Kit to reliably read them. For example, a PDF417 code can have up to 34 17-unit wide "words" in a single row, which would ideally be at least 1156 pixels wide.

As for the example in iOS built-in camera, it is only recognized when set to a higher resolution.
The same to ML Kit, it will help to set a higher Preset for dense QR codes.

@joel-speedwell
Copy link
Author

Hello, thanks for the quick response!

Apologies for not making this clear in my question: I am actually developing the app on Android and was comparing performance with the iOS version of our app (using Apple's QR code API).

Do you have any suggestions for settings that we could tweak (equivalent to the "preset" you mentioned for iOS) except for Android?

Thanks again.

@SilverDestiny
Copy link
Collaborator

The guideline above is also suitable for Android: https://developers.google.com/ml-kit/vision/barcode-scanning/android#input-image-guidelines

Did you try the latest V3 barcode scanner? It gives much better performance and result than before, and the version is 17.0.0, which was recently released on 8/11.

I also test this sample dense QR code by ML Kit Barcode scanner https://i.stack.imgur.com/BDY0Q.png
It looks like we need to set higher resolution for the input image to properly scan this QR code. Low resolution seems hard to detect it.

And FYI ML Kit barcode scanning model was trained to scan all types of barcodes. If your app only focus on QR code format, you can set the barcode format in BarcodeScannerOptions to only scan QR codes, which would probably help a little bit. https://developers.google.com/ml-kit/vision/barcode-scanning/android#1.-configure-the-barcode-scanner

@joel-speedwell
Copy link
Author

Hey @SilverDestiny , thanks for the response and ideas. Yes I am using version 17.0.0. I agree increasing the resolution would help - currently I am using the CameraX API with an ImageAnalysis use case and it's giving me 1088x1088 resolution images, but even that resolution seems insufficient.

Here is an example of one of our QR codes at the resolution that we're working with:
https://i.imgur.com/nXYRGoy.png

I'm starting to think we will need to do our own pre-processing on the image, e.g. to correct the skew, the slight blur in the top left corner, apply binarization, etc. as it seems like MLKit can't handle an image at this quality for this density of QR code.

If you have any ideas/suggestions it would be much appreciated. Thank you both for your time.

@SilverDestiny
Copy link
Collaborator

https://i.imgur.com/nXYRGoy.png
Yeah this one is indeed hard to detect..Is it easy to be detected by other scanners?

I'm not sure if 1088x1088 is enough for this high density of QR codes. Is it possible to rescale it to higher resolution?
And I feel for this type of QR codes, probably needs high-quality inputs.
ML Kit upgraded the Barcode model recently and will optimize more in later releases. :)

@miworking3
Copy link
Collaborator

Closing as this thread haven't got update in 17 days. Please reopen it with if any further questions. Thanks.

@andyrooc23
Copy link

This is still a problem for me. High pixel density not working on iPhone 15, ~1800 character qrcode. Not detecting in mlkit but detecting on native camera...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants