Decoding QRCode (Java) - Problem with Finder Patterns

1,310 views
Skip to first unread message

bryl...@gmail.com

unread,
Feb 25, 2011, 2:05:24 PM2/25/11
to zx...@googlegroups.com
Hello!

This is my first contact with ZXing Library and I am trying to create an application (in future working on Android, currently on Win7 PC) for extracting data from QRCodes and processing it. So basically my goal is to extract the code about QRCodes and on that basis create my own application.

As for the "creating codes" part, everything went ok so far. But I've encountered a small problem in "extract data" part of the code.

Here's the thing:
I've written a simple test to grab the general concept of the code, basing on the Developer Notes ( http://code.google.com/p/zxing/wiki/DeveloperNotes ):

/* necessery imports */

public class Test {
     public static void main(String[] args) throws Exception {
          BufferedImage img = ImageIO.read(new File("qrcode_sample.jpg"));

          LuminanceSource source = new BufferedImageLuminanceSource(img);
          BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
 
          Reader reader = new QRCodeReader();
          Result result = reader.decode(bitmap);

          System.out.println(result.getText());
     }
}


The debugger threw NotFoundException from that part of the code:
File: FinderPatternFinder.java

...
private FinderPattern[] selectBestPatterns() throws NotFoundException {

    int startSize = possibleCenters.size();
    if (startSize < 3) {
      // Couldn't find enough finder patterns
      throw NotFoundException.getNotFoundInstance();
    }
...

In my understanding of that exception, the application can't find those three corner-markers in the qrcode_sample.jpg image. But I've tried many images, from camera, from internet and even perfectly formed QRCodes created in paint. Nevertheless, I've still failed to achieve a single string with information. Can you help me with finding the anwser?

Generally speaking all I need to have are the means to:
-scan an image from the phone's camera
-read the qrcode from the image
-extract text data from the qrcode

The rest will be handled by my code. No sharing, no database saving, no other code formats than QR. Thank you for your help.

Mateusz

Sean Owen

unread,
Feb 25, 2011, 2:11:46 PM2/25/11
to zx...@googlegroups.com
You'd have to post your image(s).

Mateusz Bryła

unread,
Feb 25, 2011, 2:18:27 PM2/25/11
to zxing

Sean Owen

unread,
Feb 25, 2011, 4:04:45 PM2/25/11
to zx...@googlegroups.com
Second one decodes fine:

The first one is rejected as invalid, I am not sure why.
I don't think it's a library issue though, in either case.

bryl...@gmail.com

unread,
Feb 25, 2011, 6:13:49 PM2/25/11
to zx...@googlegroups.com
Indeed, I also thing that there is something wrong with my code. But what? I can't imagine where could I make a mistake, when I've almost rewritten the code from developer's notes...

Lachezar Dobrev

unread,
Feb 26, 2011, 8:09:31 AM2/26/11
to zx...@googlegroups.com
I was able to read both images with the Android application.
Both read "Matheusz Bryla" (with a stroked l).

2011/2/26 bryl...@gmail.com <bryl...@gmail.com>:

Lachezar Dobrev

unread,
Feb 26, 2011, 8:18:36 AM2/26/11
to zx...@googlegroups.com
Doh... Weird!

Using the Command Line Runner the pure QR code is read pronto. The
other image fails to read, but merely scaling it down 1:10 makes it
readable in a blink!

Probably an issue with large images?

2011/2/26 Lachezar Dobrev <l.do...@gmail.com>:

bryl...@gmail.com

unread,
Feb 26, 2011, 8:40:18 AM2/26/11
to zx...@googlegroups.com
There was something mentioned somewhere on the zxing wiki, that the camera has to be in the proper distance from the code. That solves the problem with why the original application didn't scan the second image previously, but my problem is still left unsolved!

What is wrong there? Or maybe I missed an important section? Can anyone write me a sketch of a simplest possible application which decodes the text message from qr code given a specific picture?

Maybe it's my understanding of the zxing library that fails here...
Reply all
Reply to author
Forward
0 new messages