Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan multiple barcodes with zxing.net

My aim is to detect multiple datamatrices on a larger image like this (the four big):

full image

Based on several code samples, I made a small test program:

Bitmap image = getImage();

DataMatrixReader reader = new DataMatrixReader();
GenericMultipleBarcodeReader genericReader = new genericMultipleBarcodeReader(reader);
Dictionary<DecodeHintType, object> hints = new Dictionary<DecodeHintType,object>();
hints.Add(DecodeHintType.TRY_HARDER, true);

BitmapLuminanceSource source = new BitmapLuminanceSource(image);
HybridBinarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Result[] results = genericReader.decodeMultiple(binaryBitmap,hints);

show(results);

It could'nt detect any code on the large image.

But it can detect the code, when its cropped like that:

cropped

After that I merged two generated data matrices, and it failed too:

enter image description here

Last I ran two more test with slightly cropped images, both failed:

enter image description here

enter image description here

So it seems this library is not robust at all, or maybe I use it wrong.

Any idea how to improve my results? (including other libraries and preprocessing)

like image 730
András Kovács Avatar asked Jan 21 '15 18:01

András Kovács


1 Answers

It can't be said that the library is not robust but there are two key factors affecting you here:

  • Zxing's data-matrix detection algorithm assumes that the barcode is centered. Or more precisely, that the center of the image is inside the data-matrix.
  • Zxing's multiple reader specially fails when barcodes are grid-aligned.

My recommendation is to implement your own MultipleBarcodeReader taking into account what I've mentioned.

A naive approach could be to take sample images centered over a grid of points spaced so every data-matrix (no matter its position within the image) contain at least one of the points inside. You just have to make sure to exclude duplicated codes.

like image 89
mhcuervo Avatar answered Oct 17 '22 23:10

mhcuervo