【问题标题】:Detecting QR code using zxing使用 zxing 检测二维码
【发布时间】:2012-08-07 04:37:20
【问题描述】:

我正在检测二维码。我的要求是当用户向相机展示他/她的二维码时,程序必须检测并在二维码周围绘制一个框。我正在使用 zxing 库 + C#。我搜索了很多东西,但我无法在其中找到任何样本。请任何人帮助我。

【问题讨论】:

  • 如果我没看错,您首先要检测 二维码在视图中,然后(由某些用户操作触发?)阅读 what i> 在里面吗?
  • 是的 GertArnold 这就是我想要的。
  • @user1081305:zxing 必须能够检测二维码的存在,因为它在内部就是这样做的。我从来没有这样做过。如果有任何可以使用的公共方法,请查看源代码。
  • 我看到 Zxing 里面有一个单独的类,叫做检测器。但他们将位矩阵作为检测器的输入,我无法在 c# 中将位图图像转换为位矩阵。(我认为它在 java 中可用,我不确定)。如果你知道如何请让我知道。

标签: c# zxing


【解决方案1】:

您可以为此使用检测器类。检测器构造函数将 BitMatrix 对象作为其唯一参数,该参数可以从 BinaryBitmap 对象的 BlackMatrix 属性中获取...

public string Detect(Bitmap bitmap)
    {
        try
        {
            com.google.zxing.LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            var binarizer = new HybridBinarizer(source);
            var binBitmap = new BinaryBitmap(binarizer);
            BitMatrix bm = binBitmap.BlackMatrix;
            Detector detector = new Detector(bm);
            DetectorResult result = detector.detect();

            string retStr = "Found at points ";
            foreach (ResultPoint point in result.Points)
            {
                retStr += point.ToString() + ", ";
            }

            return retStr;
        }
        catch
        {
            return "Failed to detect QR code.";
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    相关资源
    最近更新 更多