C# 使用 ZXING.NET 解码真实图像中的 QRCODE

use*_*507 2 c# qr-code decoding computer-vision zxing

我正在尝试读取 USB 相机获取的图像中的二维码。在其他帖子中,我读到最好的开源库是 ZXing。

如果二维码来自数字生成的图像,则库工作正常,但如果二维码来自图像由相机获取的真实情况,则解码库会遇到一些困难。

所获取的图像会受到一些眩光、代码变形或对比度缓慢的干扰。

您知道一些参数可以更好地设置阅读器吗?或者在详细说明之前添加一些过滤器到图像中?

例如:

BarcodeReader reader = new BarcodeReader();

reader.AutoRotate = true;
reader.Options.TryHarder = true;
reader.Options.PureBarcode = false;
reader.Options.PossibleFormats = new List<BarcodeFormat>();
reader.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE);

var result = reader.Decode(image);
Run Code Online (Sandbox Code Playgroud)

谢谢

JD1*_*D11 5

经过多次测试,300dpi 扫描图像的最佳结果为:

//use gaussian filter to remove noise
var gFilter = new GaussianBlur(2);
image = gFilter.ProcessImage(image);
                   
var options = new DecodingOptions { PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.QR_CODE }, TryHarder = true };
    
using (image)
{
    //use GlobalHistogramBinarizer for best result
    var reader = new BarcodeReader(null, null, ls => new GlobalHistogramBinarizer(ls)) { AutoRotate = false, TryInverted = false, Options = options };
    var result = reader.Decode(image);
    reader = null;
                    
   return result;
}
Run Code Online (Sandbox Code Playgroud)

对于高斯滤波器,我使用http://www.cnblogs.com/Dah/archive/2007/03/30/694527.html中的代码

希望这对某人有帮助。