使用 IRONOCR 如何在 C# 教學中從發票中提取文本 Kannapat Udonpant 更新日期:8月 20, 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 如何使用Tesseract進行收據OCR 安裝使用Tesseract的C#庫進行收據OCR 探索功能豐富的C#庫,用於對收據執行OCR 使用Tesseract從收據中提取數據 在提取的文本結果中搜索特定數據 讀取輸入收據圖像上的條碼值 1. IronOCR,一個光學字符識別API IronOCR是一個OCR庫,可用於從圖像中識別文本數據,用於信息提取,包括收據OCR。 它是基於Tesseract OCR引擎構建的,該引擎被認為是目前可用的最準確的收據識別OCR引擎之一。 IronOCR可以從不同類型的文件中讀取關鍵信息,包括PNG、JPG、TIFF、JSON和PDF格式,並且可以識別多種語言的文本。 IronOCR的一個關鍵功能,使其特別適用於收據OCR,是它能夠自動檢測文字方向,即使圖像被旋轉或歪斜。 這對於收據上傳和數據提取的準確文本識別至關重要,因為收據通常包含大量信息,可能會折疊或皺摺,導致文本變形。 2. IronOCR 功能 C# OCR使用深度學習掃描和識別來自圖片、掃描文檔和PDF的文本。 .NET OCR支持超過125種全球語言。 IronOCR可以從多種文件格式的圖像中讀取文本,包括PNG、JPG、TIFF和PDF。 Text, structured data, JSON output, or searchable PDFs can be produced from extracted information. IronOCR支持.NET版本5、6和7(Core、Framework和Standard)。 IronOCR根據文本區域將輸入分成不同的圖像。 它使用計算機視覺來識別包含文本元素的區域。 3. 在Visual Studio中創建新項目 打開 Visual Studio 並轉到文件菜單。 選擇“新項目”,然後選擇控制台應用程式。 輸入專案名稱並在適當的文本框中選擇路徑。 然後,點擊創建按鈕。 選擇所需的.NET Framework,如下圖所示: 現在將生成控制台應用程式的項目結構。 完成後,會打開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來讀取收據上的條碼以及文本。 To read barcodes on receipts, you will need to use the BarcodeReader class in combination with the ReadBarCodes method. 這裡有一個讀取條碼的示例: 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 輸入 Image 輸出 Text IronOCR 為 C# 開發者提供目前我們所知的最先進的Tesseract API,可以在任何平台上使用。 上文文章解釋了如何在C#項目中安裝並使用IronOCR從收據中提取數據,並提供了示例代碼片段。 請閱讀從圖像中讀取文本教程。 IronOCR是Iron Suite的一部分,其中包含五個不同的.NET庫,用於操作文檔和圖像。 You can buy the entire Iron Suite for the price of just two IronOCR licenses. 在您的生產應用程序中試用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 可以處理包括 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 上打游戏或重看《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%,消除崩潰並提高企業工作流程的速度。 閱讀更多 如何在 C# 中對車牌進行 OCR (教學)如何在 C# 中從螢幕截圖中...
發表日期 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%,消除崩潰並提高企業工作流程的速度。 閱讀更多