IronOCR 操作指南 結果信心 如何使用 IronOCR 獲得 C# OCR 閱讀信心。 Curtis Chau 更新:2026年1月10日 下載 IronOCR NuGet 下載 DLL 下載 Windows 安裝程式 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronOCR 的讀取置信度表示 OCR 系統對識別文字準確性的肯定程度,其值從 0 到 100 不等,分數越高表示可靠性越高 - 可透過任何 OcrResult 物件上的 Confidence 屬性存取。 OCR(光學字元辨識)的讀取置信度是指 OCR 系統對影像或文件中辨識出的文字的準確性所賦予的確定性或可靠性等級。 它是衡量 OCR 系統對識別文本正確性的信心程度的指標。 在處理 掃描的文件、照片或任何文字品質可能有差異的影像時,這項指標變得特別重要。 置信度分數越高,表示辨識結果的準確度越有把握;而信賴度分數越低,表示辨識結果的可靠性可能較低。 瞭解這些信心等級有助於開發人員在應用程式中實作適當的驗證邏輯和錯誤處理。 <! -- --> <!--說明:說明程式碼概念的圖表或截圖 --> 快速入門:一行掌握 OCR 讀取技巧 使用 IronTesseract 的 Read 方法與圖像檔案路徑,然後訪問返回的 OcrResult 上的 Confidence 屬性,以查看 IronOCR 對其文字辨識的確定程度。 這是開始評估 OCR 輸出精確度的簡單可靠方法。 立即開始使用 NuGet 建立 PDF 檔案: 使用 NuGet 套件管理器安裝 IronOCR PM > Install-Package IronOcr 複製並運行這段程式碼。 double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence; 部署到您的生產環境進行測試 立即開始在您的專案中使用 IronOCR,免費試用! 免費試用30天 ### 最小工作流程(5 個步驟) 下載 C# 庫以存取讀取置信度 准备目标图像和 PDF 文档 Access the `Confidence` property of the OCR result 檢索頁面、段落、行、字和字符的信心 Check the `Choices` property for alternative word choices 如何獲得閱讀 C# 的信心? 對輸入影像執行 OCR 後,文字的置信度會儲存在Confidence屬性中。 使用"using"語句可以在使用後自動釋放物件。 分別使用OcrImageInput和OcrPdfInput類別添加影像和 PDF 等文件。 Read 方法將返回一個 OcrResult 物件,可存取 Confidence 屬性。 :path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-confidence.cs using IronOcr; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add image using var imageInput = new OcrImageInput("sample.tiff"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Get confidence level double confidence = ocrResult.Confidence; Imports IronOcr ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Add image Private imageInput = New OcrImageInput("sample.tiff") ' Perform OCR Private ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Get confidence level Private confidence As Double = ocrResult.Confidence $vbLabelText $csharpLabel 返回的置信度值範圍從 0 到 100,其中: 90-100:信心十足 - 文本高度可靠 80-89:信心良好 - 文字大致準確,但有少許不確定性 70-79:中度信心 - 文字可能包含一些錯誤 低於 70:置信度低 - 應檢閱或重新處理文字 如何獲得不同層級的信心? 您不僅可以獲得整個文件的置信度,還可以存取每一頁、每一段、每一行、每一個單字和每個字元的置信度。 此外,您還可以獲得區塊的置信度,該區塊表示一個或多個緊密相鄰的段落的集合。 <! -- --> <!--說明:說明程式碼概念的圖表或截圖 --> :path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-confidence-level.cs // Get page confidence level double pageConfidence = ocrResult.Pages[0].Confidence; // Get paragraph confidence level double paragraphConfidence = ocrResult.Paragraphs[0].Confidence; // Get line confidence level double lineConfidence = ocrResult.Lines[0].Confidence; // Get word confidence level double wordConfidence = ocrResult.Words[0].Confidence; // Get character confidence level double characterConfidence = ocrResult.Characters[0].Confidence; // Get block confidence level double blockConfidence = ocrResult.Blocks[0].Confidence; ' Get page confidence level Dim pageConfidence As Double = ocrResult.Pages(0).Confidence ' Get paragraph confidence level Dim paragraphConfidence As Double = ocrResult.Paragraphs(0).Confidence ' Get line confidence level Dim lineConfidence As Double = ocrResult.Lines(0).Confidence ' Get word confidence level Dim wordConfidence As Double = ocrResult.Words(0).Confidence ' Get character confidence level Dim characterConfidence As Double = ocrResult.Characters(0).Confidence ' Get block confidence level Dim blockConfidence As Double = ocrResult.Blocks(0).Confidence $vbLabelText $csharpLabel 實用範例:依可信度篩選 當處理不同品質的文件時,例如 低品質掃描,您可以使用置信分數來篩選結果: using IronOcr; using System.Linq; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Configure for better accuracy ocrTesseract.Configuration.ReadBarCodes = false; ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd; // Add image using var imageInput = new OcrImageInput("invoice.png"); // Apply filters to improve quality imageInput.Deskew(); imageInput.DeNoise(); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Filter words with confidence above 85% var highConfidenceWords = ocrResult.Words .Where(word => word.Confidence >= 85) .Select(word => word.Text) .ToList(); // Process only high-confidence text string reliableText = string.Join(" ", highConfidenceWords); Console.WriteLine($"High confidence text: {reliableText}"); // Flag low-confidence words for manual review var lowConfidenceWords = ocrResult.Words .Where(word => word.Confidence < 85) .Select(word => new { word.Text, word.Confidence }) .ToList(); foreach (var word in lowConfidenceWords) { Console.WriteLine($"Review needed: '{word.Text}' (Confidence: {word.Confidence:F2}%)"); } using IronOcr; using System.Linq; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Configure for better accuracy ocrTesseract.Configuration.ReadBarCodes = false; ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd; // Add image using var imageInput = new OcrImageInput("invoice.png"); // Apply filters to improve quality imageInput.Deskew(); imageInput.DeNoise(); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Filter words with confidence above 85% var highConfidenceWords = ocrResult.Words .Where(word => word.Confidence >= 85) .Select(word => word.Text) .ToList(); // Process only high-confidence text string reliableText = string.Join(" ", highConfidenceWords); Console.WriteLine($"High confidence text: {reliableText}"); // Flag low-confidence words for manual review var lowConfidenceWords = ocrResult.Words .Where(word => word.Confidence < 85) .Select(word => new { word.Text, word.Confidence }) .ToList(); foreach (var word in lowConfidenceWords) { Console.WriteLine($"Review needed: '{word.Text}' (Confidence: {word.Confidence:F2}%)"); } Imports IronOcr Imports System.Linq ' Instantiate IronTesseract Dim ocrTesseract As New IronTesseract() ' Configure for better accuracy ocrTesseract.Configuration.ReadBarCodes = False ocrTesseract.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd ' Add image Using imageInput As New OcrImageInput("invoice.png") ' Apply filters to improve quality imageInput.Deskew() imageInput.DeNoise() ' Perform OCR Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Filter words with confidence above 85% Dim highConfidenceWords = ocrResult.Words _ .Where(Function(word) word.Confidence >= 85) _ .Select(Function(word) word.Text) _ .ToList() ' Process only high-confidence text Dim reliableText As String = String.Join(" ", highConfidenceWords) Console.WriteLine($"High confidence text: {reliableText}") ' Flag low-confidence words for manual review Dim lowConfidenceWords = ocrResult.Words _ .Where(Function(word) word.Confidence < 85) _ .Select(Function(word) New With {Key .Text = word.Text, Key .Confidence = word.Confidence}) _ .ToList() For Each word In lowConfidenceWords Console.WriteLine($"Review needed: '{word.Text}' (Confidence: {word.Confidence:F2}%)") Next End Using $vbLabelText $csharpLabel 什麼是 OCR 中的字元選擇? 除了置信水準之外,還有另一個有趣的屬性叫做選擇。 選項中包含備選詞語清單及其統計相關性。 此資訊允許使用者存取其他可能的角色。 此功能在使用 多種語言或專用字型時特別有用。 :path=/static-assets/ocr/content-code-examples/how-to/tesseract-result-confidence-get-choices.cs using IronOcr; using static IronOcr.OcrResult; // Instantiate IronTesseract IronTesseract ocrTesseract = new IronTesseract(); // Add image using var imageInput = new OcrImageInput("Potter.tiff"); // Perform OCR OcrResult ocrResult = ocrTesseract.Read(imageInput); // Get choices Choice[] choices = ocrResult.Characters[0].Choices; Imports IronOcr Imports IronOcr.OcrResult ' Instantiate IronTesseract Private ocrTesseract As New IronTesseract() ' Add image Private imageInput = New OcrImageInput("Potter.tiff") ' Perform OCR Private ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Get choices Private choices() As Choice = ocrResult.Characters(0).Choices $vbLabelText $csharpLabel 替代字元選擇有何幫助? 替代字元的選擇可提供多種好處: 1.模糊解析:當'O"和"0"或"l"和"1'等字元混淆時 2.字體變化:風格化或裝飾性字型的不同詮釋 3.品質問題:處理退化文字時的多種可能性 4.語言背景:基於語言規則的替代詮釋 使用字元選擇工作 以下是一個綜合範例,示範如何使用字元選擇來提高精確度: using IronOcr; using System; using System.Linq; using static IronOcr.OcrResult; // Configure IronTesseract for detailed results IronTesseract ocrTesseract = new IronTesseract(); // Process image with potential ambiguities using var imageInput = new OcrImageInput("ambiguous_text.png"); OcrResult ocrResult = ocrTesseract.Read(imageInput); // Analyze character choices for each word foreach (var word in ocrResult.Words) { Console.WriteLine($"\nWord: '{word.Text}' (Confidence: {word.Confidence:F2}%)"); // Check each character in the word foreach (var character in word.Characters) { if (character.Choices != null && character.Choices.Length > 1) { Console.WriteLine($" Character '{character.Text}' has alternatives:"); // Display all choices sorted by confidence foreach (var choice in character.Choices.OrderByDescending(c => c.Confidence)) { Console.WriteLine($" - '{choice.Text}': {choice.Confidence:F2}%"); } } } } using IronOcr; using System; using System.Linq; using static IronOcr.OcrResult; // Configure IronTesseract for detailed results IronTesseract ocrTesseract = new IronTesseract(); // Process image with potential ambiguities using var imageInput = new OcrImageInput("ambiguous_text.png"); OcrResult ocrResult = ocrTesseract.Read(imageInput); // Analyze character choices for each word foreach (var word in ocrResult.Words) { Console.WriteLine($"\nWord: '{word.Text}' (Confidence: {word.Confidence:F2}%)"); // Check each character in the word foreach (var character in word.Characters) { if (character.Choices != null && character.Choices.Length > 1) { Console.WriteLine($" Character '{character.Text}' has alternatives:"); // Display all choices sorted by confidence foreach (var choice in character.Choices.OrderByDescending(c => c.Confidence)) { Console.WriteLine($" - '{choice.Text}': {choice.Confidence:F2}%"); } } } } Imports IronOcr Imports System Imports System.Linq Imports IronOcr.OcrResult ' Configure IronTesseract for detailed results Dim ocrTesseract As New IronTesseract() ' Process image with potential ambiguities Using imageInput As New OcrImageInput("ambiguous_text.png") Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput) ' Analyze character choices for each word For Each word In ocrResult.Words Console.WriteLine(vbCrLf & $"Word: '{word.Text}' (Confidence: {word.Confidence:F2}%)") ' Check each character in the word For Each character In word.Characters If character.Choices IsNot Nothing AndAlso character.Choices.Length > 1 Then Console.WriteLine($" Character '{character.Text}' has alternatives:") ' Display all choices sorted by confidence For Each choice In character.Choices.OrderByDescending(Function(c) c.Confidence) Console.WriteLine($" - '{choice.Text}': {choice.Confidence:F2}%") Next End If Next Next End Using $vbLabelText $csharpLabel 進階信心策略 在處理 專業文件如護照、牌照或MICR支票時,置信分數對於驗證變得非常重要: using IronOcr; public class DocumentValidator { private readonly IronTesseract ocr = new IronTesseract(); public bool ValidatePassportNumber(string imagePath, double minConfidence = 95.0) { using var input = new OcrImageInput(imagePath); // Configure for passport reading ocr.Configuration.ReadBarCodes = true; ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine; // Apply preprocessing input.Deskew(); input.Scale(200); // Upscale for better accuracy var result = ocr.Read(input); // Find passport number pattern var passportLine = result.Lines .Where(line => line.Text.Contains("P<") || IsPassportNumberFormat(line.Text)) .FirstOrDefault(); if (passportLine != null) { Console.WriteLine($"Passport line found: {passportLine.Text}"); Console.WriteLine($"Confidence: {passportLine.Confidence:F2}%"); // Only accept if confidence meets threshold return passportLine.Confidence >= minConfidence; } return false; } private bool IsPassportNumberFormat(string text) { // Simple passport number validation return System.Text.RegularExpressions.Regex.IsMatch(text, @"^[A-Z]\d{7,9}$"); } } using IronOcr; public class DocumentValidator { private readonly IronTesseract ocr = new IronTesseract(); public bool ValidatePassportNumber(string imagePath, double minConfidence = 95.0) { using var input = new OcrImageInput(imagePath); // Configure for passport reading ocr.Configuration.ReadBarCodes = true; ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine; // Apply preprocessing input.Deskew(); input.Scale(200); // Upscale for better accuracy var result = ocr.Read(input); // Find passport number pattern var passportLine = result.Lines .Where(line => line.Text.Contains("P<") || IsPassportNumberFormat(line.Text)) .FirstOrDefault(); if (passportLine != null) { Console.WriteLine($"Passport line found: {passportLine.Text}"); Console.WriteLine($"Confidence: {passportLine.Confidence:F2}%"); // Only accept if confidence meets threshold return passportLine.Confidence >= minConfidence; } return false; } private bool IsPassportNumberFormat(string text) { // Simple passport number validation return System.Text.RegularExpressions.Regex.IsMatch(text, @"^[A-Z]\d{7,9}$"); } } Imports IronOcr Public Class DocumentValidator Private ReadOnly ocr As New IronTesseract() Public Function ValidatePassportNumber(imagePath As String, Optional minConfidence As Double = 95.0) As Boolean Using input As New OcrImageInput(imagePath) ' Configure for passport reading ocr.Configuration.ReadBarCodes = True ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine ' Apply preprocessing input.Deskew() input.Scale(200) ' Upscale for better accuracy Dim result = ocr.Read(input) ' Find passport number pattern Dim passportLine = result.Lines _ .Where(Function(line) line.Text.Contains("P<") OrElse IsPassportNumberFormat(line.Text)) _ .FirstOrDefault() If passportLine IsNot Nothing Then Console.WriteLine($"Passport line found: {passportLine.Text}") Console.WriteLine($"Confidence: {passportLine.Confidence:F2}%") ' Only accept if confidence meets threshold Return passportLine.Confidence >= minConfidence End If Return False End Using End Function Private Function IsPassportNumberFormat(text As String) As Boolean ' Simple passport number validation Return System.Text.RegularExpressions.Regex.IsMatch(text, "^[A-Z]\d{7,9}$") End Function End Class $vbLabelText $csharpLabel 優化更好的信心。 若要獲得更高的置信度分數,請考慮使用 影像篩選器 和預處理技術: using IronOcr; // Create an optimized OCR workflow IronTesseract ocr = new IronTesseract(); using var input = new OcrImageInput("low_quality_scan.jpg"); // Apply multiple filters to improve confidence input.Deskew(); // Correct rotation input.DeNoise(); // Remove noise input.Sharpen(); // Enhance edges input.Dilate(); // Thicken text input.Scale(150); // Upscale for clarity // Configure for accuracy over speed ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; ocr.Configuration.EngineMode = TesseractEngineMode.TesseractOnly; var result = ocr.Read(input); Console.WriteLine($"Document confidence: {result.Confidence:F2}%"); // Generate confidence report var confidenceReport = result.Pages .Select((page, index) => new { PageNumber = index + 1, Confidence = page.Confidence, WordCount = page.Words.Length, LowConfidenceWords = page.Words.Count(w => w.Confidence < 80) }); foreach (var page in confidenceReport) { Console.WriteLine($"Page {page.PageNumber}: {page.Confidence:F2}% confidence"); Console.WriteLine($" Total words: {page.WordCount}"); Console.WriteLine($" Low confidence words: {page.LowConfidenceWords}"); } using IronOcr; // Create an optimized OCR workflow IronTesseract ocr = new IronTesseract(); using var input = new OcrImageInput("low_quality_scan.jpg"); // Apply multiple filters to improve confidence input.Deskew(); // Correct rotation input.DeNoise(); // Remove noise input.Sharpen(); // Enhance edges input.Dilate(); // Thicken text input.Scale(150); // Upscale for clarity // Configure for accuracy over speed ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5; ocr.Configuration.EngineMode = TesseractEngineMode.TesseractOnly; var result = ocr.Read(input); Console.WriteLine($"Document confidence: {result.Confidence:F2}%"); // Generate confidence report var confidenceReport = result.Pages .Select((page, index) => new { PageNumber = index + 1, Confidence = page.Confidence, WordCount = page.Words.Length, LowConfidenceWords = page.Words.Count(w => w.Confidence < 80) }); foreach (var page in confidenceReport) { Console.WriteLine($"Page {page.PageNumber}: {page.Confidence:F2}% confidence"); Console.WriteLine($" Total words: {page.WordCount}"); Console.WriteLine($" Low confidence words: {page.LowConfidenceWords}"); } Imports IronOcr ' Create an optimized OCR workflow Dim ocr As New IronTesseract() Using input As New OcrImageInput("low_quality_scan.jpg") ' Apply multiple filters to improve confidence input.Deskew() ' Correct rotation input.DeNoise() ' Remove noise input.Sharpen() ' Enhance edges input.Dilate() ' Thicken text input.Scale(150) ' Upscale for clarity ' Configure for accuracy over speed ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5 ocr.Configuration.EngineMode = TesseractEngineMode.TesseractOnly Dim result = ocr.Read(input) Console.WriteLine($"Document confidence: {result.Confidence:F2}%") ' Generate confidence report Dim confidenceReport = result.Pages _ .Select(Function(page, index) New With { .PageNumber = index + 1, .Confidence = page.Confidence, .WordCount = page.Words.Length, .LowConfidenceWords = page.Words.Count(Function(w) w.Confidence < 80) }) For Each page In confidenceReport Console.WriteLine($"Page {page.PageNumber}: {page.Confidence:F2}% confidence") Console.WriteLine($" Total words: {page.WordCount}") Console.WriteLine($" Low confidence words: {page.LowConfidenceWords}") Next End Using $vbLabelText $csharpLabel 摘要 要建立強大的文件處理應用程式,瞭解並運用 OCR 信心分數是不可或缺的。 透過利用 IronOCR 的置信屬性和字元選擇,開發人員可以在其 OCR 工作流程中實作智慧型驗證、錯誤處理和品質保證機制。 無論您是要處理 螢幕快照、表格,或是專門的文件,置信度分數都能提供所需的指標,以確保文字擷取的精確度。 常見問題解答 什麼是 OCR 信心,為什麼它很重要? OCR 置信度是一個從 0 到 100 的度量,表示 OCR 系統對文字辨識準確性的肯定程度。IronOCR 透過任何 OcrResult 物件上的 Confidence 屬性提供此度量,協助開發人員評估辨識文字的可靠性,尤其是在處理掃描文件、照片或文字品質不一的影像時。 如何在 C# 中快速檢查 OCR 的信心? 使用 IronOCR,您只需要一行程式碼就可以得到 OCR 的信心值: double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence; 這會回傳一個 0-100 之間的信心分數,表示 IronOCR 對於文字辨識的肯定程度。 不同的置信度分數範圍代表什麼意思? IronOCR 信心分數表示:90-100 (優) 表示文字高度可靠;80-89 (良) 表示文字大致準確,但有輕微的不確定性;70-79 (中) 表示文字可能包含一些錯誤;低於 70 (低) 表示文字應該重新檢閱或處理。 如何存取不同文字元素的置信度? IronOCR 可讓您擷取多重粒度的置信度 - 頁面、段落、行、字詞和個別字元。執行 OCR 之後,您可以透過 OcrResult 物件結構存取各層級的置信度屬性。 我可以得到有信心分數的替代詞建議嗎? 是的,IronOCR 提供了一個「選擇」(Choices)屬性,可提供其他的字詞選擇以及它們的置信度分數。當 OCR 引擎識別出同一文字的多種可能解釋時,此功能會有所幫助,讓您可以實作智慧型驗證邏輯。 如何在我的應用程式中實作信心驗證? 使用 IronOCR 的 Read 方法後,檢查 OcrResult 的 Confidence 屬性。根據置信度臨界值實施條件邏輯 - 例如,自動接受 90 分以上的結果,標記 70-90 分之間的結果以供審查,並重新處理或手動驗證 70 分以下的結果。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 審核人 Jeffrey T. Fritz 首席計畫經理 - .NET 社群團隊 Jeff 也是 .NET 和 Visual Studio 團隊的首席計畫經理。他是 .NET Conf 虛擬會議系列的執行製作人,並主持「Fritz and Friends」開發人直播串流,每週播出兩次,與觀眾一起討論技術和編寫程式碼。Jeff 為 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP Summit 等大型 Microsoft 開發人員活動撰寫工作坊、簡報和規劃內容。 準備好開始了嗎? Nuget 下載 5,384,824 | 版本: 2026.2 剛剛發布 免費 NuGet 下載 總下載量:5,384,824 查看許可證