使用ZXING.NET对真实图像中的QR码进行C#解码

使用ZXING.NET对真实图像中的QR码进行C#解码,c#,computer-vision,qr-code,zxing,decoding,C#,Computer Vision,Qr Code,Zxing,Decoding,我正在尝试读取usb摄像头采集的图像中的二维码。 在其他帖子中,我读到最好的开源库是ZXing 如果QR码来自数字生成的图像,库工作正常,但如果QR码来自真实情况,即图像由相机获取,则解编码库有一些困难 获取的图像会受到一些眩光、代码变形或低对比度的干扰 您知道一些参数,以便更好地设置阅读器吗? 或者在细化之前添加一些过滤器到图像中 例如: BarcodeReader reader = new BarcodeReader(); reader.AutoRotate = true; reader.

我正在尝试读取usb摄像头采集的图像中的二维码。 在其他帖子中,我读到最好的开源库是ZXing

如果QR码来自数字生成的图像,库工作正常,但如果QR码来自真实情况,即图像由相机获取,则解编码库有一些困难

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

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

例如:

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);
BarcodeReader=新的条形码阅读器();
reader.AutoRotate=true;
reader.Options.TryHarder=true;
reader.Options.PureBarcode=false;
reader.Options.possibleformas=新列表();
reader.Options.possibleformas.Add(条形码格式.QR\u码);
var结果=读取器。解码(图像);

谢谢

经过多次测试,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;
}
//使用高斯滤波器去除噪声
var gFilter=新的GaussianBlur(2);
image=gFilter.ProcessImage(image);
var options=newdecodingoptions{possibleformas=newlist{BarcodeFormat.QR_CODE},TryHarder=true};
使用(图像)
{
//使用GlobalHistorogrambinarizer可获得最佳结果
var reader=new条形码阅读器(null,null,ls=>new globalhistorogrambinarizer(ls)){AutoRotate=false,TryInverted=false,Options=Options};
var结果=读取器。解码(图像);
reader=null;
返回结果;
}
对于高斯滤波器,我使用来自

希望这能帮助别人