用于检测图像中的QRCode的示例代码 [英] sample code to detect QRCode in an image

查看:84
本文介绍了用于检测图像中的QRCode的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中使用此代码对QRCode进行解码(但无法检测到),并且有效:

I use this code in C# to decode (not detect) a QRCode and it works:

LuminanceSource ls = new RGBLuminanceSource(image, image.Width, image.Height);
Result result = new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(ls)));

现在,我想在更复杂的图像中检测QRCode,其中包含许多其他内容,例如图像和文本.我无法理解如何完成此操作,因为我找不到任何示例,而且将位图(C#)转换为检测器的Bitmatrix(zxing)并不是那么直接.

Now I would like to detect a QRCode in a more complex image with a lot of other stuffs such images and text. I'm not able to understand how to accomplish this because I cannot find any sample and transforming Bitmap (C#) to Bitmatrix for Detector (zxing) is not so direct.

有人有一段代码可以给我吗?

Does anyone have a piece of code to give me?

非常感谢

我尝试了这段代码,但出现了ReaderException:

I try this code but I get a ReaderException:

代码:

LuminanceSource ls = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);            
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] rs = multiReader.decodeMultiple(new BinaryBitmap(new HybridBinarizer(ls)), hints);
 return rs[0].Text;

例外

com.google.zxing.ReaderException:

in com.google.zxing.qrcode.detector.FinderPatternFinder.selectBestPatterns()
   in com.google.zxing.qrcode.detector.FinderPatternFinder.find(Hashtable hints)
   in com.google.zxing.qrcode.detector.Detector.detect(Hashtable hints)
   in com.google.zxing.qrcode.QRCodeReader.decode(BinaryBitmap image, Hashtable hints)
   in com.google.zxing.qrcode.QRCodeReader.decode(BinaryBitmap image)
   in ...Logic.BarCodeManager.QRCodeReader(Bitmap bitmap) in 


更新02/12/2011


我刚刚尝试用iPhone上的应用程序扫描打印的QRCode(帖子顶部的代码段),并且效果很好!因此,问题肯定在检测/解码阶段.


UPDATE 02/12/2011


I have just tried to scan the printed QRCode (with the piece of code on the top of the post) with an App on my iPhone and it works well! So the problem is surely in the detection/decode phase.

推荐答案

虽然很旧.我仍然想发布它,以防有人需要.图像的噪声使zxing难以检测到qrcode.如果图像无噪点,则效果会更好.我使用一种简单的方法来减少扫描图像的噪点.可以通过缩小图像来完成.缩小因数可能会因图像的噪点而异.我发现因子3在我的情况下效果很好.

Though it's old. I still want to post it in case someone needs it. The noise of images makes them difficult for zxing to detect qrcodes. The results are much better if the images are noise free. I use a simple method to reduce noise of scanned images. It can be done by shrinking the image. The shrink factor may vary by the noise of images. I found the factor 3 works fine in my case.

这篇关于用于检测图像中的QRCode的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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