发票 OCR API(开发者教程)
发票OCR API利用机器学习和计算机视觉将发票数据转换为适合自动处理的格式。 这项技术解决了手动数据输入问题,如延迟、成本和错误,准确提取供应商信息、发票号和价格等细节,无论是数字还是扫描发票。
这篇文章将使用名为IronOCR的顶级发票OCR API。
如何创建发票 OCR API
- 下载并安装发票 OCR API
- 在Visual Studio中创建一个新的C#项目或打开一个现有项目。
- 使用
OcrInput方法加载现有图像文件 - 使用
Ocr.Read方法从图像中提取文本。 - 使用
Console.WriteLine将提取的文本打印到控制台。
1. IronOCR
由Iron Software开发的IronOCR是一款为开发人员提供一系列工具的OCR库。 它利用机器学习和计算机视觉从扫描的文档、图像和PDF中提取文本,实现自动化处理。 其API可以集成到各种语言和平台,减少手动数据输入错误,提高效率。 提取的数据可以被分析并集成到现有系统中,有助于决策和提高生产力。 像 图像预处理、条形码识别 和文件解析等功能提高了它的多功能性。 IronOCR赋予开发人员在其应用中集成文本识别的能力。
2. 先决条件
在开始使用 IronOCR 之前,需要具备一些先决条件。 这些前提条件包括
1.确保在计算机上设置了合适的开发环境。 这通常需要安装集成开发环境 (IDE),如 Visual Studio。 2.重要的是要对 C# 编程语言有基本的了解。 这将使您能够有效地理解和修改文章中提供的代码示例。 3.您需要在项目中安装 IronOCR 库。 这可以通过使用 Visual Studio 中的 NuGet 包管理器或命令行界面来完成。
确保满足这些先决条件,您就可以进入 IronOCR 的工作流程了。
3. 创建新的Visual Studio项目
要开始使用 IronOCR,第一步是创建一个新的 Visual Studio 项目。
打开 Visual Studio 并转到 "文件",然后悬停在 "新建 "上,点击 "项目"。
新项目
在新窗口中,选择 "控制台应用程序",然后单击 "下一步"。
控制台应用程序
将出现一个新窗口,输入新项目的名称和位置,然后点击下一步。
项目配置
最后,提供目标框架并点击创建。
目标框架
现在,您新的Visual Studio项目已创建。 让我们安装IronOCR。
4. 安装IronOCR
有几种下载和安装 IronOCR 库的方法。 这是两个最简单的方法。
1.使用 Visual Studio NuGet 软件包管理器 2.使用 Visual Studio 命令行
4.1. 使用Visual Studio NuGet包管理器
IronOCR 可通过 Visual Studio NuGet 包管理器包含在 C# 项目中。
选择 工具 > NuGet软件包管理器 > 管理解决方案的 NuGet 软件包,导航至 NuGet 软件包管理器图形用户界面。
NuGet 软件包管理器
之后,将出现一个新窗口。 搜索 IronOCR 并将软件包安装到项目中。
在NuGet包管理器UI中选择IronOCR包
还可以使用上述相同方法安装 IronOCR 的其他语言包。
4.2. 使用Visual Studio命令行
1.在 Visual Studio 中,转到 工具 > NuGet软件包管理器 > 软件包管理器控制台
在包管理器控制台标签中输入以下行安装IronOCR:
Install-Package IronOcr
包管理器控制台
现在,软件包将下载/安装到当前项目中,即可使用。
5. 使用IronOCR从发票中提取数据
使用IronOCR,您可以通过几行代码轻松从发票中提取数据,并将该数据用于后续的数据输入等过程。 这将取代手动数据输入及更多。
以下是一个用于提取文本的发票示例。
示例发票
现在,让我们编写代码以从这张发票中提取所有数据。
using IronOcr;
using System;
// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();
// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
// Read the image using the Read method, which performs OCR
var result = ocr.Read(input);
// Output the extracted text to the console
Console.WriteLine(result.Text);
}using IronOcr;
using System;
// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();
// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
// Read the image using the Read method, which performs OCR
var result = ocr.Read(input);
// Output the extracted text to the console
Console.WriteLine(result.Text);
}Imports IronOcr
Imports System
' Initialize a new instance of the IronTesseract class
Private ocr = New IronTesseract()
' Use the OcrInput object to load the image file
Using input = New OcrInput("r2.png")
' Read the image using the Read method, which performs OCR
Dim result = ocr.Read(input)
' Output the extracted text to the console
Console.WriteLine(result.Text)
End Using上述代码以图像形式获取输入,然后使用Read方法从IronTesseract类提取数据。
发票解析器
5.1. 发票处理以提取发票中特定数据
您还可以从发票中提取特定数据,如客户发票号。 下面是从发票中提取客户发票号的代码。
using IronOcr;
using System;
using System.Text.RegularExpressions;
// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();
// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
// Perform OCR on the image
var result = ocr.Read(input);
// Define a regular expression pattern for the invoice number
var linePattern = @"INV\/\d{4}\/\d{5}";
// Match the pattern in the extracted text
var lineMatch = Regex.Match(result.Text, linePattern);
// Check if the pattern matches any part of the text
if (lineMatch.Success)
{
// If a match is found, print the invoice number
var lineValue = lineMatch.Value;
Console.WriteLine("Customer Invoice number: " + lineValue);
}
}using IronOcr;
using System;
using System.Text.RegularExpressions;
// Initialize a new instance of the IronTesseract class
var ocr = new IronTesseract();
// Use the OcrInput object to load the image file
using (var input = new OcrInput(@"r2.png"))
{
// Perform OCR on the image
var result = ocr.Read(input);
// Define a regular expression pattern for the invoice number
var linePattern = @"INV\/\d{4}\/\d{5}";
// Match the pattern in the extracted text
var lineMatch = Regex.Match(result.Text, linePattern);
// Check if the pattern matches any part of the text
if (lineMatch.Success)
{
// If a match is found, print the invoice number
var lineValue = lineMatch.Value;
Console.WriteLine("Customer Invoice number: " + lineValue);
}
}Imports IronOcr
Imports System
Imports System.Text.RegularExpressions
' Initialize a new instance of the IronTesseract class
Private ocr = New IronTesseract()
' Use the OcrInput object to load the image file
Using input = New OcrInput("r2.png")
' Perform OCR on the image
Dim result = ocr.Read(input)
' Define a regular expression pattern for the invoice number
Dim linePattern = "INV\/\d{4}\/\d{5}"
' Match the pattern in the extracted text
Dim lineMatch = Regex.Match(result.Text, linePattern)
' Check if the pattern matches any part of the text
If lineMatch.Success Then
' If a match is found, print the invoice number
Dim lineValue = lineMatch.Value
Console.WriteLine("Customer Invoice number: " & lineValue)
End If
End Using
发票扫描
6.结论
IronOCR的发票OCR API利用机器学习和计算机视觉革新了从发票中提取数据。 这项技术将发票文本和数字转换为机器可读格式,简化了数据提取以便分析、集成和流程改进。 它为自动化发票处理提供了一个强大的解决方案,提高准确性,优化像应付账款这样的工作流程。 使用此技术也可以实现从扫描发票的自动数据输入。
IronOCR利用Tesseract的最佳结果提供高精确度,无需额外设置。 它支持 多页框架 TIFF、PDF 文件 和所有流行的图像格式。 还可以从图像中读取条形码值。
请访问主页网站以获取更多关于IronOCR的信息。 欲了解关于发票OCR的更多教程,请访问以下详细发票OCR教程。 要了解如何使用计算机视觉查找文本如发票字段,请访问此计算机视觉操作指南。
常见问题解答
如何通过OCR自动化发票数据处理?
您可以使用IronOCR通过利用其机器学习算法来自动化发票数据处理。IronOCR从数字和扫描的发票中提取诸如供应商信息、发票号码和价格等细节,减少手动输入错误并提高效率。
设置发票OCR API涉及哪些步骤?
要使用IronOCR设置发票OCR API,请首先通过Visual Studio的NuGet包管理器下载并安装库。接下来,创建一个新的C#项目,集成IronOCR,并使用其方法加载和读取图像文件以进行文本提取。
IronOCR可以提取如发票号码之类的特定数据吗?
是的,IronOCR可以提取如发票号码之类的特定数据。它利用正则表达式来匹配提取文本中的模式,让您可以从发票中提取特定信息。
IronOCR有什么发票处理受益功能?
IronOCR包括图像预处理、条形码识别和文件解析等功能。这些功能提高了准确提取和处理各种发票格式文本的能力,改善数据采集和工作流程效率。
图像预处理如何提高OCR结果?
IronOCR中的图像预处理通过在文本提取之前优化图像质量来提高OCR结果。这包括像对比度调整和噪声减少这样的操作,可以从发票中提取更准确的数据。
是否可以将IronOCR用于数字和扫描的发票?
是的,IronOCR能够处理数字和扫描的发票。它使用先进的机器学习和计算机视觉技术从各种格式和图像质量中准确提取文本。
IronOCR如何处理多页格式和文件类型?
IronOCR支持多页格式和流行的图像和PDF文件类型。它能够有效地从复杂文档中提取文本,使其在各种发票处理应用中具有多样性。
开发人员在哪里可以找到使用IronOCR的教程?
开发人员可以在IronOCR网站上找到教程和其他资源。该网站提供了一系列学习材料,包括如何指南和博客文章,适用于在不同情境中应用IronOCR。






