示例代码,用于检测图像中的QRCode

我在C#中使用此代码来解码(不检测)QRCode并且它可以工作:

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

现在我想在一个更复杂的图像中检测一个QRCode,其中有很多其他的东西,比如图像和文本。 我无法理解如何实现这一点,因为我找不到任何样本并将Bitmap(C#)转换为Bitmatrix for Detector(zxing)并不是那么直接。

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

非常感谢


UPDATE


我尝试这个代码,但我得到一个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(post顶部的代码片段),它运行良好! 所以问题肯定在检测/解码阶段。

QR码始终在左上角,右上角,左下角有三个正方形。 知道了这一点,您应该能够在要解析的图像的像素数据中搜索该方形图案,通过一些简单的逻辑解析来计算出qr代码的左上角,宽度和高度。

虽然它已经老了。 我仍然想发布它以防有人需要它。 图像的噪声使zxing很难检测到qrcodes。 如果图像没有噪声,结果会好得多。 我使用一种简单的方法来减少扫描图像的噪音。 可以通过缩小图像来完成。 收缩因子可能因图像噪声而异。 我发现因子3在我的情况下工作得很好。

  private string Qrreader(Bitmap x) { BarcodeReader reader = new BarcodeReader { AutoRotate = true, TryHarder = true }; Result result = reader.Decode(x); string decoded = result.ToString().Trim(); return decoded; } 

适合我! TryHarder让它在整个图片中进行搜索