简体   繁体   English

使用zxing库读取多个条形码的问题

[英]Issue to read multiple barcodes using zxing library

I am trying to read 2D Data matrix barcode using zxing library(GenericMultipleBarcodeReader). 我正在尝试使用zxing库(GenericMultipleBarcodeReader)读取2D数据矩阵条形码。 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. 问题在于zing阅读器的效率非常低,它识别来自图像1.png的1个条形码,而没有来自图像2.png的具有48个条形码的条形码。 Is there any way to get 100% efficiency or any other library which results 100% 有没有办法获得100%的效率或任何其他图书馆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.png2.JPG

Please help to resolve this issue. 请帮助解决此问题。

Thanks 谢谢

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. 它应该工作得相当好。

An alternative solution is to consider a barcode engine that can detect multiple barcodes in various orientations on one document. 另一种解决方案是考虑条形码引擎,该条形码引擎可以在一个文档上检测各种方向上的多个条形码。 If you're running on Windows, the ClearImage Barcode SDK has a Java API and should be able to handle your needs without pre-processing. 如果您在Windows上运行, ClearImage Barcode SDK具有Java API,应该能够在不进行预处理的情况下满足您的需求。 You can test if their engine can read your image using their Online Barcode Reader . 您可以使用在线条形码阅读器测试他们的引擎是否可以读取您的图像。

Some sample code: 一些示例代码:

public static void testDataMatrix () {
  try { 
       String filename  = "1.png ";
       CiServer objCi = new CiServer();
       Ci = objCi.getICiServer();

       ICiDataMatrix reader = Ci.CreateDataMatrix(); // read DataMatrix Barcode
       reader.getImage().Open(filename, 1);
       int n = reader.Find(0); // find all the barcodes in the doc
       for (i = 1; i <= n; i++) {
          ICiBarcode Bc = reader.getBarcodes().getItem(i); // getItem is 1-based
          System.out.println("Barcode " + i + " has Text: " + Bc.getText());
       }
   } catch (Exception ex) {System.out.println(ex.getMessage());}
 }

Disclaimer: I've done some work for Inlite in the past. 免责声明:我过去为Inlite做过一些工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM