我在 C# 中使用此代码解码(不检测)QRCode,它有效:
LuminanceSource ls = new RGBLuminanceSource(image, image.Width, image.Height);
Result result = new QRCodeReader().decode(new BinaryBitmap(new HybridBinarizer(ls)));
现在我想在包含许多其他内容(例如图像和文本)的更复杂的图像中检测 QRCode。我无法理解如何完成此操作,因为我找不到任何示例,并且将位图 (C#) 转换为检测器 (zxing) 的位矩阵并不是那么直接。
谁有一段代码可以给我?
非常感谢
更新
我尝试了这段代码,但我得到了一个 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
2011 年 2 月 12 日更新
我刚刚尝试用我的 iPhone 上的应用程序扫描打印的 QRCode(代码段位于帖子顶部)并且效果很好!所以问题肯定在检测/解码阶段。
最佳答案
二维码总是在左上角、右上角、左下角三个方 block 。知道了这一点,你应该能够在你正在解析的图像的像素数据中搜索那个方形图案,通过一些简单的逻辑解析来找出二维码的左上角、宽度和高度。
关于c# - 检测图像中 QRCode 的示例代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8339612/