跳至页脚内容
使用 IRONOCR

OCR 收据数据提取(逐步教程)

使用 IronOCR 进行收据 OCR 可改变企业和个人的游戏规则。通过该程序,您可以从实物收据中提取重要信息,并将其转换为数字数据。 本文将带您逐步了解如何使用 IronOCR 从收据中获得最大收益。

OCR 简介

光学字符识别或 OCR 是一种允许计算机从图像或扫描文件中读取和理解文本的技术。 通过将印刷文本转换为机器可读文本,OCR 使您能够存储、处理和分析物理文档中包含的信息。

2. IronOCR简介

IronOCR 是面向 C# 和 .NET 开发人员的 OCR(光学字符识别)库。 它使开发人员能够从图像PDF和其他文档格式中提取文本。 IronOCR 基于广受欢迎的Tesseract OCR 引擎,并增加了其他功能,使其成为各种应用(包括收据 OCR)的理想选择。

3. 使用IronOCR进行数据提取的好处

以下是使用 IronOCR 进行 OCR 收据数据提取的一些主要优势:

  • 高准确性:IronOCR 可提供出色的 OCR API 准确性,确保从收据和其他文档中提取可靠的数据。
  • Multilingual support:IronOCR 支持超过 125 种语言,适合全球应用。
  • 易于使用:该库提供了简单直观的 API,使开发人员能够轻松地在其项目中实现 OCR 功能。
  • 可定制:IronOCR 提供了各种选项,用于微调 OCR 结果,确保为您的特定用例提取最佳数据。

4. IronOCR的工作原理

IronOCR 采用先进的 OCR 算法来识别和提取图像和文档中的文本。 它可以处理各种格式,包括 JPEG、PNG、TIFF 和 PDF。 该库可读取输入文件,识别其中的文本,并将提取的文本输出为字符串,然后根据需要进行处理或存储。 IronOCR 还使用计算机视觉以达到最佳效果。

5. 使用IronOCR的先决条件

要开始使用 IronOCR 进行收据数据提取,首先需要安装 IronOCR 软件包。 这可以通过 .NET 的软件包管理器 NuGet 轻松完成。 只需在 Visual Studio 中打开您的项目,然后按照以下步骤操作即可:

1.在解决方案资源管理器中右键单击您的项目,然后选择 "管理 NuGet 包"。

  1. 在 NuGet 包管理器窗口中,搜索"IronOCR"。 3.选择 IronOcr 软件包并点击 "安装"。

IOCR 收据数据提取(分步教程),图 1:在 NuGet 软件包管理器 UI 中搜索 IronOCR 软件包在 NuGet 软件包管理器用户界面中搜索 IronOcr 软件包

6. 准备收据图像

在从收据中提取数据之前,您需要确保收据图像的高质量,以提高收据 OCR API 流程的准确性。 以下是一些捕捉收据良好形象的技巧:

1.使用扫描文件。 您可以使用高分辨率扫描仪进行收据扫描。 2.确保收据光线充足,没有阴影。 3.理顺收据上的任何折痕或褶皱,以免隐藏关键信息。 4.确保收据上的文字清晰、不模糊,以提高收据处理能力。

OCR 收据数据提取(分步教程),图 2:用于文本提取的收据图像示例样本收据图像用于文本提取

7. 对收据图像执行OCR

安装好 IronOCR 并准备好收据图像后,就可以执行 OCR 处理了。 在您的 .NET 应用程序中,使用以下代码片段:

using IronOcr;

// Initialize the IronTesseract class, which is responsible for OCR operations
var ocr = new IronTesseract();

// Use the OcrInput class to load the image of your receipt.
// Replace @"path/to/your/receipt/image.png" with the actual file path.
using (var ocrInput = new OcrInput(@"path/to/your/receipt/image.png"))
{
    // Read the content of the image and perform OCR recognition
    var result = ocr.Read(ocrInput);

    // Output the recognized text to the console
    Console.WriteLine(result.Text);
}
using IronOcr;

// Initialize the IronTesseract class, which is responsible for OCR operations
var ocr = new IronTesseract();

// Use the OcrInput class to load the image of your receipt.
// Replace @"path/to/your/receipt/image.png" with the actual file path.
using (var ocrInput = new OcrInput(@"path/to/your/receipt/image.png"))
{
    // Read the content of the image and perform OCR recognition
    var result = ocr.Read(ocrInput);

    // Output the recognized text to the console
    Console.WriteLine(result.Text);
}
Imports IronOcr

' Initialize the IronTesseract class, which is responsible for OCR operations
Private ocr = New IronTesseract()

' Use the OcrInput class to load the image of your receipt.
' Replace @"path/to/your/receipt/image.png" with the actual file path.
Using ocrInput As New OcrInput("path/to/your/receipt/image.png")
	' Read the content of the image and perform OCR recognition
	Dim result = ocr.Read(ocrInput)

	' Output the recognized text to the console
	Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

代码解释

using IronOcr;
using IronOcr;
Imports IronOcr
$vbLabelText   $csharpLabel

该行将 IronOCR 库导入到您的 .NET 应用程序中,允许您访问其功能。

var ocr = new IronTesseract();
var ocr = new IronTesseract();
Dim ocr = New IronTesseract()
$vbLabelText   $csharpLabel

此行将创建 IronTesseract 类的新实例,该类是 IronOCR 中负责 OCR 操作的主类。

using (var ocrInput = new OcrInput(@"path/to/your/receipt/image.png"))
using (var ocrInput = new OcrInput(@"path/to/your/receipt/image.png"))
Using ocrInput As New OcrInput("path/to/your/receipt/image.png")
$vbLabelText   $csharpLabel

在此,创建了 OcrInput 类的新实例,该实例表示 OCR 流程的输入图像。 @"path/to/your/receipt/image.png"应替换为收据图片的实际文件路径。 using 语句可确保在 OCR 操作完成后,分配给 OcrInput 实例的资源被正确释放。

var result = ocr.Read(ocrInput);
var result = ocr.Read(ocrInput);
Dim result = ocr.Read(ocrInput)
$vbLabelText   $csharpLabel

此行调用 IronTesseract 实例的 Read 方法,并将 OcrInput 对象作为参数传递。 Read 方法处理输入图像并执行 OCR 操作,识别并提取图像中的文本。 这将开启收据识别流程。

Console.WriteLine(result.Text);
Console.WriteLine(result.Text);
Console.WriteLine(result.Text)
$vbLabelText   $csharpLabel

最后,这一行将提取的文本输出到控制台。 result 对象是 OcrResult 类的实例,包含识别的文本和有关 OCR 过程的其他信息。 提取的文本可通过访问 result 对象的 Text 属性显示。

OCR 收据数据提取(分步教程),图 3:提取文本的输出提取文本的输出

微调OCR结果

IronOCR 提供多种选项来提高 OCR 的准确性和性能。 这包括预处理图像、调整 OCR 引擎设置以及为收据选择合适的语言。

图像预处理

您可以通过应用图像预处理技术来增强 OCR 结果,例如

1.纠偏:纠正图像中的任何旋转或倾斜。 2.去噪:通过去除图片中的噪点来提高文本的可读性。

下面是一个如何应用这些技术的示例:

using IronOcr;

// Initialize the IronTesseract class
var ocr = new IronTesseract();

// Load the image of your receipt and apply preprocessing techniques
using (var input = new OcrInput(@"path/to/your/receipt/image.png"))
{
    input.DeNoise(); // Remove noise from the image
    input.DeSkew();  // Correct any skewing in the image

    // Perform OCR and extract the recognized text
    var result = ocr.Read(input);
    Console.WriteLine(result.Text);
}
using IronOcr;

// Initialize the IronTesseract class
var ocr = new IronTesseract();

// Load the image of your receipt and apply preprocessing techniques
using (var input = new OcrInput(@"path/to/your/receipt/image.png"))
{
    input.DeNoise(); // Remove noise from the image
    input.DeSkew();  // Correct any skewing in the image

    // Perform OCR and extract the recognized text
    var result = ocr.Read(input);
    Console.WriteLine(result.Text);
}
Imports IronOcr

' Initialize the IronTesseract class
Private ocr = New IronTesseract()

' Load the image of your receipt and apply preprocessing techniques
Using input = New OcrInput("path/to/your/receipt/image.png")
	input.DeNoise() ' Remove noise from the image
	input.DeSkew() ' Correct any skewing in the image

	' Perform OCR and extract the recognized text
	Dim result = ocr.Read(input)
	Console.WriteLine(result.Text)
End Using
$vbLabelText   $csharpLabel

语言选择

IronOCR 支持超过 125 种语言,为您的收据选择正确的语言可以显著提高 OCR 结果。 要指定语言,请在代码中添加以下一行:

ocr.Configuration.Language = OcrLanguage.English;
ocr.Configuration.Language = OcrLanguage.English;
ocr.Configuration.Language = OcrLanguage.English
$vbLabelText   $csharpLabel

从 OCR 结果中提取数据

完成 OCR 处理后,就该从文本中提取特定信息了。 根据您的需要,您可能需要提取以下数据:

1.商店名称和地址。 2.购买日期和时间。 3.项目名称和价格。 4.小计、税金和总金额。

为此,您可以在 .NET 应用程序中使用正则表达式或字符串操作技术。 例如,您可以使用以下代码片段从 OCR 结果中提取日期:

using System;
using System.Text.RegularExpressions;

// Define a regular expression pattern for matching dates
var datePattern = @"\d{1,2}\/\d{1,2}\/\d{2,4}";

// Search for a date in the OCR result text
var dateMatch = Regex.Match(result.Text, datePattern);
if (dateMatch.Success)
{
    // Parse the matched date string into a DateTime object
    var dateValue = DateTime.Parse(dateMatch.Value);
    Console.WriteLine("Date: " + dateValue);
}
using System;
using System.Text.RegularExpressions;

// Define a regular expression pattern for matching dates
var datePattern = @"\d{1,2}\/\d{1,2}\/\d{2,4}";

// Search for a date in the OCR result text
var dateMatch = Regex.Match(result.Text, datePattern);
if (dateMatch.Success)
{
    // Parse the matched date string into a DateTime object
    var dateValue = DateTime.Parse(dateMatch.Value);
    Console.WriteLine("Date: " + dateValue);
}
Imports System
Imports System.Text.RegularExpressions

' Define a regular expression pattern for matching dates
Private datePattern = "\d{1,2}\/\d{1,2}\/\d{2,4}"

' Search for a date in the OCR result text
Private dateMatch = Regex.Match(result.Text, datePattern)
If dateMatch.Success Then
	' Parse the matched date string into a DateTime object
	Dim dateValue = DateTime.Parse(dateMatch.Value)
	Console.WriteLine("Date: " & dateValue)
End If
$vbLabelText   $csharpLabel

您可以为需要从收据中提取的其他信息创建类似的模式。

存储和分析提取的数据

现在,您已经从收据中提取了相关信息,可以将其存储到数据库中、进行分析或导出为 CSV、JSON 或 Excel 等其他文件格式。

结论

总之,使用 IronOCR 进行收据 OCR 是实现财务数据数字化和管理的创新而高效的解决方案。 有了 IronOCR,您可以取代人工数据录入。 按照本指南的步骤,您就可以利用 IronOCR 的强大功能来改进您的费用跟踪和数据分析。 最重要的是,IronOCR 提供免费试用,让您无需任何承诺即可体验其功能。

试用期结束后,如果您决定继续使用 IronOCR,许可证起价为 $799 ,这为您在应用程序中利用 OCR 技术的优势提供了一种具有成本效益的方式。

常见问题解答

如何使用C#将收据图像转换为数字文本?

您可以通过初始化IronTesseract类,使用OcrInput加载图像,并调用Read方法提取文本,使用IronOCR将收据图像转换为数字文本。

什么是光学字符识别,它如何用于收据?

光学字符识别(OCR)是一种将图像或扫描文档中的文本转换为机器可读数据的技术。它通过扫描印刷材料并将其转换为可以使用IronOCR存储和分析的文本来用于收据。

如何提高收据图像的OCR结果质量?

提高OCR结果可以通过确保收据图像质量高,使用倾斜校正和去噪等图像预处理技术,并在IronOCR中选择正确的语言设置来实现。

使用C# OCR库进行收据数据提取有哪些优势?

使用像IronOCR这样的C# OCR库可以通过提供高精度,支持超过125种语言,以及自定义选项来提高收据数据提取的质量,并且易于整合到.NET项目中。

如何使用提取的收据数据进行报告和分析?

提取的收据数据可以存储在数据库中或导出为CSV、JSON或Excel等格式,使进一步的处理、报告和分析变得可能。

在.NET环境中安装OCR库的过程是什么?

要在.NET环境中安装IronOCR,请打开Visual Studio,导航到‘管理NuGet包’,搜索‘IronOCR’,然后将其安装到您的项目中。

如何从OCR输出中提取收据的特定数据?

可以通过使用正则表达式或字符串操作来解析诸如商店名称、购买日期和商品价格等信息,从OCR输出中提取特定数据。

收据数据OCR中的常见挑战是什么,如何应对?

常见的挑战包括图像质量差和复杂的收据布局。可以通过提高图像质量,使用预处理技术以及使用IronOCR的自定义选项来解决这些问题。

IronOCR是否提供收据OCR的多语言支持?

是的,IronOCR提供多语言支持,能够识别和处理超过125种语言的文本,提高其在全球应用中的实用性。

C# OCR库是否提供试用版,以及有哪些许可选项?

IronOCR提供免费试用版,允许用户探索其功能。试用期后,提供各种许可选项,起步于具有成本效益的轻量版本。

Kannaopat Udonpant
软件工程师
在成为软件工程师之前,Kannapat 在日本北海道大学完成了环境资源博士学位。在攻读学位期间,Kannapat 还成为了车辆机器人实验室的成员,隶属于生物生产工程系。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程团队,专注于 IronPDF。Kannapat 珍视他的工作,因为他可以直接从编写大多数 IronPDF 代码的开发者那里学习。除了同行学习外,Kannapat 还喜欢在 Iron Software 工作的社交方面。不撰写代码或文档时,Kannapat 通常可以在他的 PS5 上玩游戏或重温《最后生还者》。