使用Zxing .net进行条形码识别

时间:2017-05-07 20:37:48

标签: c# .net barcode zxing

我正在编写一个从单页tiff读取条形码(只有code39类型)的Windows服务,并在解码条形码后做了一些事情。

问题在于条形码识别:它的工作时间不到50%。 我用一批有意义的tiff对它进行了测试,并将结果与​​使用原始ZXing(Java)的https://zxing.org/w/decode.jspx进行了比较。

我的代码使用此处提供的示例https://zxingnet.codeplex.com/,但我相信可以改进条形码识别,遗憾的是我没有找到更多代码示例......

这是我的代码:

List<Document> risma = new List<Document>();

// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
string currentBarcode = "";

foreach (FileInfo scannedPage in inputScans)
                {
                    // load a bitmap
                    var barcodeBitmap = (Bitmap)Bitmap.FromFile(scannedPage.FullName);
                    // detect and decode the barcode inside the bitmap
                    var result = reader.Decode(barcodeBitmap);
                    // first page of a new document
                    if (result != null && result.Text != Settings.Default.AttachmentBarcode)
                    {
                        currentBarcode = result.Text;
                        risma.Add(new Document(new Page(currentBarcode, scannedPage)));
                    }
                    else
                    {
                        // checks for pages before the first recognized barcode
                        if (currentBarcode == "") continue;
                        // add remaining pages to current document
                        else risma.Last().AddPage(new Page(currentBarcode, scannedPage));
                    }
                }

// save documents to file
foreach (Document doc in risma) doc.MakeTiff();

我的问题是:有没有更好的方法用Zxing.net解码code39条码?

我在创建BarcodeReader对象后添加了以下内容。

// configure and create a barcode reader instance
                List<BarcodeFormat> codeFormats = new List<BarcodeFormat>();
                codeFormats.Add(BarcodeFormat.CODE_39);
                IBarcodeReader reader = new BarcodeReader()
                {
                    AutoRotate = true,
                    TryInverted = true,
                    Options =
                    {
                        PossibleFormats = codeFormats,
                        TryHarder = true,
                        ReturnCodabarStartEnd = true,
                        PureBarcode = false
                    }
                };

现在认识真的好多了。不知道Zxing .net中是否还有其他可能性,无论如何都会很好看

0 个答案:

没有答案