C# 基于Zxing.net的条码识别

C# 基于Zxing.net的条码识别,c#,.net,barcode,zxing,C#,.net,Barcode,Zxing,我正在编写一个windows服务,它从单页tiff中读取条形码(只有code39类型),并在解码条形码后执行某些操作 问题在于条形码识别:其工作时间不到50%。 我用一批一致的tiff对其进行了测试,并将结果与使用原始ZXing(Java)的结果进行了比较 我的代码使用这里提供的示例,但我相信条形码识别可以改进,遗憾的是,我没有找到更多的代码示例 这是我的代码: List<Document> risma = new List<Document>(); // create

我正在编写一个windows服务,它从单页tiff中读取条形码(只有code39类型),并在解码条形码后执行某些操作

问题在于条形码识别:其工作时间不到50%。 我用一批一致的tiff对其进行了测试,并将结果与使用原始ZXing(Java)的结果进行了比较

我的代码使用这里提供的示例,但我相信条形码识别可以改进,遗憾的是,我没有找到更多的代码示例

这是我的代码:

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();
List risma=new List();
//创建条形码阅读器实例
IBarcodeReader=新条形码阅读器();
字符串currentBarcode=“”;
foreach(输入扫描中的文件信息扫描页面)
{
//加载位图
var barcodeBitmap=(Bitmap)Bitmap.FromFile(scannedPage.FullName);
//检测并解码位图中的条形码
var result=reader.Decode(条形码位图);
//新文档的第一页
if(result!=null&&result.Text!=Settings.Default.AttachmentBarcode)
{
currentBarcode=result.Text;
添加(新文档(新页面(当前条形码,扫描页面));
}
其他的
{
//检查第一个识别条形码之前的页面
如果(currentBarcode==“”)继续;
//将剩余页面添加到当前文档
else risma.Last().AddPage(新页面(currentBarcode,scannedPage));
}
}
//将文档保存到文件
foreach(risma中的Document)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
                    }
                };
//配置并创建条形码读取器实例
List codeFormats=新列表();
codeformat.Add(BarcodeFormat.CODE_39);
IBarcodeReader=新条形码阅读器()
{
自动旋转=真,
TryInverted=true,
选择权=
{
可能格式=代码格式,
TryHarder=true,
ReturnCodabarStartEnd=true,
PureBarcode=false
}
};

现在的认知度真的更好了。不知道Zxing.net中是否还有其他可能性,不管怎样都很好

您应该设置选项“reader.Options.TryHarder=true;”。无论如何,您是否可以向我发送一些测试文件,以便我可以直接将.net版本与java进行比较?你可以通过电子邮件或项目主页与我联系(旧的谢谢你,Michael。我找到了选项,并将其设置为什么,如果我错了,请纠正我,是识别的最大可能。我编辑了问题,插入了更改,但没有示例图像,我无法在这里进一步帮助。Hey@refex只想问你,你的解决方案很好,因为对我来说,它至少在总工程师?