IRONSOFTWAREHOME

如何使用IronOCR獲取C# OCR讀取信心水準

Curtis Chau
Curtis Chau
Updated: 2026年6月4日

IronOCR的讀取信心水準表示OCR系統對已識別文字準確性的確定程度,範圍從0到100,分數越高表示可靠性越高——可以通過任何OcrResult屬性存取。

在OCR(光學字元識別)中,讀取信心水準指的是OCR系統對圖像或文件中已識別文字的準確性所賦予的確定性或可靠性水平。 這是衡量OCR系統對已識別文字是否正確的信心水準。 這個指標在處理掃描文件照片或任何文字質量可能不同的圖像時顯得尤為重要。

高信心得分表示識別的準確性很高,而低信心得分則表明識別可能不太可靠。 了解這些信心水準有助於開發者在應用程式中實現適當的驗證邏輯和錯誤處理。

快速入門:在一行中獲取OCR讀取信心水準

使用Confidence屬性,以查看IronOCR對其文字識別的確定性。 這是一個簡單可靠的方式來開始評估OCR輸出準確性。

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2複製並運行這段程式碼片段。

    double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence;
    C#
  3. 3部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronOCR,透過免費試用
    arrow pointer

如何在C#中獲取讀取信心水準?

在對輸入圖像進行OCR後,文字的信心水準被儲存在Confidence屬性中。 使用'using'語句來自動釋放用過的物件。 分別使用OcrPdfInput類新增圖像和PDF文件。 Read方法將返回一個OcrResult物件,允許存取Confidence屬性。

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;

返回的信心值範圍從0到100,其中:

  • 90-100:優秀的信心水準 - 文字非常可靠
  • 80-89:良好的信心水準 - 文字通常準確,僅有少許不確定
  • 70-79:中等信心水準 - 文字可能包含一些錯誤
  • 70以下:低信心水準 - 應該檢查或重新處理文字

如何在不同級別獲取信心水準?

您不僅可以檢索整個文件的信心水準,還可以存取每個頁面、段落、行、單詞和字元的信心水準。 此外,您還可以獲取塊的信心水準,塊表示一個或多個段落的緊密集合。

// 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;

實用範例:按信心水準過濾

在處理品質不同的文件(例如低品質掃描件)時,您可以使用信心得分來過濾結果:

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}%)");
}

OCR中的字元選擇是什麼?

除了信心水準外,還有另一個有趣的屬性叫Choices。 選擇包含替代單詞選擇的列表及其統計相關性。 此資訊允許使用者存取其他可能的字元。 此功能在處理多語言或專用字體時特別有用。

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;

替代字元選擇如何提供幫助?

替代字元選擇提供多項好處:

  1. 疑義解決:當'O'和'0'、'l'和'1'混淆時
  2. 字體變化:對於樣式化或裝飾性字體的不同解釋
  3. 品質問題:處理劣化文字時的多個可能性
  4. 語言上下文:基於語言規則的替代解釋
OCR字元選擇除錯視圖展示信心得分和'第八章'的文字識別結果

使用字元選擇

這是一個全面的範例,展示如何利用字元選擇來提高準確性:

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}%");
            }
        }
    }
}

高級信心策略

在處理專用文件(如護照車牌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;

// 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}");
}

總結

理解並利用OCR信心水準是構建強健的文件處理應用程式的關鍵。 通過利用IronOCR的信心屬性和字元選擇,開發者可以在OCR工作流程中實現智能驗證、錯誤處理和品質保證機制。 無論您是否在處理截圖表格或專用文件,信心得分提供了必要的指標來確保準確的文字提取。

常見問題

什麼是 OCR 信心及其重要性?

OCR 信心是一種從 0 到 100 的衡量標準,表示 OCR 系統對文字識別準確性的確定程度。IronOCR 透過 OcrResult 物件上的 Confidence 屬性提供此指標,幫助開發人員評估識別文字的可靠性,特別是在處理掃描文件、照片或文字品質不均的圖像時。

如何在 C# 中快速檢查 OCR 信心?

using 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 物件結構存取每個層級的 Confidence 屬性。

我可以獲得帶有信心評分的替代單詞建議嗎?

是的,IronOCR 提供一個 Choices 屬性,提供替代單詞選擇及其信心評分。當 OCR 引擎識別相同文字的多個可能解釋時,此功能有助於實現智能驗證邏輯。

如何在應用程式中實施基於信心的驗證?

在使用 IronOCR 的 Read 方法後,檢查 OcrResult 的 Confidence 屬性。基於信心水準設定條件邏輯——例如,自動接受高於 90 的結果,標記 70-90 之間的結果供審查,而對低於 70 的結果進行重新處理或手動驗證。

What are character choices in IronOCR?

Character choices in IronOCR refer to alternative word choices and their relevance metrics provided during OCR. This feature is useful for handling ambiguities and understanding potential character variations in the text.

How can character choices aid in text recognition?

Character choices help resolve ambiguities by offering alternative interpretations for similar-looking characters and words. This is particularly beneficial when dealing with font variations, degraded text, and multiple languages.

What preprocessing techniques improve IronOCR text accuracy?

Preprocessing techniques such as deskewing, denoising, sharpening, and scaling can significantly enhance text accuracy by improving image quality before executing OCR processes with IronOCR.

How does IronOCR handle low confidence recognition results?

IronOCR allows you to filter and flag low-confidence recognition results for review. You can identify words with confidence scores below a certain threshold and address uncertainties by using validation or reprocessing strategies.

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

Nuget Downloads 6,236,385版本:2026.9剛剛發布

立即獲取免費

立即獲取 30天試用金鑰

bullet_checked無需信用卡或註冊帳號
bullet_test在生產
環境中進行測試,且不顯示浮水印
bullet_calendar30 天全
功能產品
bullet_support試用期間提供 24/5 技術
支援
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立
C# PDF的NuGet程式庫
使用NuGet安裝

版本: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. 在解決方案資源管理器中,右鍵點擊參考,管理NuGet包
  2. 選擇瀏覽並搜尋"IronOCR"
  3. 選擇包並安裝
C# PDF DLL
下載 DLL

版本: 2026.9

這裡下載Windows安裝程式。

  1. 下載並解壓IronOCR至您的方案目錄下的~/Libs等位置
  2. 在Visual Studio解決方案資源管理器中,右鍵點擊參考。選擇瀏覽,"IronOCR.dll"

授權從$999

有問題嗎?聯絡我們的開發團隊。

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
獲取您的無義務諮詢
填寫以下表格或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
被全球數百萬工程師信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立