Zxing NotFoundException

jsosnowski picture jsosnowski · Sep 10, 2015 · Viewed 7.1k times · Source

I try to use Zxing to decode Aztec code.

I use code from SO answer. Here is a part of it:

public static String readQRCode(String filePath, String charset, Map hintMap)
        throws FileNotFoundException, IOException, NotFoundException {
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
            new BufferedImageLuminanceSource(
                    ImageIO.read(new FileInputStream(filePath)))));
    Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap,
            hintMap);
    return qrCodeResult.getText();
}

I try to read those image by code above:

enter image description here

But this fails with:

Exception in thread "main" com.google.zxing.NotFoundException

I said - Ok, maybe it's too low quality - so I took GIMP and:

  1. Erode image with 3x3 mask.
  2. Take automatic gimp thresholding (binarize image).

That simple pre-processing gave me this:

enter image description here

Maybe it hasn't wonderful quality, but it is simply black and white - is it better? No. I still obtain:

Exception in thread "main" com.google.zxing.NotFoundException

What is strange: almost all Barcode Readers reads both without any problems. For example: NeoReader (Android - mobile phone) reads both from laptop's screen - correctly!

I want to add that absolutely clear images like this from Wiki, are correctly recognized by this code.

Question:

What is wrong with the code above?

How decode this Aztec codes? I can do any preprocessing, but what steps are require?

Please help.

Project details: Java 8, com.google.zxing:core:3.2.1, com.google.zxing:javase:3.2.1

Answer

AdamF picture AdamF · Sep 20, 2015

Please don't use jpg files, because you lose some important informations. Use lossless compression file formats like bmp or png.

I can't still read this code with zxing but another webpage: http://www.onlinebarcodereader.com/ reads it after my preprocessing:

  1. Crop Image to your aztec code only: enter image description here
  2. Create uniform array of Points (83 rows and 83 columns) and make small circles around each point (center = computed point, radius = 4): enter image description here
  3. Create matrix of size 83x83 and set the value of each matrix cell to image average in corresponding circle. The result: enter image description here
  4. Use Simple thresholding (if value < 114 then 0 otherwise 255) and save such image with quiet zone and module size as 4:

enter image description here

I don't know why online zxing reader doesn't read this code (maybe there is to much errors and you should improve a little bit the algorithm above).

The preprocessing is very easy so you can use any open source image processing library e.g. OpenCV. (I used Adaptive Vision Studio (Lite version should be enough) ).

Using online aztec reader mentioned above I receive:

mAMAAPZCAEEABr8yAjkAMX8KMAA1AP98AFAAUgBFAPtaAFkARA7/TgBUACAATd8ALgpTAL5UD1f3blIavVoOV+5OfFLXFklau0xeDndDAEFL3k8eQf06QQBMt38jd0kARH/fThpaAb1DHiDu/jBOwAauCi0K1gIzy43Oj9doLjY7SjQKwTFX2+ZVALtHCpZ2VAB8A8GTrzZSWHtqRB73VgBGor8yljgASHueRn63AjcANnuX25lnBv93/zgALW4rLfYDDg5TBV5LwQBPB3dG6rxOtlUdP6AeTO8CQRZJeypHSxseXi4qLvceLyKCLYvc89DaMfDnawc38+8wLjkMB247hjIHrw0AvQrXwSPXfyBSgjQ/Cqwwj7UaNe1uNSN9OQA3g0NhD70yN8Dv3SM4ADeDi7szNiZbLD8Wh2EXvU/uIO1HGkYPAjYHl7wyYjbokcNB1zYyw7hTO5ZNlsdDXt7TiiDhErx2GAF7ARjfMn8IVxsws3c1AkYvBje+NSNB8ANN6zPwBzj7izIj7zAT7TQAMANsOhJJJJJU/w==M