3

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

Community
  • 1
  • 1
jsosnowski
  • 1,560
  • 3
  • 26
  • 56

1 Answers1

2

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

ZZ 5
  • 1,744
  • 26
  • 41
AdamF
  • 2,501
  • 17
  • 30
  • Thanks for your reply. Later I will try your preprocessing idea. It doesn't solve whole problem, because I still need to assume some column/row number. But it's ok, I think I can handle it - in my project I can even simply do whole process several times (form value 80 - 85 for example). I really appreciate your work - thanks. – jsosnowski Sep 20 '15 at 19:27
  • 1
    Your solution works in Zxing! At least for above example image. Online Zxing decodes it successfully only after passing image by URL (not file - weird). Here is output: https://zxing.org/w/decode?u=http%3A%2F%2Fi.stack.imgur.com%2FJ3Hj7.png Tomorrow I will check if this image is also decoded by Zxing Java library. Thanks a lot. – jsosnowski Sep 20 '15 at 19:35
  • Could you explain a little bit more descriptive how to achieve final effect from the third step? – ZZ 5 Oct 07 '15 at 12:45
  • 1
    @ZZ5 In the third step we have gray based image in size 83x83px so you have to check if the gray value of each pixel is less than 114 (in this example 114 gives nice result). If it's less then in final matrix you put black pixel otherwise white pixel. Use google to read more about Image Thresholding. – AdamF Oct 07 '15 at 19:00
  • I was following your method, but without acceptable effects. For my base I've used the same image that you've used and after third step I get [0] and in the fourth step [1] (or [2] using Otsu's method). What could I've done wrong? [0] http://i.imgur.com/AU430xR.jpg [1] http://i.imgur.com/BAqxoJU.jpg [2] http://i.imgur.com/1NdcbHj.jpg – ZZ 5 Oct 12 '15 at 08:00
  • 1
    @ZZ5 Unfortunately I don't see your code so I can't help you . If you want to see my solution, here is it (I changed it a bit, according to my post): https://onedrive.live.com/redir?resid=E945F827BB83662A!106&authkey=!AMpjrdTqEW02CV8&ithint=file%2czip . To open the file Program.avlite you should download "Adaptive Vision Studio 4.3 Lite". I think it should help you to write the solution in any other language like Java/c++. – AdamF Oct 12 '15 at 18:52