2012-10-04 74 views
3

我想使用zxing庫(GenericMultipleBarcodeReader)讀取二維數據矩陣條形碼。我在單個圖像上有多個條形碼。使用zxing庫讀取多個條形碼問題

的問題是,在尖嘯聲讀取器的效率是很低的,它 識別從圖像1.png 1個條形碼和沒有從具有48個條形碼圖像2.png條形碼。有 任何方式來獲得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

請幫忙解決此問題。

感謝

回答

4

它並不完全以這種方式工作。它不會讀取網格中的條形碼,因爲它假定它可以以某種與網格不兼容的方式剪切圖像。您將不得不編寫自己的方法將圖像剪切成可掃描區域。

數據矩陣解碼器假定圖像的中心位於條形碼內部的情況也是如此。這是您需要將圖像預先切割成圓柱體周圍的正方形然後掃描的另一個原因。那麼它應該工作得很好。

+0

@肖恩 - 感謝您的回覆,請告訴我是條碼的角度也可能是讀條碼的問題? – Raman

+0

它應該能夠以所有這些角度進行掃描,但是它在豎直時會更好地工作。 –

2

另一種解決方案是考慮一個條形碼引擎,它可以檢測一個文檔上多個方向上的多個條形碼。如果您在Windows上運行,ClearImage Barcode SDK具有Java API,並且應該能夠處理您的需求而無需預處理。您可以測試他們的引擎是否可以使用他們的Online Barcode Reader來讀取您的圖像。

一些示例代碼:

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一些工作。