Issue with scanning the QR code present in Indian aadhaar card

211 views
Skip to first unread message

Kishan Kumar

unread,
Aug 21, 2018, 8:32:16 PM8/21/18
to zxing
I am trying to decode the QR code present in the Indian aadhar card using Zxing API for the customer uploaded aadhar image on our website.

I am able to decode the QR code if its big in size and get the complete XML data. However the QR codes which are small in size are not getting decoded as QR codes. They are getting decoded as BarcodeFormat.UPC_E, which is a one dimensional bar code unlike QR code which is two dimensional. So the output for small QR codes is coming something like this 04400621, instead of the expected XML output. This is happening with the online tool https://zxing.org/w/decode.jspx as well.

Some small QR codes are getting decoded by the online tool if we crop just the QR code part of the aadhar but the API fails to decode if we pass the cropped part of the small images.

I am using below API present in com.google.zxing.MultiFormatReader class

Result decode(BinaryBitmap image, Map hints)

Putting breakpoints in MultiFormatReader library, I could see that QRCodeReader is not able to decode the QR code, however MultiFormatOneDReader is able to decode the same.

Hence the small QR codes are getting decoded as BarcodeFormat.UPC_E it seems.

Pasting the code snippet below:


String filePath = "xyz";
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(filePath);
BufferedImage bufferedImage = ImageIO.read(fileInputStream);

LuminanceSource bufferedImageLuminanceSource = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(bufferedImageLuminanceSource));

Map<DecodeHintType, Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(
DecodeHintType.class);
tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS,
EnumSet.allOf(BarcodeFormat.class));
tmpHintsMap.put(DecodeHintType.CHARACTER_SET, "ISO-8859-1");
tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);(tried with and without this option)

Result result = new MultiFormatReader().decode(binaryBitmap, tmpHintsMap);

Lachezar Dobrev

unread,
Aug 27, 2018, 8:49:22 AM8/27/18
to kisha...@gmail.com, zxing
Use only QR_CODE for POSSIBLE_FORMATS.
You're (probably) getting a False-Positive with UPC or Code-39 or
another 1D bar-code type.
> --
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

kishan

unread,
Aug 30, 2018, 9:54:58 PM8/30/18
to l.do...@gmail.com, zx...@googlegroups.com
Hi Lachezar,

Thanks for your response.
But I had already tried that.
Zxing is not able to decode the small QR codes on passing BarcodeFormat.QR_CODE and is throwing the exception: com.google.zxing.NotFoundException.

The problem is that even the online tool  https://zxing.org/w/decode.jspx  is not able to decode small QR codes.

Thanks,
Kishan.

Lachezar Dobrev

unread,
Aug 31, 2018, 8:21:30 AM8/31/18
to Kishan Kumar, zxing
If possible can you share one of these? It might be any of a
thousand reasons why the code is not recognised.

Typically though I'd suggest that you try slightly fiddling with the
image: scaling up and down, applying various blurs, applying various
sharpening. ZXing is designed to handle streams of images, and is not
a sure-shot solution when you only have one frame/image to work with.
Instead ZXing works at significantly less than 100% accuracy, but
works fast so that streams can be processes real-time. When there is
no stream, you can simulate one (by applying various modifications to
generate "frames").

kishan

unread,
Aug 31, 2018, 9:14:11 PM8/31/18
to l.do...@gmail.com, zx...@googlegroups.com
Here is a sample aadhaar image which doesn't work - https://i.stack.imgur.com/1mqTw.jpg.
Its taken from this post where someone had posted the same issue some time back with Indian aadhaar cards. The image of the QR code on an Indian aadhaar card is too small as can be seen from the above image. 
Reply all
Reply to author
Forward
0 new messages