【问题标题】:sample code to detect QRCode in an image用于检测图像中的 QRCode 的示例代码
【发布时间】:2011-12-01 10:13:05
【问题描述】:

我在 C# 中使用此代码来解码(不检测)二维码,它可以工作:

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

现在我想在更复杂的图像中检测二维码,其中包含许多其他内容,例如图像和文本。我无法理解如何做到这一点,因为我找不到任何样本并且将 Bitmap (C#) 转换为 Bitmatrix for Detector (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 的问题...因为只有 10 张图片的 1 张代码已被解码!在其他情况下,会引发 com.google.zxing.ReaderException!

标签: c# qr-code zxing


【解决方案1】:

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

【讨论】:

  • 我查看了“multiReader.decodeMultiple”的代码,它按照你说的做......我想如果有一个完整的(我想)功能,我不必重新发明轮子库:)
【解决方案2】:

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

【讨论】:

    【解决方案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 让它在整个图片中搜索

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多