使用c#自动识别来自不同供应商的发票

发票

在无纸化办公室工作时,企业会从不同的供应商那里收到数百种不同的表格和发票。手工查找、提取和存储所有必要的信息通常是一个主要的痛点和瓶颈。谢天谢地LEADTOOLS文档SDK我们的专利形式认可技术,一切都可以很容易地自动化,以提高工作流的生产力和效率。

使用LEADTOOLS,用户只需要为每个不同的发票或表单类型创建模板,也称为主表单。然后将这些主表单存储在存储库中,并用于自动识别当前正在处理的填充表单的类型。

在下面的演示中,我们取一个已填充表单的目录,并将其与主表单列表进行比较。我们将首先加载希望识别的填充表单以及希望与之比较的主表单。

填写表格

填充的表单可以跨越多个页面,因此我们需要从填充的表单中读取图像数据,并将每个页面添加到FormRecognitionAttributes类的实例中。

私有静态FormRecognitionAttributes LoadFilledFormAttributes(string filledFormName) {FormRecognitionAttributes filledFormAttributes = recognitionEngine.CreateForm(null);RasterImage currentForm = codecs。加载(fillledformname, 0, CodecsLoadByteOrder.)BgrOrGray, 1, -1);for (int I = 0;i < currentForm.PageCount;i++) {recognitionEngine. i++。AddFormPage(填充formattributes, currentForm, null);currentForm。Page = i + 1;} recognitionEngine.CloseForm (filledFormAttributes);返回filledFormAttributes; }

载入主表格

加载主表单就像读取主表单的.bin文件并将其加载到FormRecognitionAttributes类的实例中一样简单。

私有静态FormRecognitionAttributes LoadMasterFormAttributes(string masterFormName) {FormRecognitionAttributes masterFormAttributes = new FormRecognitionAttributes();masterFormAttributes.SetData (File.ReadAllBytes (masterFormName));返回masterFormAttributes;}

找到合适的伴侣

现在,我们准备循环遍历一个充满填充表单的整个目录,并查找它们对应的主表单。

私有静态无效的RecognizeForms(){控制台。WriteLine(“认识形式\ n”);string[] formsToRecognize =目录。GetFiles(filledFormsDirectory, "*.tif", searchchoption . alldirectories);string[] masterFileNames =目录。GetFiles(masterFormsDirectory, "*.bin", SearchOption.AllDirectories);foreach (string filledFormName in formsToRecognize) {FormRecognitionAttributes filledFormAttributes = LoadFilledFormAttributes(filledFormName);string resultMessage = "";foreach (string masterFileName in masterFileName) {FormRecognitionAttributes masterFormAttributes = LoadMasterFormAttributes(masterFileName);//将主表单与填充表单FormRecognitionResult recognitionResult = recognitionEngine进行比较。CompareForm(masterFormAttributes, fillledformattributes, null);//当识别引擎比较两个文档时,它也为引擎认为两个文档匹配的程度设置一个置信度。Confidence >= AllowedConfidenceLevel)    {     resultMessage = $"Form {Path.GetFileNameWithoutExtension(filledFormName)} has been recognized as a(n) {Path.GetFileNameWithoutExtension(masterFileName)} with a confidence level of {recognitionResult.Confidence}";     break;    }    resultMessage = $"The form {Path.GetFileNameWithoutExtension(filledFormName)} failed to be recognized with a confidence level of {recognitionResult.Confidence}";   }   Console.WriteLine(resultMessage);   Console.WriteLine("=============================================================\n");  } }

请继续关注

在下一篇博客中,我们将展示如何使用本文中的主表单从填写好的表单中读取信息。

尝试我们的免费评估今天!

将我们的任何先进技术添加到您的项目通过下载我们的库的全部集合免费的LEADTOOLS评估SDK。

不知道从哪里开始?让我们的专家告诉你!安排一次演示了解更多关于我们获奖的sdk将如何帮助您的应用程序开发到下一个水平的信息。

关于价格或许可问题,请通过电子邮件或致电704-332-5532。

这个条目是在表格识别及处理.书签的永久链接

留言回复

您的电邮地址将不会公布。必填项已标记