从图像中检测并解码多个2d(Datamatrix,QRcode) [英] Detect and decode multiple 2d (Datamatrix, QRcode) from an image

查看:228
本文介绍了从图像中检测并解码多个2d(Datamatrix,QRcode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,该项目涉及将图像文件作为桌面上的输入,然后检测和解码存在的所有条形码(一维和二维).

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.

我一直在与zxing一起工作,并且在GenericMultipleBarcodeReader的帮助下,我能够从图像中读取多个一维条形码.但是,它无法检测到二维条形码. 但是,如果我裁剪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.

因此,如果我的图像具有2个1D条形码和2D条形码,则我的输出仅包含2个解码的1D条形码.

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

我也尝试使用ByQuadrantReader,但这也不起作用.

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

我的代码:

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?

推荐答案

QR码可以在图像中的任何位置找到,但是Data Matrix必须位于图像的中心.这就是为什么在裁剪图像时它会起作用的原因.

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.

这篇关于从图像中检测并解码多个2d(Datamatrix,QRcode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆