journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.78k stars 1.27k forks source link

Read Color QR code #693

Open duttabhishek0 opened 2 years ago

duttabhishek0 commented 2 years ago

Not able to read QR codes that are colored and have a logo in between

Which library version are you using? v4.3.0

Which phone/tablet are you using, and which Android version does it run? Tested on Samsung A51 and Samsung Note 20(API 31/Android 11)

Does the same happen on other devices or an emulator? yes

In the case of an error do you have a stack trace or adb logs? NA

I want to scan QR codes that are colored and have a logo in between. Unfortunately, nothing happens the scanner just scans unless and until I go back.

rkistner commented 2 years ago
  1. Can you post a sample of the barcode that fails to scan?
  2. Does it work in other barcode scanners, such as this one?

In general, QR codes should have a dark foreground on a light background. The color shouldn't matter, as long as the contract is high enough.

If the QR code has a light foreground on dark background, you'll have compatibility issues with many barcode scanners. With this library, you can use the "INVERTED_SCAN" or "MIXED_SCAN" modes - see this: https://github.com/journeyapps/zxing-android-embedded/blob/e48229ac3f47318e4b5516c645147d7dea37dc28/sample/src/main/java/example/zxing/MainActivity.java#L42

If there is a logo in between, there is also a chance that it removes too much info to be able to scan properly.

duttabhishek0 commented 2 years ago
  1. Can you post a sample of the barcode that fails to scan? image

  2. Does it work in other barcode scanners, such as this one? No

rkistner commented 2 years ago

In this case the logo is not specifically an issue, but the contrast is simply too low for the current algorithms to work well.

If you have control over how the barcodes are generated, pick a much darker color for the foreground. If you can't, you'll have difficulty with these barcodes.

duttabhishek0 commented 2 years ago

Yes I can change the contrast. I will do the needful. Thanks for help :)

khavnu commented 2 years ago
  1. Can you post a sample of the barcode that fails to scan? image
  2. Does it work in other barcode scanners, such as this one? No

Result is: https:\www.google.com

First, i think need to reduce image contrast, it work but not good as i expected. (for camera scan: you can do this in SourceData.class with YUVLuminaceSource. For image scan you can convert bitmap to black and white bitmap)

After more research and trick, this is my solution: You can use GlobalHistogramBinarizer instead of HybridBinarizer(ex: in MixedDecoder.java). This might affect to performance Hope this help!

henry-leu commented 2 years ago

Hi,

I also have the same issue reading the qr image. My company has this greenish qr image. The qr image contains JWT token string. ZXing is able to read it. But the parse result is not a JWT string. It is an arbitrary string.

May I know what the issue is? Could it be the image size too big? Color of the image?

Thanks!

rkistner commented 2 years ago

If it scans and gives a result, the issue is not likely with the color or size of the image.

Check what results you get with other scanners. It's possible that it's an issue with how the barcode was encoded, rather than with the scanning. If you do get different results with other scanners, create a new issue here with a sample of the barcode.

henry-leu commented 2 years ago

I use the built-in scanner on iPhone. It gave me a correct JWT token text.

emartynov commented 6 months ago

So any recommendation what to do with QR code in the dark mode?

I tried the solution above with the MIXED scan type but it didn't work.

emartynov commented 5 months ago

Let me put an example here:

Screenshot 2024-07-05 at 17 08 22

~This is recognised by Android camera app but not with this library.~

Actually, I made a mistake and MIXED mode is working for the QR above.