在生产环境中测试,无水印。
随时随地满足您的需求。
获得30天的全功能产品。
几分钟内就能启动并运行。
在您的产品试用期间,全面访问我们的支持工程团队。
发票数据处理是指接收、管理和验证来自供应商或承包商的发票,确保付款正确且按时完成。此过程包括一些步骤,旨在确保处理业务交易的准确性、合规性和效率,以避免纸质发票。 自动化发票处理可以显著减少手动数据输入错误并提高效率。 IronOCR 是一个强大的光学字符识别 (OCR) 软件库,可以用于从数字文件的发票中提取数据或文本,使其成为在 C# 应用程序中自动化发票 OCR 处理的优秀工具。
创建一个 Visual Studio 项目。
安装IronOCR C#库。
示例输入发票图像。
使用 Tesseract 从收据图像中提取数据。
光学字符识别是一种技术,可以识别和转换不同类型的文档、PDF或文本图像,将其转换为可编辑和可搜索的数据。 OCR技术处理文本图像并提取字符,使其可被机器读取。 高级光学字符识别(OCR)发票软件系统有助于财务管理工具和发票自动化。
优点:OCR通过自动化数据输入、减少错误并使数据搜索和检索更容易来提高生产力。 它还支持文档存档,帮助企业管理无纸化工作流程。
OCR技术已经显著发展,使其在处理文件和发票数据提取方面极其精确且有用,可支持多种不同的发票格式,以减少手动数据输入、消除手动发票处理并增强数据安全性。
IronOCR 是一个强大的适用于 .NET (C#) 的光学字符识别 (OCR) 库,允许开发人员从图像、PDF 和其他文档格式中提取文本,开发 OCR 发票软件,并实现应付账款工作流程。 它提供了一个易于使用的API,用于将OCR功能集成到应付账款系统或会计系统中。
在开始之前,请确保您具备以下条件:
打开 Visual Studio,点击创建新项目。
在选项中选择控制台应用程序。
提供项目名称和路径。
选择 .NET 版本类型。
在 Visual Studio 中的项目中,转到工具 > NuGet 包管理器 > 为解决方案管理 NuGet 包。 点击“浏览”选项卡并搜索IronOCR。 选择IronOCR并点击安装。
另一种选项是使用控制台和以下命令。
dotnet add package IronOcr --version 2024.12.2
dotnet add package IronOcr --version 2024.12.2
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'dotnet add package IronOcr --version 2024.12.2
带有发票编号的数字发票示例图像。
现在使用以下代码从发票中提取数据以进行OCR发票处理。
using IronOcr;
License.LicenseKey = "Your License";
string filePath = "sample1.jpg"; // image for invoice OCR
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(filePath);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
// next steps are to process data and use the extracted and validated data with invoice date
}
using IronOcr;
License.LicenseKey = "Your License";
string filePath = "sample1.jpg"; // image for invoice OCR
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
ocrInput.LoadImage(filePath);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
// next steps are to process data and use the extracted and validated data with invoice date
}
Imports IronOcr
License.LicenseKey = "Your License"
Dim filePath As String = "sample1.jpg" ' image for invoice OCR
' Create an instance of IronTesseract
Dim ocr = New IronTesseract()
' Load the image or PDF file
Using ocrInput As New OcrInput()
ocrInput.LoadImage(filePath)
' Optionally apply filters if needed
ocrInput.Deskew()
' ocrInput.DeNoise();
' Read the text from the image or PDF
Dim ocrResult = ocr.Read(ocrInput)
' Output the extracted text
Console.WriteLine("Extracted Text:")
Console.WriteLine(ocrResult.Text)
' next steps are to process data and use the extracted and validated data with invoice date
End Using
提供的代码演示了如何在C#中使用IronOCR库通过OCR(光学字符识别)从图像(例如发票)中提取文本。 以下是代码每个部分的解释,但不包含具体代码:
许可证密钥设置:
代码开始于为IronOCR设置许可证密钥。 此密钥是使用该库全部功能所必需的。 如果您有有效的许可证,请将“Your License”替换为您的实际许可证密钥。
指定输入文件:
filePath 变量保存包含发票的图像的位置(在本例中为“sample1.jpg”)。 这是将用于文本提取的文件。
创建一个OCR实例:
创建一个IronTesseract实例。 IronTesseract 是负责对输入数据(图像或PDF)执行OCR操作的类。
加载图像:
然后,代码创建一个 OcrInput 对象,用于加载图像(在本例中,是由 filePath 指定的 JPG 文件)。 LoadImage 方法用于读取图像文件并为 OCR 做准备。
应用图像滤镜:
代码包含一个过滤步骤,其中可以应用可选的图像处理方法,如Deskew(校正倾斜图像)和DeNoise(去除图像噪声),以提高OCR的准确性。 在这种情况下,只有Deskew方法是激活的。
执行 OCR:
显示提取的文本:
为了提高效率,只能使用图像的一部分进行提取。
using IronOcr;
using IronSoftware.Drawing;
License.LicenseKey = "Your Key";
string filePath = "sample1.jpg";
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
var ContentArea = new Rectangle(x: 0, y: 0, width: 1000, height: 250);
ocrInput.LoadImage(filePath, ContentArea);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
}
using IronOcr;
using IronSoftware.Drawing;
License.LicenseKey = "Your Key";
string filePath = "sample1.jpg";
// Create an instance of IronTesseract
var ocr = new IronTesseract();
// Load the image or PDF file
using (var ocrInput = new OcrInput())
{
var ContentArea = new Rectangle(x: 0, y: 0, width: 1000, height: 250);
ocrInput.LoadImage(filePath, ContentArea);
// Optionally apply filters if needed
ocrInput.Deskew();
// ocrInput.DeNoise();
// Read the text from the image or PDF
var ocrResult = ocr.Read(ocrInput);
// Output the extracted text
Console.WriteLine("Extracted Text:");
Console.WriteLine(ocrResult.Text);
}
Imports IronOcr
Imports IronSoftware.Drawing
License.LicenseKey = "Your Key"
Dim filePath As String = "sample1.jpg"
' Create an instance of IronTesseract
Dim ocr = New IronTesseract()
' Load the image or PDF file
Using ocrInput As New OcrInput()
Dim ContentArea = New Rectangle(x:= 0, y:= 0, width:= 1000, height:= 250)
ocrInput.LoadImage(filePath, ContentArea)
' Optionally apply filters if needed
ocrInput.Deskew()
' ocrInput.DeNoise();
' Read the text from the image or PDF
Dim ocrResult = ocr.Read(ocrInput)
' Output the extracted text
Console.WriteLine("Extracted Text:")
Console.WriteLine(ocrResult.Text)
End Using
此代码使用IronOCR从图像的特定区域提取文本,并可选择应用诸如倾斜校正之类的过滤器以提高准确性。 提取的文本随后被显示,准备进一步使用。
代码的第一部分涉及为IronOCR设置许可证密钥。 这需要在库中使用OCR功能。 您应该将许可证密钥替换为您从IronOCR获得的实际密钥,以便访问库的全部功能。
您希望处理的图像的文件路径已指定。 此图像(在此情况下为 JPG 文件)包含 OCR 将从中提取文本的文档或内容。 路径可以指向本地系统或其他可访问存储上的图像文件。
创建了一个IronTesseract类的实例。 此对象是核心引擎,将在图像上执行光学字符识别。
在图像中定义了一个矩形(感兴趣区域)。 此矩形用于指定OCR引擎将聚焦的图像部分。 在此示例中,矩形从左上角开始(x=0,y=0),宽度为1000像素,高度为250像素。 此步骤帮助OCR仅处理图像的相关部分,提高准确性和速度。
图像被加载到OCR引擎,但只有定义的矩形(内容区域)被处理。 这使您能够将OCR的范围缩小到图像的特定部分,当图像包含不相关的区域(例如背景或徽标)且您不想处理这些区域时,这尤其有用。
该代码可以选择性地对图像应用纠偏过滤器。 倾斜校正是指在图像存在任何倾斜或旋转时对其进行矫正的过程,以提高OCR的准确性。 另一个过滤器,denoise,可用但被注释掉了。 如果启用,它将从图像中去除噪声(不需要的标记),这可能进一步提高OCR的准确性。
OCR 引擎读取图像(或其指定区域)并提取其识别的任何文本。 结果存储在一个包含识别文本的对象中。
最后,提取的文本将打印到控制台。 此文本是 OCR 过程的结果,可以进一步处理、验证,或用于诸如数据输入或文档管理的应用程序中。
IronOCR需要密钥才能从发票中提取数据,请从许可页面获取您的开发人员试用密钥。
using IronOcr;
License.LicenseKey = "Your Key";
using IronOcr;
License.LicenseKey = "Your Key";
Imports IronOcr
License.LicenseKey = "Your Key"
本文提供了使用IronOCR进行发票处理的基本示例。 您可以进一步自定义和扩展此代码以满足您的具体需求。
IronOCR 提供了一种高效且易于集成的解决方案,用于从图像和 PDF 中提取文本,非常适合发票处理。 通过将IronOCR与C#字符串操作或正则表达式结合使用,您可以快速处理并提取发票中的重要数据。
这是一个发票处理的基本示例,通过更高级的配置(如语言识别、多页面PDF处理等),您可以微调OCR结果以提高对特定用例的准确性。
IronOCR 的 API 非常灵活,可以用于除了发票处理之外的多种 OCR 任务,包括收据扫描、文件转换和数据录入自动化。