Barcode not recognized from Java application but recognized with Android barcode app

109 views
Skip to first unread message

Peter Pinnau

unread,
Jun 15, 2016, 9:19:15 AM6/15/16
to zxing
I use zxing in a java project to detect 2D Code39 barcodes in scanned A4 documents.

In a first step I use opencv to find barcode areas. This works well and I have 300dpi images which only contain one barcode and nothing else.

Unfortunately zxing only detects 13 of my 17 test codes.

I am able to scan all failed codes with the android app directly from my computer screen.
I believe that the app uses the same core library as my java programme.


core-3.2.1.jar
javase-3.2.1.jar

Here is my code to find the barcode:

LuminanceSource lumSource = new BufferedImageLuminanceSource(scanImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource));


Map<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

try {
// Look for barcode
Result result = reader.decode(bitmap, hints);

...

I attached one of the failed images.

If I leave

hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

only 2 codes are recognized.


I also checked the bitmap.getBitMatrix() and wrote it back to a BufferedImage. The result was exactly the barcode image.

I have no idea what else to try but i am sure that there is a solution since the android app is able to decode the image.

Thanks
Peter

contour.png

Peter Pinnau

unread,
Jun 15, 2016, 11:00:24 AM6/15/16
to zxing
I tried some simple image processing in case of fail and that seems to do the trick. The scanned image contains to much black in the code for some reason.

I elimanted pixels with some neighbour conditions and now all 17 codes are recognized.

See attached file with the processed image from my first post. I will spend some further research on this and make it more flexible.

The android app recognized the code in the processed image much faster than in the original one.

That is a wide topic and commercial tools seem to have a lot of built in extras to improve recognition.

Cheers

bitmatrix_white.png

Peter Pinnau

unread,
Jun 15, 2016, 11:12:25 AM6/15/16
to zxing
Another question: For image processing I modify the BitMatrix retrieved via

BitMatrix matrix = bitmap.getBlackMatrix();

When I rerun

reader.decode(bitmap, hints);

after modification of the BitMatrix the reader still processed the old data. For a start I created a new BufferedImage + LuminanceSource + BitMap

Is there a way to manipulate the BitMatrix and rerun the reader?

Jaspreet Singh

unread,
Feb 21, 2017, 10:55:22 PM2/21/17
to zxing
Did you found any solution for this???
Reply all
Reply to author
Forward
0 new messages