Please help: QR Code Reading Problem.

199 views
Skip to first unread message

Steven Ang

unread,
Apr 30, 2015, 2:32:35 AM4/30/15
to zx...@googlegroups.com
I am trying to create a code which can read the QR Code from an image file.
I found out that the code can work with PNG formatted file but cannot work with JPEG.

Can any one here help me to find out the reason why it doesn't work with JPEG?

public static void deCodeQRCode(File inputFile,
Map<DecodeHintType, Object> hints) throws Exception {

BufferedImage image;
LuminanceSource tempSource;
BinaryBitmap bitmap;
MultiFormatReader codeReader;
Result tempResult;
String finalResult;

if (inputFile == null || inputFile.getName().trim().isEmpty()) {
throw new IllegalArgumentException("File not found.");
}

try {

image = ImageIO.read(inputFile);

} catch (Exception e) {
throw new Exception (e.getMessage());
}

if (image == null) {
throw new IllegalArgumentException("Could not decode the image");
}

tempSource = new BufferedImageLuminanceSource(image);
bitmap = new BinaryBitmap(new HybridBinarizer(tempSource));
codeReader = new MultiFormatReader();

try {

if (hints != null && ! hints.isEmpty()) {
tempResult = codeReader.decode(bitmap, hints);
} else {
tempResult = codeReader.decode(bitmap);
}

finalResult = String.valueOf(tempResult.getText());

System.out.println(finalResult);

} catch (Exception e) {
e.printStackTrace();
throw new Exception("QRCodeUtil.decode Exception. " + e.toString());
}

}

The following error message appear's when reading an JPEG image

com.google.zxing.NotFoundException
java.lang.Exception: QRCodeUtil.decode Exception. com.google.zxing.NotFoundException
at cn.aws.testautomation.common.QRCodeUtil.deCodeQRCode(QRCodeUtil.java:128)
at cn.aws.testautomation.common.QRCodeUtil.main(QRCodeUtil.java:210)

Thank you and good day.
sample_01.jpg
sample_01.png

Lachezar Dobrev

unread,
Apr 30, 2015, 5:28:38 AM4/30/15
to Steven Ang, zxing
It works if you use the TRY_HARDER hint.
JPEG is a lossy compression. It is possible, that it has added
artefacts that affect the algorithms.
> --
> 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.

Lachezar Dobrev

unread,
Apr 30, 2015, 7:10:16 AM4/30/15
to Steven Ang, zxing
The size of the images is different too.
Resizing the .jpg to the (nearly) same size (in pixels) also helps
and the bar-code can be found and read.
Reply all
Reply to author
Forward
0 new messages