2016-08-04 21 views
0

我試圖讀取由usb相機獲取的圖像中的QR碼。 在其他文章中,我讀過最好的開源庫ZXing。C#使用ZXING.NET解碼實際圖像的QRCodeE

如果qrcode來自數字生成的圖像,該庫運行良好,但是如果qrcode來自真實情況,其中圖像由相機獲取,則解析庫存在一些困難。

獲取的圖像受到一些眩光或代碼變形或對比度緩慢的干擾。

你知道一些參數來設置更好的讀者嗎? 或者一些過濾器在闡述之前添加到圖像中?

例如:

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); 

謝謝

回答

0

經過多次測試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; 
}` 

高斯濾波器我用這個代碼http://www.cnblogs.com/Dah/archive/2007/03/30/694527.html

希望這可以幫助別人。