发票 OCR 机器学习(逐步教程)
在当今快节奏的商业环境中,任务和非结构化数据的自动化已成为提高效率和减少人为错误的关键策略。 其中一项任务是从发票或采购订单中提取信息,这一过程传统上需要大量的人工投入。 然而,得益于机器学习、深度学习模型和光学字符识别 (OCR) 软件技术的进步,企业现在可以使用 IronOCR 等工具简化发票信息提取流程。 在本文中,我们将探讨如何利用机器学习和 IronOCR 来彻底改变发票处理方式。
了解发票 OCR 工具
OCR 技术已经存在一段时间了,但随着机器学习的出现,其在发票处理和数据提取方面的应用得到了显著提升。 OCR(光学字符识别)是一种将不同类型的文档(例如包含发票信息的扫描纸质文档、PDF 文件、财务文档或数码相机拍摄的输入图像)转换为可编辑和可搜索数据的技术。 它本质上是利用图像预处理技术将图像中的文本转换为机器可读文本。
IronOCR是一个功能强大的 OCR 库,它基于机器学习算法构建,可以集成到各种应用程序和编程语言中,使其成为发票处理的多功能工具。 通过使用 IronOCR,企业可以自动化发票数据提取,例如发票号码、日期、供应商详细信息和行项目,具有显著的准确性。
使用 IronOCR 进行发票 OCR 的优势
使用IronOCR 进行发票处理具有诸多优势,可以显著提高贵公司财务运营(例如应付账款)的效率和准确性。 让我们更详细地探讨一下这些好处:
1. 准确性和减少误差
IronOCR 利用先进的机器学习算法,准确地识别和提取发票中的文本。 这样可以最大限度地减少数据录入过程中人为错误的发生概率,确保关键财务信息得到正确记录。
2. 节省时间和成本
使用 IronOCR 实现发票处理自动化,可以显著减少手动数据录入所需的时间和资源。 通过优化员工时间并减少对体力劳动的需求,这可以大幅节省成本。
3. 效率提升
IronOCR能够快速高效地处理大量发票。 这样就省去了员工手动输入每张发票数据的麻烦,使他们能够专注于更具战略意义的任务。
4. 可扩展性
IronOCR 具有可扩展性,能够随着您的业务扩展而处理不断增长的发票数量。 您无需担心工作量增加和边界框过多导致发票文档处理系统不堪重负。
5. 全球影响力
IronOCR 支持 125 多种语言,使企业能够处理来自世界各地供应商和客户的发票。 无论发票是用何种语言书写的,IronOCR 都能准确提取数据。
6. 多格式支持
IronOCR 可以处理各种格式的发票,包括扫描图像、基于图像的 PDF 和基于文本的 PDF。 这种多功能性确保您可以轻松处理来自不同来源和格式的发票。
7. 定制和数据提取
您可以自定义 IronOCR,从发票中提取特定数据字段,例如发票编号、日期、供应商详细信息和行项目信息。 这种程度的定制化使您可以根据您的具体业务需求来定制解决方案。
8. 合规性和审计追踪
使用 IronOCR 进行自动发票处理有助于保持准确的记录并提供审计跟踪。 这对于遵守财务法规和简化审计流程至关重要。
9. 缩短发票处理周期
IronOCR 的精简和自动化特性减少了处理发票所需的时间,从而缩短了发票处理周期。 这可以加快向供应商付款的速度,并改善双方关系。
10. 增强型数据分析
通过将发票数据以结构化的数字格式存储,您可以进行更深入的数据分析。 这有助于识别趋势、优化支出并做出明智的财务决策。
实施 IronOCR 进行发票处理
要实施 IronOCR 进行发票处理,请按照以下一般步骤操作:
步骤 1:创建一个新的 C
首先,在您首选的开发环境(例如 Visual Studio 或 Visual Studio Code)中创建一个新的 C# 项目或打开一个现有项目。 本次演示我使用的是 Visual Studio 2022 IDE 和控制台应用程序。 您可以在任何项目类型中使用相同的实现,例如 ASP.NET Web API、ASP.NET MVC、ASP.NET Web Forms 或任何 .NET Framework。
步骤 2:通过 NuGet 包管理器安装 IronOCR
要在您的项目中使用 IronOCR,您需要安装 IronOCR NuGet 包。 以下是操作方法:
1.打开 NuGet 软件包管理器控制台。 在 Visual Studio 中,您可以在"工具">"NuGet 包管理器">"包管理器控制台"下找到它。
发票 OCR 机器学习(分步教程):图 2 - 软件包管理器控制台
运行以下命令安装 IronOCR 软件包:
Install-Package IronOcr
- 等待包安装完成。 完成后,您就可以在项目中使用 IronOCR 了。
步骤 3:在 C# 中实现 OCR
现在,让我们编写 C# 代码,使用 IronOCR 对发票执行 OCR 操作。 我们将使用以下发票样本作为示例。
以下示例代码将以发票图像作为输入,并从发票中提取数据,例如发票号码、采购订单等。
// Define the path to the invoice image
string invoicePath = @"D:\Invoices\SampleInvoice.png";
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Add the invoice image to the OCR input
input.AddImage(invoicePath);
// Perform OCR on the input image and store result
OcrResult result = ocr.Read(input);
// Output the extracted text from the image to the console
Console.WriteLine(result.Text);
}// Define the path to the invoice image
string invoicePath = @"D:\Invoices\SampleInvoice.png";
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Add the invoice image to the OCR input
input.AddImage(invoicePath);
// Perform OCR on the input image and store result
OcrResult result = ocr.Read(input);
// Output the extracted text from the image to the console
Console.WriteLine(result.Text);
}' Define the path to the invoice image
Dim invoicePath As String = "D:\Invoices\SampleInvoice.png"
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Add the invoice image to the OCR input
input.AddImage(invoicePath)
' Perform OCR on the input image and store result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from the image to the console
Console.WriteLine(result.Text)
End Using上面的代码是一个简洁的 C# 示例,它使用 IronOCR 对单个发票图像 (SampleInvoice.png) 执行 OCR,然后将提取的发票数据打印到控制台。 请务必将invoicePath变量替换为您的特定发票图像文件的路径。
让我们一次性导入多张发票,并提取其中的数据。 以下是我们用作输入的发票目录。
以下示例代码将一次性从多张发票中提取文本。
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all images to the console
Console.WriteLine(result.Text);
}// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all images to the console
Console.WriteLine(result.Text);
}' Get all PNG files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.png")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddImage(file)
Next file
' Perform OCR on all the added images and store the result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from all images to the console
Console.WriteLine(result.Text)
End Using上面的代码将从文件夹中获取所有 PNG 图像,提取数据,然后将文件夹中所有发票的提取数据打印到控制台。
将提取的数据保存为可搜索的 PDF 发票
以下代码将读取文件夹中的所有图像,执行数据提取,并将它们保存为单个可搜索的 PDF 发票。
// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Save the result as a searchable PDF
result.SaveAsSearchablePdf(@"D:\Invoices\Searchable.pdf");
}// Get all PNG files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.png");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddImage(file);
}
// Perform OCR on all the added images and store the result
OcrResult result = ocr.Read(input);
// Save the result as a searchable PDF
result.SaveAsSearchablePdf(@"D:\Invoices\Searchable.pdf");
}' Get all PNG files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.png")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddImage(file)
Next file
' Perform OCR on all the added images and store the result
Dim result As OcrResult = ocr.Read(input)
' Save the result as a searchable PDF
result.SaveAsSearchablePdf("D:\Invoices\Searchable.pdf")
End Using所有示例中的代码几乎都相同; 我们只是做了一些细微的改动,以演示不同的使用场景。 输出的PDF文件如下所示:
通过这种方式,IronPDF 提供了一种最简单的自动化发票处理和文档处理的方法。
从PDF发票中提取发票数据
要使用 IronOCR 从 PDF 发票中提取数据,您可以按照与前面代码示例类似的方法进行操作。 IronOCR能够处理基于图像和基于文本的PDF文件。 以下是一个从PDF发票中提取数据的简要示例:
// Get all PDF files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.pdf");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddPdf(file);
}
// Perform OCR on all the added PDFs and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text);
}// Get all PDF files from the specified directory
string[] fileArray = Directory.GetFiles(@"D:\Invoices\", "*.pdf");
// Create an instance of IronTesseract for OCR processing
IronTesseract ocr = new IronTesseract();
// Use 'using' to ensure proper disposal of OcrInput resources
using (OcrInput input = new OcrInput())
{
// Loop through each file and add it to the OCR input
foreach (string file in fileArray)
{
input.AddPdf(file);
}
// Perform OCR on all the added PDFs and store the result
OcrResult result = ocr.Read(input);
// Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text);
}' Get all PDF files from the specified directory
Dim fileArray() As String = Directory.GetFiles("D:\Invoices\", "*.pdf")
' Create an instance of IronTesseract for OCR processing
Dim ocr As New IronTesseract()
' Use 'using' to ensure proper disposal of OcrInput resources
Using input As New OcrInput()
' Loop through each file and add it to the OCR input
For Each file As String In fileArray
input.AddPdf(file)
Next file
' Perform OCR on all the added PDFs and store the result
Dim result As OcrResult = ocr.Read(input)
' Output the extracted text from all PDFs to the console
Console.WriteLine(result.Text)
End Using上述代码使用 IronOCR 高效地批量处理位于目录 (@"D:\Invoices\") 中的多个 PDF 发票。 它检索文件路径,将每个 PDF 添加为 OCR 处理,合并提取的文本,并将结果打印到控制台。 这种方法简化了处理大量发票的组织的发票数据提取流程,提高了效率并减少了人工工作量。
结论
总而言之,机器学习与先进的 OCR 技术(如 IronOCR)的融合正在重塑发票的处理方式。 本文将带您了解 IronOCR 的使用过程,并展示了其显著优势。 通过采用 IronOCR,企业可以提高准确率,节省时间和金钱,并轻松处理各种格式和语言的发票。 取消人工数据录入不仅可以提高效率,还可以降低财务交易中出现代价高昂的错误的可能性。 IronOCR 简化并改进了发票处理工作流程,对于希望在当今竞争激烈的环境中提升财务运营能力的企业来说,这是一个明智的选择。 此外,IronOCR 还提供了一系列强大的功能,包括支持 125 多种语言、可自定义的数据提取以及与基于图像和基于文本的 PDF 的兼容性。
IronOCR 的功能集令人印象深刻,但同样值得注意的是, IronOCR 的定价模式旨在满足各种业务需求,为小型企业和大型公司提供免费试用,并提供灵活的选择。 无论您是处理少量发票还是管理大量财务文件,IronOCR 都是一个可靠且经济高效的解决方案。








