我正在其涉及我的桌面上拍攝圖像文件作爲輸入,然後檢測和存在的所有條形碼進行解碼,一維和二維項目解碼多個2D(二維條碼,QRCODE)。檢測並從圖像
我一直與斑馬線與GenericMultipleBarcodeReader的幫助,我能夠從圖像讀取多個一維條碼。但是,它無法檢測二維條形碼。 但是,如果我裁剪二維條形碼並單獨輸入此裁剪後的部分,它將檢測並解碼它,而不會出現任何問題。
因此,如果我的圖像有2個1D條形碼和一個2D條形碼,我的輸出只包含2個1D條形碼解碼。
我也嘗試使用ByQuadrantReader,但那也不起作用。
我的代碼:
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result[] result;
HashMap<DecodeHintType,Object> hints = new HashMap<>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try
{
result = new GenericMultipleBarcodeReader(new MultiFormatReader()).decodeMultiple(bitmap, hints);
}
catch (ReaderException re)
{
return re.toString();
}
List<String> strings = new ArrayList<String>();
for (Result r: result)
{
strings.add(r.getText());
}
return String.valueOf(Arrays.toString(strings.toArray()));
誰能告訴我一個辦法做到這一點?
@Skippy 'LuminanceSource源=新BufferedImageLuminanceSource(圖像); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); 結果[]結果; HashMap hints = new HashMap <>(); hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE); 嘗試{ 結果=新GenericMultipleBarcodeReader(新MultiFormatReader())decodeMultiple(位圖,提示)。 } catch(ReaderException re){ return re.toString(); } 列表串=新的ArrayList (); (結果r:結果){ strings.add(r.getText()); } 返回將String.valueOf(Arrays.toString(strings.toArray()));' –
Rohit
很抱歉的差格式。我是新來的,還沒有想出如何在這裏格式化我的代碼。 – Rohit
@Skippy感謝您的格式鏈接,將會等待您對代碼的幫助。 – Rohit