在线文档管理:条形码识别技术

随着条形码在文档管理流程中的重要性日益增加,其准确性和易用性使得它成为日常文档管理中不可或缺的一部分。条形码不仅可以用来识别文档,还可以用于批量扫描分离,甚至作为文档的可靠元数据标识符。本文将向展示如何在网络应用程序中,通过ImageCapture Suite的帮助,从捕获或扫描的图像中解码条形码。

Dynamsoft的ImageCapture Suite是一个为网络应用程序设计的在线图像获取和处理工具包。它允许从扫描仪、网络摄像头以及其他TWAIN/UVC/WIA兼容设备中捕获图像,并且支持所有主流浏览器——包括Internet Explorer(32位/64位)、Firefox、Chrome和Safari——在Windows和Mac上运行。此外,该工具包还附带了Barcode Reader SDK,使能够在线解码1D和2D条形码符号。

如果对SDK感兴趣,可以访问Dynamsoft网站下载30天免费试用版。

编码指南

特别提示:作为在客户端浏览器中运行的组件,JavaScript是调用ImageCapture Suite所有方法/属性/事件的首选语言。

ImageCapture Suite允许加载现有图像或从扫描仪、网络摄像头等捕获图像。以下是使用C#语言加载图像的示例代码:

function btnLoad_onclick() { DWObject.IfShowFileDialog = true; DWObject.LoadImageEx("", 5); }

以下是从服务器下载现有图像的示例代码:

if (location.hostname != "") { DWObject.HTTPPort = location.port == "" ? 80 : location.port; DWObject.HTTPDownload(location.hostname, location.pathname.substring(0, location.pathname.lastIndexOf('/')) + ImgArr); }

以下是从扫描仪或网络摄像头捕获新图像的示例代码:

function AcquireImageInner() { if (DW_DWTSourceContainerID == "") { DWObject.SelectSource(); } else { DWObject.SelectSourceByIndex(document.getElementById(DW_DWTSourceContainerID).selectedIndex); } DWObject.CloseSource(); DWObject.OpenSource(); var iSelectedIndex = document.getElementById(DW_DWTSourceContainerID).selectedIndex; var iTwainType = DWObject.GetSourceType(iSelectedIndex); if (iTwainType == 0) { DWObject.IfShowUI = document.getElementById("ShowUI").checked; var i; for (i = 0; i < 3; i++) { if (document.getElementsByName("PixelType").item(i).checked == true) { DWObject.PixelType = i; } } DWObject.Resolution = Resolution.value; DWObject.IfFeederEnabled = document.getElementById("ADF").checked; DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked; AppendMessage("Pixel Type: " + DWObject.PixelType + "Resolution: " + DWObject.Resolution + ""); } else { DWObject.IfShowUI = document.getElementById("ShowUIForWebcam").checked; if (DW_InWindows) { DWObject.SelectMediaTypeByIndex(document.getElementById("MediaType").selectedIndex); DWObject.SelectResolutionForCamByIndex(document.getElementById("ResolutionWebcam").selectedIndex); AppendMessage("MediaType: " + DWObject.MediaType + "Resolution: " + DWObject.ResolutionForCam + ""); } } DWObject.IfDisableSourceAfterAcquire = true; DWObject.AcquireImage(); }

加载或捕获条形码图像到控件后,接下来就可以解码条形码符号了。以下是使用JavaScript解码条形码的示例代码:

function J_Barcoding() { var barcodeVerStr = DWObject.BarcodeVersion; if (!barcodeVerStr || barcodeVerStr != DW_BarcodeVersion) { if (location.hostname != "") { var strHostIP = location.hostname; DWObject.HTTPPort = location.port == "" ? 80 : location.port; var CurrentPathName = unescape(location.pathname); var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1); var strBarcodepath = CurrentPath + "Resources/barcode.zip"; DWObject.HTTPDownloadResource(strHostIP, strBarcodepath, "barcode.zip"); } } var strLength = DWObject.GetImageSize(DWObject.CurrentImageIndexInBuffer, DWObject.GetImageWidth(DWObject.CurrentImageIndexInBuffer), DWObject.GetImageHeight(DWObject.CurrentImageIndexInBuffer)); if (strLength > 300000) { DWObject.IfShowProgressBar = true; } else { DWObject.IfShowProgressBar = false; } var barcodeformat = document.getElementById("ddl_barcodeFormat").value; DWObject.ReadBarcode(DWObject.CurrentImageIndexInBuffer, barcodeformat); DWObject.IfShowProgressBar = true; var barcodeText = ""; barcodeText += "ReadBarcode : " + DWObject.ErrorString + ""; var count = DWObject.BarcodeCount; barcodeText += "BarcodeCount: " + count + ""; for (var i = 0; i < count; i++) { var text = DWObject.GetBarcodeText(i); var x = DWObject.GetBarcodeInfo(0, i); var y = DWObject.GetBarcodeInfo(1, i); var type = DWObject.GetBarcodeInfo(2, i); var len = DWObject.GetBarcodeInfo(5, i); barcodeText += ("barcode[" + (i + 1) + "]: " + text + ""); barcodeText += ("text len:" + len + ""); barcodeText += ("type:" + getBarcodeType(type) + ""); barcodeText += ("x: " + x + " y:" + y + ""); var strBarcodeString = text + "\r\n" + getBarcodeType(type); DWObject.AddText(DWObject.CurrentImageIndexInBuffer, x, y, strBarcodeString, 255, 4894463, 0, 1); } AppendMessage(barcodeText); J_SetBtnProcessingAndText("btnReadBarcode", false, "Try Barcode"); }

完整的源代码可以从文章中下载。有一个"Scripts\ProductKey.js"文件包含临时试用产品密钥。如果在运行示例时遇到许可错误,可以从Dynamsoft网站下载ImageCapture Suite以获取有效的试用许可。

沪ICP备2024098111号-1
上海秋旦网络科技中心:上海市奉贤区金大公路8218号1幢 联系电话:17898875485