在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
发票数据处理是指接收、管理和验证来自供应商或承包商的发票,确保付款正确且按时完成。此过程包括一些步骤,旨在确保处理业务交易的准确性、合规性和效率,以避免纸质发票。 自动化发票处理可以显著减少手动数据输入错误并提高效率。 IronOCR是一款功能强大的光学字符识别(光学字符识别)软件库,可用于从数字文件中的发票中提取数据或文本,使其成为在C#应用程序中自动化发票OCR处理的出色工具。
创建一个 Visual Studio 项目。
安装IronOCR C#库。
示例输入发票图像。
使用 Tesseract 从收据图像中提取数据。
光学字符识别是一种技术,可以识别和转换不同类型的文档、PDF或文字图像为可编辑和可搜索的数据。 OCR技术处理文本图像并提取字符,使其可被机器读取。 高级光学字符识别(OCR)发票软件系统有助于财务管理工具和发票自动化。
优势:OCR通过自动化数据输入、减少错误,并实现更轻松的数据搜索和检索,提高了生产力。 它还支持文档存档,帮助企业管理无纸化工作流程。
OCR技术已经显著发展,使其在处理文件和发票数据提取方面极其精确且有用,可支持多种不同的发票格式,以减少手动数据输入、消除手动发票处理并增强数据安全性。
IronOCR 是一种强大的光学字符识别(光学字符识别)用于.NET的库(C#)允许开发人员从图像、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(光学字符识别). 以下是代码每个部分的解释,但不包含具体代码:
License Key Setup: 许可证密钥设置
代码开始于为IronOCR设置许可证密钥。 此密钥是使用该库全部功能所必需的。 如果您有有效的许可证,请将“Your License”替换为您的实际许可证密钥。
指定输入文件:
filePath 变量保存包含发票的图像的位置。(在这种情况下,“sample1.jpg”). 这是将用于文本提取的文件。
创建 OCR 实例:
创建一个IronTesseract实例。 IronTesseract 是负责对输入数据执行 OCR 操作的类。(图像或PDF).
加载图像:
然后代码创建一个 OcrInput 对象,用于加载图像。(在这种情况下,由 filePath 指定的 JPG 文件。). LoadImage 方法用于读取图像文件并为 OCR 做准备。
应用图像滤镜:
代码包含一个过滤步骤,其中包括可选的图像处理方法,如Deskew。(纠正倾斜图像)和去噪(去除图像噪声),可以用于提高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 任务,包括收据扫描、文件转换和数据录入自动化。