Detect and decode multiple 2d (Datamatrix, QRcode) from an image

≯℡__Kan透↙ 提交于 2020-01-03 01:28:11

问题


I'm working on a project which involves taking an image file as input on my desktop and then detecting and decoding all the barcodes present, both 1D and 2D.

I've been working with zxing and with the help of GenericMultipleBarcodeReader I was able to read multiple 1D barcodes from the image. However, it fails to detect 2D barcodes. But if I crop the 2D barcode and input this cropped part separately it detects and decodes it without any problem.

So, if my image has 2 1D barcode and a 2D barcode my output consists of just the 2 1D barcodes decoded.

I also tried using ByQuadrantReader but that doesn't work either.

My code:

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()));

Could anyone tell me a way to do this?


回答1:


QR codes can be found anywhere in the image, but Data Matrix must be in the center of the image to be found. This is why it's working when you crop the image.



来源:https://stackoverflow.com/questions/17994982/detect-and-decode-multiple-2d-datamatrix-qrcode-from-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!