LEADTOOLS教程:如何使用智能捕获LEADTOOLS从扫描文档中提取条形码数据

LEADTOOLS Barcode Pro包含了开发人员需要检测、读取和写入超过100种不同的1D和2D条形码类型和子类型,如UPC、EAN、Code 128、QR Code、Data Matrix和PDF417等等。在这篇文章中,将讨论如何智能地从扫描的文件中捕获条形码。

LEADTOOLS (Lead Technology)由Moe Daher and Rich Little创建于1990年,其总部设在北卡罗来纳州夏洛特。LEAD的建立是为了使Daher先生在数码图象与压缩技术领域的发明面向市场。在29年的发展历程中,LEAD以其在全世界主要国家中占有的市场领导地位,在数码图象开发工具领域中已成为既定的全球领导者。LEADTOOLS开发与发布的LEAD是屡获殊荣的开发工具包。

LEADTOOLS Barcode Pro包含了开发人员需要检测、读取和写入超过100种不同的1D和2D条形码类型和子类型,如UPC、EAN、Code 128、QR Code、Data Matrix和PDF417等等。相比于市场上其他同类型的条形码成像技术,LEADTOOLS Barcode Pro无疑是最好的。

LEADTOOLS Barcode Pro免费版

智能捕获可以指从图像或文档捕获数据的几种不同方式。在这篇文章中,将讨论如何智能地从扫描的文件中捕获条形码。LEADTOOLS TWAIN SDK和条码SDK是开发人员可以轻松地使用它来创建物理文档的扫描应用程序,同时捕捉和提取发现的任何条形码数据库。

这个应用程序将只使用三个按钮。一个用于选择将保存PDF和TXT的输出目录,一个用于选择要扫描的扫描仪,另一个用于执行扫描并识别条形码。

SelectDir_Click

// Change the output directoryusing (FolderBrowserDialog dlg = new FolderBrowserDialog()){    dlg.ShowNewFolderButton = true;    if (dlg.ShowDialog(this) == DialogResult.OK)        _outputDirectory = System.IO.Path.GetFullPath(dlg.SelectedPath);}

ScannerSelect_Click

// Select the scanner to use_twainSession.SelectSource(null);

Scan_Read_Click

// Scan the new page(s)_twainSession.Acquire(TwainUserInterfaceFlags.Show);

现在添加以下变量。

private static BarcodeEngine engine = new BarcodeEngine();private static BarcodeReader reader = engine.Reader;// The Twain sessionprivate static TwainSession _twainSession;// The output directory for saving PDF filesprivate static string _outputDirectory;// The image processing commands we are going to use to clean the scanned imageprivate static List<RasterCommand> _imageProcessingCommands;private static int _scanCount;private static StringBuilder sb;

在Form1_Load中,添加用于设置许可证的代码、初始化新的Twain会话、订阅TwainSession.Acquire事件,然后初始化任何图像处理命令。

RasterSupport.SetLicense(@"", "");_twainSession = new TwainSession();_twainSession.Startup(this.Handle, "My Company","My Product","My Version","My Application",TwainStartupFlags.None);_twainSession.AcquirePage += new EventHandler<TwainAcquirePageEventArgs>(_twainSession_AcquirePage);// Add as many as you like, here we will add Deskew and Despeckle_imageProcessingCommands = new List<RasterCommand>();_imageProcessingCommands.Add(new DeskewCommand());_imageProcessingCommands.Add(new DespeckleCommand());

在Form1_FormClosed中,结束TWAIN会话。

// End the twain session_twainSession.Shutdown();

最后添加Twain获取句柄的代码。

private void _twainSession_AcquirePage(object sender, TwainAcquirePageEventArgs e){    _scanCount++;    // We have a page    RasterImage image = e.Image;    // First, run the image processing commands on it    foreach (RasterCommand command in _imageProcessingCommands)    {        command.Run(image);    }    // Read all the barcodes in this image    BarcodeData[] barcodes = reader.ReadBarcodes(e.Image, LeadRect.Empty, 0, null);    // Print out the barcodes we found    sb = new StringBuilder();    sb.AppendLine($"Contains {barcodes.Length} barcodes");    for (int i = 0; i < barcodes.Length; i++)    {        BarcodeData barcode = barcodes[i];        sb.AppendLine($"  {i + 1} - {barcode.Symbology} - {barcode.Value}");    }    // Save string builder to a text file    System.IO.File.WriteAllText($@"{_outputDirectory}barcodes{_scanCount}.txt", sb.ToString());    // Save image as PDF    using (RasterCodecs codecs = new RasterCodecs())    {        codecs.Save(e.Image,        $@"{_outputDirectory}ScannedImage{_scanCount}.pdf",        RasterImageFormat.RasPdf, 0);    }}

想要购买LEADTOOLS产品正版授权,或了解更多产品信息请点击“咨询在线客服”

1563778777.jpg

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年7月19日
下一篇 2019年7月19日

相关推荐

发表回复

登录后才能评论