Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

java - Issue to read multiple barcodes using zxing library

I am trying to read 2D Data matrix barcode using zxing library(GenericMultipleBarcodeReader). I have multiple barcodes on a single image.

The problem is that the efficiency of the zing reader is very low, it recognizes 1 barcode from image 1.png and no barcode from image 2.png which has 48 barcodes. Is there any way to get 100% efficiency or any other library which results 100%

My code to read barcode is:

public static void main(String[] args) throws Exception {
        BufferedImage image = ImageIO.read(new File("1.png"));
        if (image != null) {
            LuminanceSource source = new BufferedImageLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            DataMatrixReader dataMatrixReader = new DataMatrixReader();

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

            GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(
                    dataMatrixReader);
            Result[] results = reader.decodeMultiple(bitmap, hints);

            for (Result result : results) {
                System.out.println(result.toString());
            }
        }
    }

And images I used are:

1.png 2.jpg

Please help to resolve this issue.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It doesn't quite work this way. It will not read barcodes in a grid, as it makes an assumption that it can cut up the image in a certain way that won't be compatible with grids. You will have to write your own method to cut up the image into scannable regions.

It is also the case that the Data Matrix decoder assumes the center of the image is inside the barcode. This is another reason you need to pre-chop the image into squares around the cylinders and then scan. It ought to work fairly well then.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...