ZXing库无法解码Datamatrix条码 [英] ZXing library can't decode Datamatrix barcode

查看:608
本文介绍了ZXing库无法解码Datamatrix条码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ZXing库来解码Datamatrix条形码。以下是我的代码示例:

  BufferedImage bi = img.getBufferedImage(); 

Hashtable< DecodeHintType,Object> hints = new Hashtable< DecodeHintType,Object>();
hints.put(DecodeHintType.TRY_HARDER,Boolean.TRUE);

LuminanceSource source = new BufferedImageLuminanceSource(bi);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader dataMatrixReader = new DataMatrixReader();

try {
结果res = dataMatrixReader.decode(bitmap,hints);
System.out.println(resultText =+ res.getText());
} catch(例外e){
System.out.println(未能获得resultText);
e.printStackTrace();
}

我在推荐 here 此处。如果我以编程方式将此图像转换为黑白并将图像裁剪为绑定条形码,仅在其周围有一些空白区域,那么ZXing可以与这样的图像完美配合。但问题是真实的条码可能会有很小的变形,所以我简单的算法无法帮助我正确裁剪图像。更多的条形码可能不是准确地放在图像的中心,冷的亮度有点不同。我看到线程提到OpenCV功能,以找出图像上的物品对象的位置,例如这一个 ,但他们已经很老了。从那以后发生了什么变化?在我的具体情况下,我还应该考虑编写100%可靠的datamatrix解码器(和探测器)?



我决定提供由.toString组成的LuminanceSource和BinaryBitmap图像()相应对象的文本输出以供参考:
http://s28.postimg。 org / l53sykhx9 / Binary_Bitmap.png



和/65z0vlbpl/Luminance_Source.png(在同一个域中)。它们看起来很好并且已经准备好进行解码,但是解码后出现了什么问题。



所有这些图像和类似的图像都被智能手机软件识别和解码得很好我想要获得相同的结果。

解决方案

您需要通过编程或手动设置启用它。



在DecodeThread.java类中,您可以看到启用数据矩阵编码的行

  decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); 


I'm trying to use ZXing library to decode Datamatrix barcode. Here are my code sample:

BufferedImage bi = img.getBufferedImage();

Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

LuminanceSource source = new BufferedImageLuminanceSource(bi);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader dataMatrixReader = new DataMatrixReader();

try {
    Result res = dataMatrixReader.decode(bitmap,hints);
    System.out.println("resultText = "+res.getText());
} catch (Exception e) {
    System.out.println("failed to get resultText");
    e.printStackTrace();
}

I've seen almost the same samples many times accross https://stackoverflow.com/ and other sites, but this approach does not working for me in this form.

As a source I'm using images grabbed from IR-camera. Here are example image: As you see, the barcode is almost exactly at the center of an image, as Sean Owen recommended here and here. If I programmatically convert this image to black&white and crop image to bound barcode with some white space around it only, then ZXing works perfectly with images like this. But the problem is that barcode in real could have little deformations, so my simple algorythm can't help me to crop image properly. More over barcode could be placed not exactly in the center of an image and cold have a little bit different brightness. I saw threads mentioning OpenCV capabilities to find out placement of speciects objects on the image, like this one, but they are quite old. Is something changed since then? And what should i yet certainly consider to write 100% reliable datamatrix decoder (and detector) in my specific situation?

I decided to supply LuminanceSource and BinaryBitmap images made of .toString() text output of correcponding objects for reference: http://s28.postimg.org/l53sykhx9/Binary_Bitmap.png

and /65z0vlbpl/Luminance_Source.png (at the same domain). They are looking good and ready for decoding, but what is wrong with decoding then.

After all this image and similar ones recognized and decoded very well with smartphone software and i'm just wanted achieve same results.

解决方案

you need to enable it from settings programmatically or manually.

in class DecodeThread.java you can see the line that enables data matrix encoding

decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);

这篇关于ZXing库无法解码Datamatrix条码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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