使用 IRONOCR 如何在 C# 教學中從發票中提取文本 Kannapat Udonpant 更新:8月 20, 2025 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 如何在 Tesseract 中進行 OCR 收據識別 1.使用 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。 可以從擷取的資訊產生文字、結構化資料、JSON 輸出或可搜尋的 PDF 。 IronOCR 支援 .NET 版本 5、6 和 7(核心、框架和標準)。 IronOCR 根據文字區域將輸入內容分割成不同的圖片。 它利用電腦視覺技術來識別包含文字元素的區域。 3.在 Visual Studio 中建立新專案 開啟 Visual Studio,然後前往"檔案"選單。 選擇"新建專案",然後選擇"控制台應用程式"。 在適當的文字方塊中輸入專案名稱並選擇路徑。 然後按一下建立按鈕。 選擇所需的 .NET Framework 版本,如下圖所示: 在 Visual Studio 中建立新項目 現在將產生控制台應用程式的專案結構。 完成後,它將打開 Program.cs 文件,您可以在其中編寫和執行原始程式碼。 !由 Visual Studio 新專案精靈產生的 Program.cs 文件 4. 安裝 IronOCR 在 Visual Studio 中,您可以輕鬆地將 IronOCR 整合到您的 C# 專案中。 IronOCR 提供了多種與 C# .NET 專案整合的方式。 在這裡,我們將討論其中一種方法:使用 NuGet 套件管理器安裝 IronOCR。 在 Visual Studio 中,前往"工具" > "NuGet 套件管理員" > "套件管理員控制台"。 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的一部分,Iron Suite 包含五個不同的 .NET 庫,用於處理文件和圖像。 您只需支付兩份IronOCR 授權的價格,即可購買整個 Iron Suite 套件。 免費試用IronOCR,即可在您的生產應用程式中使用。 常見問題解答 如何使用 IronOCR 在 C# 中對收據影像執行 OCR? 您可以使用 IronOCR 在收據影像上執行 OCR,方法是將該影像載入 OcrInput 類別,並呼叫 Read 方法來擷取文字資料,例如分項清單和總金額。 與 Tesseract 相比,使用 IronOCR 處理發票有哪些優勢? IronOCR 提供更高的精確度,支援超過 125 種語言,並包含自動文字方向偵測和深度學習功能等特色。它也更容易使用 NuGet Package Manager 與 C# 專案整合。 如何將 IronOCR 整合到 Visual Studio 專案中? 要將 IronOCR 整合到 Visual Studio 專案中,請使用 NuGet 套件管理員。導覽到工具 > NuGet 套件管理員 > 套件管理員控制台,然後執行 Install-Package IronOcr 以將函式庫新增至您的專案。 IronOCR 可以在收據 OCR 中處理多種語言嗎? 是的,IronOCR 可以處理多種語言,支援超過 125 種全球語言,因此非常適合處理包含多種語言文字的收據。 IronOCR 如何提高收據中的文字辨識準確度? IronOCR 透過深度學習、自動偵測文字方向,以及使用 OcrInput 類別優化影像以獲得更好的 OCR 結果等功能,提高文字辨識的準確度。 是否可以使用 IronOCR 從收據中提取分項清單? 是的,IronOCR 可用於從收據中擷取分項清單,方法是在執行 OCR 之後,處理文字資料並透過模式匹配識別行列項目。 IronOCR 如何處理收據上的 BarCode 讀取? 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 上打游戏或重看《The Last of Us》。 相關文章 發表日期 12月 18, 2025 C# 讀取 PDF 表單欄位:以程式設計方式擷取表單數據 學習如何在C#中使用IronPDF讀取PDF表單字段。從可填寫PDF中提取文本、複選框、下拉列表等的簡單代碼示例。 閱讀更多 發表日期 12月 18, 2025 C# 從 PDF 擷取影像:完整開發者指南 學習如何使用IronPDF強大的方法從C#中的PDF文檔中提取圖像。完整指南中包含了.NET開發人員的代碼示例。 閱讀更多 發表日期 12月 18, 2025 C# 將 PDF 轉換為圖像:完整開發者指南 學習如何使用IronPDF將PDF文檔轉換為C#中的圖像。詳盡指南中提供了JPG、PNG和TIFF轉換的代碼示例。 閱讀更多 如何在 C# 中對車牌進行 OCR (教學)如何在 C# 中從螢幕截圖中...
發表日期 12月 18, 2025 C# 讀取 PDF 表單欄位:以程式設計方式擷取表單數據 學習如何在C#中使用IronPDF讀取PDF表單字段。從可填寫PDF中提取文本、複選框、下拉列表等的簡單代碼示例。 閱讀更多
發表日期 12月 18, 2025 C# 從 PDF 擷取影像:完整開發者指南 學習如何使用IronPDF強大的方法從C#中的PDF文檔中提取圖像。完整指南中包含了.NET開發人員的代碼示例。 閱讀更多
發表日期 12月 18, 2025 C# 將 PDF 轉換為圖像:完整開發者指南 學習如何使用IronPDF將PDF文檔轉換為C#中的圖像。詳盡指南中提供了JPG、PNG和TIFF轉換的代碼示例。 閱讀更多