使用 IRONOCR 如何在 C# 教程中从发票中获取文本 Kannapat Udonpant 已更新:八月 20, 2025 下载 IronOCR NuGet 下载 DLL 下载 Windows 安装程序 免费试用 法学硕士副本 法学硕士副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在双子座打开 向 Gemini 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 如何在 Tesseract 中对收据进行 OCR 识别 安装通过 Tesseract 进行收据 OCR 的 C# 库 探索丰富功能的 C# 库以对收据执行 OCR 使用 Tesseract 从收据中提取数据 在提取的文本结果中搜索特定数据 读取输入收据图像上的条形码值 1. IronOCR,一种光学字符识别 API IronOCR 是一个 OCR 库,可用于识别图像中的文本数据以进行信息提取,包括收据 OCR。 它建立在 Tesseract OCR 引擎上,该引擎被认为是迄今为止用于收据识别的最准确的 OCR 引擎之一。 IronOCR 可以读取不同文档类型的关键信息,包括 PNG、JPG、TIFF、JSON 和 PDF 格式,并且可以识别多种语言的文本。 IronOCR 的一个重要功能是能够自动检测文本方向,即使图像已旋转或倾斜。 这对于提交收据时的准确文本识别和数据提取至关重要,因为收据通常包含大量信息,并且可能折叠或皱褶,导致文本倾斜。 2. IronOCR功能 C# OCR 使用深度学习从照片、扫描的文档和 PDF 中扫描和识别文本。 .NET OCR 支持超过125种全球语言。 IronOCR 可以读取多种文件格式的图像中的文本,包括 PNG、JPG、TIFF 和 PDF。 从提取信息中可以生成、结构化数据、JSON 输出或可搜索的 PDF。 IronOCR 支持 .NET 版本 5、6 和 7(Core、Framework 和 Standard)。 IronOCR 将输入根据文本区域划分成不同的图片。 它使用计算机视觉来识别包含文本元素的区域。 3. 在Visual Studio中创建新项目 打开 Visual Studio 并转到文件菜单。 选择"新建项目",然后选择控制台应用程序。 在适当的文本框中输入项目名称并选择路径。 然后,点击创建按钮。 选择所需的 .NET 框架,如下图所示: 控制台应用程序的项目结构将被生成。 完成后,它将打开 Program.cs 文件,您可以在其中编写和执行源代码。 4. 安装IronOCR 在 Visual Studio 中,您可以轻松地将 IronOCR 集成到您的 C# 项目中。 IronOCR 提供了多种与 C# .NET 项目集成的方式。 在这里,我们将讨论其中之一:使用 NuGet 包管理器安装 IronOCR。 在 Visual Studio 中,进入工具 > NuGet 包管理器 > 包管理器控制台 一个新的控制台将出现在 Visual Studio 窗口的底部。 在控制台中输入以下命令并按回车。 Install-Package IronOcr IronOCR将在几秒钟内安装完成。 5. 使用 IronOCR 从收据中提取数据 IronOCR 是一个强大的 OCR 库,可以用于从收据中提取和访问详细数据。使用 IronOCR,您可以将收据的图片转换为易于分析和处理的机读文本,而不会影响数据隐私。 以下是如何使用 IronOCR 从收据中提取文本的示例: using IronOcr; using System; class Program { static void Main() { IronTesseract ocrTesseract = new IronTesseract(); // Load the receipt image using (OcrInput ocrInput = new OcrInput("ocr.png")) { // Read the OCR result OcrResult ocrResult = ocrTesseract.Read(ocrInput); string recognizedText = ocrResult.Text; // Output the recognized text to the console Console.WriteLine(recognizedText); } } } using IronOcr; using System; class Program { static void Main() { IronTesseract ocrTesseract = new IronTesseract(); // Load the receipt image using (OcrInput ocrInput = new OcrInput("ocr.png")) { // Read the OCR result OcrResult ocrResult = ocrTesseract.Read(ocrInput); string recognizedText = ocrResult.Text; // Output the recognized text to the console Console.WriteLine(recognizedText); } } } Imports IronOcr Imports System Friend Class Program Shared Sub Main() Dim ocrTesseract As New IronTesseract() ' Load the receipt image Using ocrInput As New OcrInput("ocr.png") ' Read the OCR result Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput) Dim recognizedText As String = ocrResult.Text ' Output the recognized text to the console Console.WriteLine(recognizedText) End Using End Sub End Class $vbLabelText $csharpLabel 请参考从图像读取文本教程以了解更多关于 IronOCR 如何使用 C# 从图像中读取文本。 以上代码的输出: - LOGO SHOP - LOREM IPSUM - DOLOR SIT AMET CONSECTETUR - ADIPISCING ELIT - 1 LOREM IPSUM $3.20 - 2 ORNARE MALESUADA $9.50 - 3 PORTA FERMENTUM $5.90 - 4 SODALES ARCU $6.00 - 5 ELEIFEND $9.00 - 6 SEM NISIMASSA $0.50 - 7 DUIS FAMES DIS $7.60 - 8 FACILISI RISUS $810 - TOTAL AMOUNT $49.80 - CASH $50.00 6. 使用 IronOCR 从收据图像中提取特定数据 IronOCR 允许开发人员从扫描的收据中提取关键信息,例如税额和商家名称。 这是一个展示如何从收据图像中提取总金额的示例: using IronOcr; using System; class Program { static void Main() { IronTesseract ocrTesseract = new IronTesseract(); // Set the language for OCR ocrTesseract.Language = OcrLanguage.English; // Load the receipt image using (OcrInput ocrInput = new OcrInput("ocr.png")) { // Optimize the input image for OCR ocrInput.DeNoise(true); ocrInput.Contrast(); ocrInput.EnhanceResolution(); ocrInput.ToGrayScale(); OcrResult ocrResult = ocrTesseract.Read(ocrInput); // Search for the total amount in the OCR result var totalAmount = ocrResult.Text.Contains("Total:") ? ocrResult.Text.Split("Total:")[1].Split("\n")[0] : ""; Console.WriteLine("Total Amount: " + totalAmount); } } } using IronOcr; using System; class Program { static void Main() { IronTesseract ocrTesseract = new IronTesseract(); // Set the language for OCR ocrTesseract.Language = OcrLanguage.English; // Load the receipt image using (OcrInput ocrInput = new OcrInput("ocr.png")) { // Optimize the input image for OCR ocrInput.DeNoise(true); ocrInput.Contrast(); ocrInput.EnhanceResolution(); ocrInput.ToGrayScale(); OcrResult ocrResult = ocrTesseract.Read(ocrInput); // Search for the total amount in the OCR result var totalAmount = ocrResult.Text.Contains("Total:") ? ocrResult.Text.Split("Total:")[1].Split("\n")[0] : ""; Console.WriteLine("Total Amount: " + totalAmount); } } } Imports Microsoft.VisualBasic Imports IronOcr Imports System Friend Class Program Shared Sub Main() Dim ocrTesseract As New IronTesseract() ' Set the language for OCR ocrTesseract.Language = OcrLanguage.English ' Load the receipt image Using ocrInput As New OcrInput("ocr.png") ' Optimize the input image for OCR ocrInput.DeNoise(True) ocrInput.Contrast() ocrInput.EnhanceResolution() ocrInput.ToGrayScale() Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput) ' Search for the total amount in the OCR result Dim totalAmount = If(ocrResult.Text.Contains("Total:"), ocrResult.Text.Split("Total:")(1).Split(vbLf)(0), "") Console.WriteLine("Total Amount: " & totalAmount) End Using End Sub End Class $vbLabelText $csharpLabel 得益于OcrInput类提供的多种设置,可以优化输入图像以在 OCR 过程中提高准确性。 输入 输出 - Total 16.5 7. 读取收据上的条形码 IronOCR 可用于读取收据上的条形码以及文本。 要读取收据上的条形码,您需要结合BarcodeReader类和ReadBarCodes方法。 以下是如何读取条形码的示例: using IronOcr; using System; class Program { static void Main() { var ocrTesseract = new IronTesseract(); ocrTesseract.Configuration.ReadBarCodes = true; // Load the receipt image with a barcode using (var ocrInput = new OcrInput("b.png")) { OcrResult ocrResult = ocrTesseract.Read(ocrInput); // Output the barcode values to the console foreach (var barcode in ocrResult.Barcodes) { Console.WriteLine(barcode.Value); } } } } using IronOcr; using System; class Program { static void Main() { var ocrTesseract = new IronTesseract(); ocrTesseract.Configuration.ReadBarCodes = true; // Load the receipt image with a barcode using (var ocrInput = new OcrInput("b.png")) { OcrResult ocrResult = ocrTesseract.Read(ocrInput); // Output the barcode values to the console foreach (var barcode in ocrResult.Barcodes) { Console.WriteLine(barcode.Value); } } } } Imports IronOcr Imports System Friend Class Program Shared Sub Main() Dim ocrTesseract = New IronTesseract() ocrTesseract.Configuration.ReadBarCodes = True ' Load the receipt image with a barcode Using ocrInput As New OcrInput("b.png") Dim ocrResult As OcrResult = ocrTesseract.Read(ocrInput) ' Output the barcode values to the console For Each barcode In ocrResult.Barcodes Console.WriteLine(barcode.Value) Next barcode End Using End Sub End Class $vbLabelText $csharpLabel 输入图像 输出文本 8. 结论 本文上面解释了如何在 C# 项目中安装和使用 IronOCR 以从收据中提取数据,提供了示例代码片段。 请阅读从图像读取文本的教程。 IronOCR 是Iron Suite的一部分,该套件包括五个不同的 .NET 库用于操作文档和图像。 您可以以仅相当于两个IronOCR 许可证的价格购买整个 Iron Suite。 在您的生产应用程序中尝试 IronOCR,免费试用。 常见问题解答 如何使用 IronOCR 在 C# 中对收据图像执行 OCR? 您可以使用 IronOCR 通过加载图像到 OcrInput 类并调用 Read 方法来提取文本数据,如项目列表和总金额,从而对收据图像执行 OCR。 在发票处理方面使用 IronOCR 相较于 Tesseract 的优势是什么? IronOCR 提供增强的准确性,支持超过 125 种语言,并包括自动文本方向检测和深度学习功能。它还更易于通过 NuGet 包管理器与 C# 项目集成。 如何将 IronOCR 集成到 Visual Studio 项目中? 要将 IronOCR 集成到 Visual Studio 项目,请使用 NuGet 包管理器。导航到工具 > NuGet 包管理器 > 包管理器控制台,然后执行 Install-Package IronOcr 将该库添加到项目中。 IronOCR 可以在收据 OCR 中处理多种语言吗? 是的,IronOCR 可以处理多种语言,支持超过 125 种全球语言,使其非常适合处理带有多语种文本的收据。 IronOCR 如何改善收据中的文本识别准确性? IronOCR 通过深度学习、自动文本方向检测等功能及使用 OcrInput 类优化图像以获得更好的 OCR 结果来改善文本识别准确性。 是否可以使用 IronOCR 从收据中提取项目化清单? 是的,IronOCR 可以用来从收据中提取项目化清单,通过执行 OCR 后处理文本数据并通过模式匹配识别行项目。 IronOCR 如何处理收据上的条形码读取? IronOCR 通过使用 BarcodeReader 类和 ReadBarCodes 方法扫描和解码收据上存在的条形码来处理条形码读取。 IronOCR 可以处理哪些文件格式以进行收据 OCR? IronOCR 可以处理多种文件格式以进行收据 OCR,包括 PNG、JPG、TIFF 和 PDF,使其适用于不同类型的输入。 在 C# 中设置 IronOCR 以进行发票处理需要哪些步骤? 设置 IronOCR 用于发票处理涉及通过 NuGet 安装库,配置带有收据图像的 OcrInput,并使用 Read 方法提取文本数据。您还可以使用库的功能以提高准确性并提取总计等特定数据。 Kannapat Udonpant 立即与工程团队聊天 软件工程师 在成为软件工程师之前,Kannapat 在日本北海道大学完成了环境资源博士学位。在攻读学位期间,Kannapat 还成为了车辆机器人实验室的成员,隶属于生物生产工程系。2022 年,他利用自己的 C# 技能加入 Iron Software 的工程团队,专注于 IronPDF。Kannapat 珍视他的工作,因为他可以直接从编写大多数 IronPDF 代码的开发者那里学习。除了同行学习外,Kannapat 还喜欢在 Iron Software 工作的社交方面。不撰写代码或文档时,Kannapat 通常可以在他的 PS5 上玩游戏或重温《最后生还者》。 相关文章 已发布十二月 18, 2025 C# 读取 PDF 表单字段:以编程方式提取表单数据 了解如何使用IronPDF在C#中读取PDF表单字段。从可填写PDF中提取文本、复选框、下拉列表等,提供简单的代码示例。 阅读更多 已发布十二月 18, 2025 C# 从 PDF 中提取图像:完整开发者指南 了解如何在C#中使用IronPDF强大的方法从PDF文档中提取图像。包含.NET开发人员的完整指南和代码示例。 阅读更多 已发布十二月 18, 2025 C# 将 PDF 转换为图像:完整开发者指南 了解如何在C#中使用IronPDF将PDF文档转换为图像。提供JPG、PNG和TIFF转换的逐步指南和代码示例。 阅读更多 如何在 C# 中使用 OCR 车牌(教程)如何在 C# 中从截图中获取文本
已发布十二月 18, 2025 C# 读取 PDF 表单字段:以编程方式提取表单数据 了解如何使用IronPDF在C#中读取PDF表单字段。从可填写PDF中提取文本、复选框、下拉列表等,提供简单的代码示例。 阅读更多