使用 IRONOCR 收據掃描 API 開發者教學 Kannapat Udonpant 更新日期:6月 22, 2025 Download IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 收據掃描API使用先進的OCR技術從收據中提取關鍵數據。 通過消除手動錯誤並提高生產力,它簡化了數據輸入過程。 該API功能多樣且準確,支持多語言、貨幣和格式。 通過自動化收據解析,企業可以深入了解支出模式並做出數據驅動的決策。 本文將演示如何使用C# OCR庫IronOCR從收據中提取重要信息。 IronOCR IronOCR是由Iron Software開發的多功能OCR庫和API,為開發人員提供了一個從各種來源(如掃描文檔、圖像和PDF)中提取文本的強大解決方案。 憑藉其先進的OCR算法、計算機視覺和機器學習模型,即使在挑戰性場景中,IronOCR也能確保高度的準確性和可靠性。 該庫支持多種語言和字體樣式,非常適合全球應用。 通過將IronOCR與機器學習模型功能集成到他們的應用程式中,開發人員可以輕鬆地自動化數據輸入、文本分析和其他任務,提升生產力和效率。 使用IronOCR,開發人員可以輕鬆地從各種來源中獲取文本,包括文檔、照片、截圖,甚至實時攝像頭反饋的JSON響應。 通過利用複雜的算法和機器學習模型,IronOCR分析圖像數據,識別單個字符,並將其轉換為機器可讀的文本。 這個獲取的文本可以用於各種目的,例如數據輸入、信息檢索、文本分析和手動任務的自動化。 必要條件 在開始使用IronOCR之前,您需要滿足一些前提條件。 這些先決條件包括: 確保您已經在您的計算機上設置了合適的開發環境。 這通常涉及到安裝例如Visual Studio之類的集成開發環境 (IDE)。 需要具備C#語言的基本知識。 這將使您能夠有效地理解和修改文章中提供的代碼示例。 您需要在您的項目中安裝IronOCR庫。 這可以通過Visual Studio中的NuGet包管理器或者命令行界面來完成。 通過確保這些前提條件已經滿足,您將準備好開始使用IronOCR。 創建新的Visual Studio專案 要開始使用IronOCR,第一步是創建一個新的Visual Studio項目。 打開Visual Studio,然後轉到文件,懸停在新建,然後點擊項目。 新專案圖片 在新窗口中,選擇控制台應用程序,然後點擊下一步。 控制台應用 將出現一個新窗口。 寫下新專案的名稱和位置,然後點擊下一步。 项目配置 最後,提供目標框架並點擊創建。 目標框架 現在您的新的Visual Studio專案已創建,讓我們安裝IronOCR。 安裝 IronOCR 有幾種方法可以下載並安裝IronOCR庫。 但是,這裡有兩種最簡單的方法。 使用Visual Studio NuGet程序包管理器 使用Visual Studio命令行 使用Visual Studio NuGet包管理器 使用Visual Studio NuGet包管理器可將IronOCR包含在C#項目中。 通過選擇工具 > NuGet包管理器 > 管理解決方案的NuGet包來導航到NuGet包管理器圖形用戶界面 NuGet 套件管理器 之後,一個新窗口將出現。 搜索 IronOCR 並在項目中安裝該套件。 IronOCR 也可以使用上述方法安裝 IronOCR 的其他語言包。 使用Visual Studio命令行 In Visual Studio, go to Tools > NuGet 套件管理器 > Package Manager Console 在包管理器控制台標籤中輸入以下行: Install-Package IronOcr 包管理器控制台 現在包將下載/安裝到當前項目並準備使用。 使用收據OCR API提取數據 使用IronOCR從收據圖像中提取數據並將其保存為結構化數據形式,對於大多數開發人員來說,這是一個救星。 使用IronOCR,你可以只用幾行代碼來實現這一點。 使用此功能,您可以使用不同的文檔類型提取行項目、定價、稅額、總額等等。 using IronOcr; using System; using System.Collections.Generic; using System.Text.RegularExpressions; class ReceiptScanner { static void Main() { var ocr = new IronTesseract(); // Load the image of the receipt using (var input = new OcrInput(@"r2.png")) { // Perform OCR on the input image var result = ocr.Read(input); // Regular expression patterns to extract relevant details from the OCR result var descriptionPattern = @"\w+\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)"; var pricePattern = @"\$\d+(\.\d{2})?"; // Variables to store extracted data var descriptions = new List<string>(); var unitPrices = new List<decimal>(); var taxes = new List<decimal>(); var amounts = new List<decimal>(); var lines = result.Text.Split('\n'); foreach (var line in lines) { // Match each line against the description pattern var descriptionMatch = Regex.Match(line, descriptionPattern); if (descriptionMatch.Success) { descriptions.Add(descriptionMatch.Groups[1].Value.Trim()); unitPrices.Add(decimal.Parse(descriptionMatch.Groups[2].Value)); // Calculate tax and total amount for each item var tax = unitPrices[unitPrices.Count - 1] * 0.15m; taxes.Add(tax); amounts.Add(unitPrices[unitPrices.Count - 1] + tax); } } // Output the extracted data for (int i = 0; i < descriptions.Count; i++) { Console.WriteLine($"Description: {descriptions[i]}"); Console.WriteLine($"Quantity: 1.00 Units"); Console.WriteLine($"Unit Price: ${unitPrices[i]:0.00}"); Console.WriteLine($"Taxes: ${taxes[i]:0.00}"); Console.WriteLine($"Amount: ${amounts[i]:0.00}"); Console.WriteLine("-----------------------"); } } } } using IronOcr; using System; using System.Collections.Generic; using System.Text.RegularExpressions; class ReceiptScanner { static void Main() { var ocr = new IronTesseract(); // Load the image of the receipt using (var input = new OcrInput(@"r2.png")) { // Perform OCR on the input image var result = ocr.Read(input); // Regular expression patterns to extract relevant details from the OCR result var descriptionPattern = @"\w+\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)"; var pricePattern = @"\$\d+(\.\d{2})?"; // Variables to store extracted data var descriptions = new List<string>(); var unitPrices = new List<decimal>(); var taxes = new List<decimal>(); var amounts = new List<decimal>(); var lines = result.Text.Split('\n'); foreach (var line in lines) { // Match each line against the description pattern var descriptionMatch = Regex.Match(line, descriptionPattern); if (descriptionMatch.Success) { descriptions.Add(descriptionMatch.Groups[1].Value.Trim()); unitPrices.Add(decimal.Parse(descriptionMatch.Groups[2].Value)); // Calculate tax and total amount for each item var tax = unitPrices[unitPrices.Count - 1] * 0.15m; taxes.Add(tax); amounts.Add(unitPrices[unitPrices.Count - 1] + tax); } } // Output the extracted data for (int i = 0; i < descriptions.Count; i++) { Console.WriteLine($"Description: {descriptions[i]}"); Console.WriteLine($"Quantity: 1.00 Units"); Console.WriteLine($"Unit Price: ${unitPrices[i]:0.00}"); Console.WriteLine($"Taxes: ${taxes[i]:0.00}"); Console.WriteLine($"Amount: ${amounts[i]:0.00}"); Console.WriteLine("-----------------------"); } } } } Imports Microsoft.VisualBasic Imports IronOcr Imports System Imports System.Collections.Generic Imports System.Text.RegularExpressions Friend Class ReceiptScanner Shared Sub Main() Dim ocr = New IronTesseract() ' Load the image of the receipt Using input = New OcrInput("r2.png") ' Perform OCR on the input image Dim result = ocr.Read(input) ' Regular expression patterns to extract relevant details from the OCR result Dim descriptionPattern = "\w+\s+(.*?)\s+(\d+\.\d+)\s+Units\s+(\d+\.\d+)\s+Tax15%\s+\$(\d+\.\d+)" Dim pricePattern = "\$\d+(\.\d{2})?" ' Variables to store extracted data Dim descriptions = New List(Of String)() Dim unitPrices = New List(Of Decimal)() Dim taxes = New List(Of Decimal)() Dim amounts = New List(Of Decimal)() Dim lines = result.Text.Split(ControlChars.Lf) For Each line In lines ' Match each line against the description pattern Dim descriptionMatch = Regex.Match(line, descriptionPattern) If descriptionMatch.Success Then descriptions.Add(descriptionMatch.Groups(1).Value.Trim()) unitPrices.Add(Decimal.Parse(descriptionMatch.Groups(2).Value)) ' Calculate tax and total amount for each item Dim tax = unitPrices(unitPrices.Count - 1) * 0.15D taxes.Add(tax) amounts.Add(unitPrices(unitPrices.Count - 1) + tax) End If Next line ' Output the extracted data For i As Integer = 0 To descriptions.Count - 1 Console.WriteLine($"Description: {descriptions(i)}") Console.WriteLine($"Quantity: 1.00 Units") Console.WriteLine($"Unit Price: ${unitPrices(i):0.00}") Console.WriteLine($"Taxes: ${taxes(i):0.00}") Console.WriteLine($"Amount: ${amounts(i):0.00}") Console.WriteLine("-----------------------") Next i End Using End Sub End Class $vbLabelText $csharpLabel 正如您在下面看到的,IronOCR可以輕鬆地從收據中提取所需的文本。 輸出 提取整個收據 如果您想提取整個收據,可以在OCR收據中使用幾行代碼來輕鬆完成。 using IronOcr; using System; class WholeReceiptExtractor { static void Main() { var ocr = new IronTesseract(); using (var input = new OcrInput(@"r3.png")) { // Perform OCR on the entire receipt and print text output to console var result = ocr.Read(input); Console.WriteLine(result.Text); } } } using IronOcr; using System; class WholeReceiptExtractor { static void Main() { var ocr = new IronTesseract(); using (var input = new OcrInput(@"r3.png")) { // Perform OCR on the entire receipt and print text output to console var result = ocr.Read(input); Console.WriteLine(result.Text); } } } Imports IronOcr Imports System Friend Class WholeReceiptExtractor Shared Sub Main() Dim ocr = New IronTesseract() Using input = New OcrInput("r3.png") ' Perform OCR on the entire receipt and print text output to console Dim result = ocr.Read(input) Console.WriteLine(result.Text) End Using End Sub End Class $vbLabelText $csharpLabel 掃描收據API輸出 像IronOCR這樣的收據圖像掃描API提供了一個強大的軟體解決方案,用於自動化從收據中提取數據。通過利用先進的OCR技術,企業可以輕鬆從收據圖像或掃描中提取重要信息,包括商業供應商名稱、購買日期、逐項列出的清單、價格、稅金和總金額。 With support for multiple languages, currencies, receipt formats, and barcode support, businesses can streamline their receipt management processes, save time, gain insights into spending patterns, and make data-driven decisions. 作为一个多功能的OCR库和API,IronOCR为开发人员提供了所需的工具,精确有效地从各种来源提取文本,实现任务自动化,提高整体效率。 通过满足必要的前提条件并将IronOCR集成到他们的應用程式中,開發人員可以解鎖收據數據處理的優勢並提升工作流程。 有關IronOCR的更多信息,請訪問此許可頁面。 要了解如何使用計算機視覺查找文本,請訪問此計算機視覺操作指南。 有关收据OCR的更多教程,请访问以下OCR C#教程。 常見問題解答 我如何在 C# 中使用 OCR 自動化收據數據提取? 您可以在 C# 中使用 IronOCR 自動化收據資料擷取,從而以高精度從收據影像中擷取關鍵細節,如項目列、價格、稅項和總金額。 在 C# 中設置收據掃描專案的先決條件是什麼? 要在 C# 中設置收據掃描專案,您需要 Visual Studio、基本的 C# 編程知識以及在專案中安裝的 IronOCR 程式庫。 如何在 Visual Studio 中使用 NuGet 套件管理器安裝 OCR 程式庫? 開啟 Visual Studio,然後轉到工具 > NuGet 套件管理器 > 管理解決方案的 NuGet 套件,搜索 IronOCR 並在專案中安裝。 我可以使用 Visual Studio 命令行安裝 OCR 程式庫嗎? 是的,您可以通過打開 Visual Studio 中的套件管理器控制台,然後運行命令:Install-Package IronOcr來安裝 IronOCR。 如何使用 OCR 從整個收據中提取文本? 要從整個收據中提取文本,請使用 IronOCR 對整張收據圖像進行 OCR,然後使用 C# 代碼輸出提取的文本。 收據掃描 API 的好處是什麼? 像 IronOCR 這樣的收據掃描 API 自動化資料擷取,最小化手動錯誤,提升生產力,並為更好的商業決策提供支出模式洞察。 OCR 程式庫是否支持多語言和多貨幣? 是的,IronOCR 支援多語言、多貨幣和收據格式,這使其非常適合全球應用。 OCR 程式庫在從影像中擷取文本方面的準確性如何? IronOCR 通過使用先進的 OCR 演算法、計算機視覺和機器學習模型,甚至在挑戰性情況下也能保證高準確性。 可以用 OCR 從收據中提取哪些類型的數據? IronOCR 可以提取數據如項目條目、價格、稅款金額、總金額和其他收據細節。 自動化收據解析如何改善業務流程? 通過 IronOCR 自動化收據解析可以改善業務流程,從而減少手動輸入,允許準確的資料收集,並能夠做出數據驅動的決策。 Kannapat Udonpant 立即與工程團隊聊天 軟體工程師 在成為软件工程師之前,Kannapat 從日本北海道大學完成了環境資源博士學位。在追逐學位期间,Kannapat 還成為了生產工程系一部份——汽車机器人实验室的成員。2022 年,他利用他的 C# 技能加入 Iron Software 的工程團隊, 專注於 IronPDF。Kannapat 珍惜他的工作,因为他直接向编写大部分 IronPDF 使用的代码的开发者学习。除了同行学习,Kannapat 还喜欢在 Iron Software 工作的社交十环。当他不编写代码或文档时,Kannapat 通常在他的 PS5 上打游戏或重看《The Last of Us》。 相關文章 發表日期 9月 29, 2025 如何使用 IronOCR 建立 .NET OCR SDK 使用 IronOCR 的 .NET SDK 創建強大的 OCR 解決方案。簡單的 API,企業功能,跨平台支持的文檔處理應用。 閱讀更多 發表日期 9月 29, 2025 如何在 C# GitHub 專案中整合 OCR OCR C# GitHub 教學:使用 IronOCR 在您的 GitHub 專案中實現文本識別。包括程式碼範例和版本控制技巧。 閱讀更多 更新日期 9月 4, 2025 如何將文檔處理記憶體減少 98%:IronOCR 的工程突破 IronOCR 2025.9 通過流式架構將 TIFF 處理記憶體減少 98%,消除崩潰並提高企業工作流程的速度。 閱讀更多 開發者的 OCR 自動化指南最佳用於發票處理的OCR更...
發表日期 9月 29, 2025 如何使用 IronOCR 建立 .NET OCR SDK 使用 IronOCR 的 .NET SDK 創建強大的 OCR 解決方案。簡單的 API,企業功能,跨平台支持的文檔處理應用。 閱讀更多
發表日期 9月 29, 2025 如何在 C# GitHub 專案中整合 OCR OCR C# GitHub 教學:使用 IronOCR 在您的 GitHub 專案中實現文本識別。包括程式碼範例和版本控制技巧。 閱讀更多
更新日期 9月 4, 2025 如何將文檔處理記憶體減少 98%:IronOCR 的工程突破 IronOCR 2025.9 通過流式架構將 TIFF 處理記憶體減少 98%,消除崩潰並提高企業工作流程的速度。 閱讀更多