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

3
我正在尝试使用zxing库(GenericMultipleBarcodeReader)读取2D数据矩阵条形码。我在单个图像上有多个条形码。
问题在于,zing阅读器的效率非常低,它只能从图像1.png识别出1个条形码,并且无法从图像2.png(其中包含48个条形码)中识别任何条形码。是否有任何方法可以获得100%的效率或任何其他库可以实现100%的效果?
我的读取条形码的代码如下:
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());
            }
        }
    }

我使用的图片如下:

1.png 2.jpg

请帮忙解决这个问题。

谢谢

2个回答

5

情况不完全是这样的。它无法读取网格中的条形码,因为它假定可以按一定方式切割图像,但这种方式与网格不兼容。您需要编写自己的方法将图像切分为可扫描区域。

此外,数据矩阵解码器假定图像的中心在条形码内部。这是您需要预先将图像切成圆柱周围的正方形再进行扫描的另一个原因。这样做应该能够很好地工作。


@Sean-感谢您的回复,请问条形码的角度是否也可能影响读取条形码? - Raman
它应该能够在所有角度进行扫描,但是当它竖直时,它的工作效果会更好。 - Sean Owen

2
一种替代方案是考虑使用能够在一个文档上检测多个不同方向的条形码的条形码引擎。如果您正在运行 Windows 系统,则 ClearImage Barcode SDK 具有 Java API,应该能够在无需预处理的情况下满足您的需求。您可以使用他们的在线条码阅读器测试其引擎是否能够读取您的图像。
以下是一些示例代码:
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());}
 }

免责声明:我之前曾为Inlite工作过。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接