Help with problem QRCode.

41 views
Skip to first unread message

James Russo

unread,
Sep 22, 2014, 8:02:03 PM9/22/14
to zx...@googlegroups.com
Hello,

For some reason this QR code is not being scanned. I can scan it via an QR app on my iPhone just fine, but via in our system where it is extracted from a PDF and then used for document routing it is not working. For some reason this one got kicked out and I'm trying to track down why? There seems to be a bit of noise on the image, and it's a bit skew'd, but nothing too crazy.

I get Format Exception when trying to scan it with the following code. Any suggestions?

public static void main(String[] args) throws COSVisitorException,
NotFoundException, ChecksumException, IOException, FormatException {

BufferedImage bufferedImage = ImageIO.read(new File("test.jpg"));
LuminanceSource lumSource = new BufferedImageLuminanceSource(
bufferedImage);

BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource));

Result result = new QRCodeReader().decode(bitmap);

System.out.println("Results:" + result.getText());

}

thanks,

-jr


2014_09_22_16_06_33_barcode.jpg

Lachezar Dobrev

unread,
Sep 23, 2014, 5:44:52 AM9/23/14
to James Russo, zxing
This is just how things work :-/
The library is not 100% accurate, and expects a shot-gun approach:
when one fails many more are to follow. When scanning with a phone you
get lots of attempts (20-30 per second), and every attempt uses a
slightly different image.
In *THIS* case you can make the image scan by downscaling 50%.
Whenever I need to scan bar-codes from scanned documents, and I have
a substantial (not mobile) CPU power I make a series of attempts with
the same image but apply various distortions: downscaling, blurring.
That does seem to help, but never reaches 100% success.
> --
> 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.
2014_09_22_16_06_33_barcode-half.jpg

James Russo

unread,
Sep 23, 2014, 6:56:12 AM9/23/14
to Lachezar Dobrev, zxing
Hello, 

Thanks for looking at this for me. Do you think the skew of the image is relevant in it not scanning? I will implement some various things since I am not CPU limited.

Also -- it seems that since I am getting format error, it knows there is a barcode there but just cannot read it, right? Otherwise I would be getting barcode not found. I am thinking I don't need to do these distortions if I get NOT_FOUND, right?

much thanks!

-jr

Lachezar Dobrev

unread,
Sep 23, 2014, 12:15:28 PM9/23/14
to James Russo, zxing
Yes, I think skewing is relevant, but not by much. ZXing can
overcome some defects like rotation and perspective distortions, and I
believe skewing is also correctable, but do not quote me on the last
one. It just happens, that ZXing does not succeed in all cases.
Sometimes ZXing fails to find the Bar-Code it generated (and needs a
PURE_BARCODE hint to find it).

You should try "distortions" even when you get a NOT_FOUND. It might
be that ZXing finds a QR Code, which can not be read. It might be that
ZXing totally fails to find the bar-code. There is no guarantee for
either case.
Also. Remember to use the TRY_HARDER hint when decoding if you are
not limited in CPU use.

James Russo

unread,
Sep 23, 2014, 12:33:45 PM9/23/14
to Lachezar Dobrev, zxing
Ok, thanks for the insight...

-jr
Reply all
Reply to author
Forward
0 new messages