使用LEADTOOLS进行非结构化发票识别和处理





0/5 (0投票)
在本白皮书中,我们将演示如何设置主表单模板,然后从中提取已填写发票的数据。
引言
毫无疑问,诸如表单识别和OCR之类的成像技术彻底改变了我们的业务方式,并从繁琐且易出错的数据输入任务中解放了无数工时。然而,这些技术仍然依赖于数据在每个文档中都位于相同位置的假设。像发票、账单和选项卡这类非结构化表单和扫描文档,在自动化系统中进行大规模处理是极其困难的,如果不是不可能的话。
在LEADTOOLS 19版本及其先进的发票识别和处理SDK技术发布后,这种情况已不复存在。即使表格的每一行和单元格高度不同,或者表格跨越多个页面,也可以处理包含表格数据的复杂、非结构化和半结构化文档。在本白皮书中,我们将演示如何设置主表单模板,然后从中提取已填写发票的数据。
设置主表单模板
第一个要求是创建一个模板,该模板定义了各个字段的位置以及期望的数据类型。这应该是用于识别的表单的空白或已编辑版本。有些字段可能具有静态位置,例如客户编号、发票编号、地址等,但发票和其他非结构化表单类型中的表格可能会严重影响识别准确性,因为主模板和已填写的发票在表格区域大小上有所不同。
LEADTOOLS通过“表格”字段类型克服了这一重大障碍。要实现表格字段,只需定义列标题,表格数据就会被识别,而无论行数、每个单元格的高度或页数如何。传统的固定位置字段也可以与表格共存(例如,发票总计),并将根据其相对于表格末尾的位置进行识别。
识别和处理已填写的发票
设置好主表单模板后,您就可以开始识别(即分类)和处理已填写的文档了。LEADTOOLS先进的表单识别算法将首先确定已填写文档匹配的是哪种类型的表单。存储库中的主表单模板数量没有限制,因此可以为企业中的所有表单和发票创建一个单一的自动化解决方案。AutoFormsEngine
可以处理所有对表单的对齐、定向、分类和处理工作,而无论其分辨率如何。最重要的是,设置AutoFormsEngine
既快速又简单,只需告诉它在哪里查找主表单模板并将已填写的发票图像传递给它即可。
// Set up the master forms repository based on a folder path
DiskMasterFormsRepository workingRepository = new DiskMasterFormsRepository(rasterCodecs,
repositoryPath);
// Use the Ocr recognition manager. Other options include Default and Barcode
AutoFormsRecognitionManager managers = AutoFormsRecognitionManager.Ocr;
// Create the forms engine
AutoFormsEngine autoEngine = new AutoFormsEngine(workingRepository, ocrEngines[0], barcodeEngine,
managers, 30, 80, _menuItemRecognizeFirstPageOnly.Checked);
autoEngine.UseThreadPool = true;
// Create the filled form we want to identify/regognize/classify against the repository
FilledForm form = new FilledForm();
form.FileName = Path.GetFileName(imagePath);
form.Name = Path.GetFileNameWithoutExtension(imagePath);
form.Image = rasterCodecs.Load(imagePath, 0, CodecsLoadByteOrder.Bgr, 1, 1);
// Run the recognition and processing on the filled form
AutoFormsRunResult result = autoEngine.Run(form.Image, MyPageRequestCallback, form, null);
if (result != null && !canceled)
{
// Get the master form (recognize/classify)
MasterForm master = new MasterForm();
master.Properties = result.RecognitionResult.Properties;
form.Master = master;
// Populate our form with the recognition and processing results and alignment information
form.Result = result.RecognitionResult.Result;
form.Alignment = result.RecognitionResult.Alignments;
//We have successfully recognized and processed a form
}
在表单成功分类后,我们可以解析结果并从模板定义的字段中提取数据。
// Create a DataGridView control for displaying the table data
DataGridView _tableResults;
_tableResults = new DataGridView();
TableFormField tableField = form.ProcessingPages[pageIndex][fieldIndex] as TableFormField;
if (tableField.Result.Status == FormFieldStatus.Success)
{
// Add the columns
foreach (TableColumn column in tableField.Columns)
_tableResults.Columns.Add(column.OcrField.Name, column.OcrField.Name);
// Add the data, looping first by the rows, then for each field (cell) within the row
TableFormFieldResult results = tableField.Result as TableFormFieldResult;
for (int i = 0; i < results.Rows.Count; i++)
{
TableFormRow row = results.Rows[i];
_tableResults.Rows.Add();
for (int j = 0; j < row.Fields.Count; j++)
{
// Get the text from the field!
OcrFormField ocrField = row.Fields[j];
TextFormFieldResult txtResults = ocrField.Result as TextFormFieldResult;
_tableResults.Rows[i].Cells[j].Value = txtResults.Text;
}
}
}
每个字段都包含大量信息,包括识别出的数据、置信度信息、字体特征、边界矩形等。正如您在图 3 中看到的,整个表格被检测为一个字段,并进一步细分为每个单元格。LEADTOOLS灵活且高度准确的处理例程能够检测并考虑单元格高度的差异,正确识别每个单元格的边界矩形,并使用光学字符识别提取数据和详细的字符信息。
想看更多?点击此处观看LEADTOOLS发票识别和处理SDK的视频演示。
结论
识别和处理来自非结构化表单(如发票和账单)的数据只是LEADTOOLS可以解决的众多实际解决方案之一。其最先进的发票识别和处理SDK可以实现自动化的会计、账单和发票解决方案。此外,LEADTOOLS还提供大量的文档清理功能,包括去歪斜、移除线条、去噪点、移除打孔等,以便在识别前过滤掉噪声。LEADTOOLS通过其全面的栅格、文档、医学和多媒体成像工具包系列,提供了无与伦比的价值。
下载完整的非结构化发票识别和处理示例
您可以下载包含上述功能的完整功能演示。要运行此示例,您需要以下条件:
- LEADTOOLS 免费 60 天试用版
- Visual Studio 2008 或更高版本
- 浏览至 LEADTOOLS 示例文件夹(例如,C:\LEADTOOLS 19\Examples\),您可以在其中找到此示例以及 LEADTOOLS 中许多其他技术的示例项目。
支持
需要帮助来运行此示例吗?联系我们的支持团队以获得免费技术支持!有关定价或许可问题,您可以联系我们的销售团队(sales@leadtools.com)或致电 704-332-5532。