Re: Scan a datamatrix in a large file

171 views
Skip to first unread message

Sean Owen

unread,
Jun 19, 2012, 7:36:01 AM6/19/12
to zx...@googlegroups.com
Note quite sure what you mean since decode() never returns null. Are you sure about what you're reporting, or is something else going on in your real code?

tlegrand

unread,
Jun 19, 2012, 7:46:15 AM6/19/12
to zx...@googlegroups.com
Sorry. I meant that resultOfReading.getText() sends me null because, later in the code, I do this :

String result = "";
LOG
.debug(resultOfReading.getText());
result
= new String(resultOfReading.getText().getBytes("ISO-8859-1"));

Sean Owen

unread,
Jun 19, 2012, 8:25:25 AM6/19/12
to zx...@googlegroups.com
Don't think so, that value should never be able to be null either. I think you need to investigate more with a debugger. What you think is null isn't as far as I can see. Or at least you haven't said exactly what you observe.

tlegrand

unread,
Jun 19, 2012, 8:39:21 AM6/19/12
to zx...@googlegroups.com
I think the best is to show all of my code :)

private String processReading(BufferedImage bufferedImage) throws BarcodeReaderException {
   
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);  
   
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    com
.google.zxing.datamatrix.DataMatrixReader zxingReader = new com.google.zxing.datamatrix.DataMatrixReader();
   
Result resultOfReading = null;
       
   
try {
       
Hashtable<DecodeHintType, Object> decodingHints = new Hashtable<DecodeHintType, Object>();
        decodingHints
.put(DecodeHintType.CHARACTER_SET, "ISO-8859-1");
        decodingHints
.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        decodingHints
.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.DATA_MATRIX));
           
        resultOfReading
= zxingReader.decode(bitmap, decodingHints);
       
   
} catch (NotFoundException e) {
        LOG
.error("ZXing error : No datamatrix found", e);
        LOG
.error("Please check if the image dpi is not too low");
   
} catch (ChecksumException e) {
        LOG
.error("ZXing error : Datamatrix was successfully detected and decoded, but was not returned because its checksum feature failed.", e);
        LOG
.error("Please check if the image dpi is not too low");
   
} catch (FormatException e) {
        LOG
.error("ZXing error :Datamatrix was successfully detected, but some aspect of the content did not conform to the barcode's format rules", e);
        LOG
.error("Please check if the image dpi is not too low");
   
}
       
   
String result = "";
       
   
try {

        LOG
.debug(resultOfReading.getText());
        result
= new String(resultOfReading.getText().getBytes("ISO-8859-1"));

   
} catch (UnsupportedEncodingException e) {
        e
.printStackTrace();
   
}
   
return result;
}

During the process of this function, I have an exception "com.google.zxing.NotFoundException" with custom error message :
ERROR [main] com.lexpersona.lp2ddoc.barcode.DataMatrixReader - ZXing error : No datamatrix found

I know that it can't get the datamatrix but I wan't to understand why because the datamatrix is the only "guy" in a white page.
Is my code ok?  Or do I need to do something else for xzing can get the datamatrix?

Thank you for your patience :)

Sean Owen

unread,
Jun 19, 2012, 10:42:41 AM6/19/12
to zx...@googlegroups.com
That's not the same as returning null. Are you sure about what you're reporting?

The exception merely means nothing was decoded in the image. The DataMatrix decoder needs the barcode to be in the center of the image, and it's not here.
Restrict the scan to the region roughly containing the barcode in the center.

tlegrand

unread,
Jun 19, 2012, 10:56:29 AM6/19/12
to zx...@googlegroups.com
Yes, sorry. And I am sure about what I am reporting. Because I thought that XZing detects the datamatrix in the entire image without it to be in the center.
The problem is the datamatrix can be at the center, at the top-right, the bottom-left or elsewhere and I don't know how to manage that. Have you got any tricks or tips, please?

Sean Owen

unread,
Jun 19, 2012, 11:34:15 AM6/19/12
to zx...@googlegroups.com
It's a peculiarity of this decoder, yes. If you have ample CPU time available, you could brute-force it -- break the image into 4ths and scan each, break into 9ths, then 16ths, etc. You're not guaranteed to have a region that works but it probably will. Or you can yourself detect the region with what appears to be your content and crop around that.

tlegrand

unread,
Jun 19, 2012, 11:57:40 AM6/19/12
to zx...@googlegroups.com
Thank you again for your patience :)

Excellent! Have you got links to read some tutos to implements that, please?

Sean Owen

unread,
Jun 19, 2012, 12:27:01 PM6/19/12
to zx...@googlegroups.com
It's about what I say there. You can use the crop parameters of the binarizer and luminance source to specify a region of the image to look at. The rest is just a few loops of code, pretty easy to write.

Reply all
Reply to author
Forward
0 new messages