1

I am new to zxing library and so to QR Codes. Using zxing library 1.7 I have generated QR codes, those QR codes are sticked to the papers and papers are later scanned in a PDF. I do have created client program of course using zxing library itself which reads this scanned PDF page by page and shows QR Code text if any QR Code is found on a page. I am trying to read multiple QR from each page of scanned PDF.

Though I am able to read some QR code the result is inconsistent. Means I am able to read some QR code in a PDF page while some of them are not getting recognized by my client program. I have gone through other threads for same topic. and modified my code a little though I am not able to get 100% result.

Here is my code snippet to give more idea about what I am exactly doing.

Note: I am using PdfReaderContentParser of itext PDF library to extract scanned image of each pdf page as shown here

private void extractBarcodeText(BufferedImage bufferedImage) {

    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.TRY_HARDER, BarcodeFormat.QR_CODE);
        LuminanceSource source = new com.google.zxing.client.j2se.BufferedImageLuminanceSource(bufferedImage);
        BinaryBitmap bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        List<String> innerTextList = new ArrayList<String>();
        QRCodeMultiReader multiReader = new QRCodeMultiReader();
        Result[] results = multiReader.decodeMultiple(bitmap, hints);

        for (int k = 0; k < results.length; k++) {
            String text = results[k].getText();
            innerTextList.add(text);
            System.out.println("####################  Rendered Text from Image #################"+ " " + text);
        }       
    } catch (NotFoundException e) {
        e.printStackTrace();
    }
}

I have tried many combinations but no luck. Is it due to poor image quality ? But then how some images are getting recognized and some remains as a mystery :(

Do anyone know what should I do to overcome this issue? Here is one sample image at bottom for your reference, in that first image is getting recognized using above code where second one (HRA) is not.!

Community
  • 1
  • 1

1 Answers1

0

My guess based on what you've said is that you need to lightly blur or down-sample the image. The large amount of white noise interferes with detection.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • Thanks Sean for your reply. But can you please let me know how can I do that lightly blur or down-sample the image and with zxing library we can do that ? – Shrenik Patel Feb 16 '12 at 10:00
  • You can use AWT's transformations to resize or blur -- search on the internet. It will operate on a `BufferedImage`. – Sean Owen Feb 16 '12 at 10:33
  • Thanks Sean. I added a blur and it has improved the recognition but I still see about 20%-30% errors. Please see the attached images at the bottom that were not recognized. This is the code that I used. Is there anything that I can do to improve the detection rate. Also, should I resize larger or smaller. In addition is there any other image manipulation that I can do? Does the algorithm work better with coloured or black and white images? – Shrenik Patel Feb 17 '12 at 13:25
  • Here is the code I am using to blur an image: [link](https://gist.github.com/1853394) Here are the images which are not being read: First Image [link](http://imgur.com/2wAcf) Second Image [link](http://imgur.com/2fiAn) – Shrenik Patel Feb 17 '12 at 13:25
  • @SeanOwen What do you mean exactly when down-sample the image? Can you also explain why we have to lightly blur the image? I don't get it Thanks. By the way, Im having similar problem with Shrenik Patel. – She Smile GM Mar 21 '13 at 06:13
  • Down sample means to convert to a lower resolution. You don't *have* to do anything. I'm suggesting why these particular images don't decode and explained why above. – Sean Owen Mar 21 '13 at 08:31