C#でのTesseract OCR信頼値の使用方法 | IronOCR

どのようにIronOCRでC# OCRの読み取りに自信をつけるか

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronOCRの読み取り信頼度は、OCRシステムが認識したテキストの正確さをどの程度確信しているかを示すもので、0から100までの値があり、スコアが高いほど信頼性が高いことを意味します。

OCR (光学式文字認識) における読み取り信頼性とは、OCR システムが画像または文書内で認識したテキストの正確さに割り当てる確実性または信頼性のレベルを指します。 これは、OCR システムが認識したテキストが正しいとどの程度確信しているかを示す指標です。 スキャンされたドキュメント写真、またはテキストの品質が変化する可能性のある画像を処理する場合、このメトリックは特に重要になります。

信頼スコアが高い場合、認識が正確であることの確実性が高いことを示し、信頼スコアが低い場合、認識の信頼性が低い可能性があることを示します。 これらの信頼レベルを理解することは、開発者がアプリケーションに適切な検証ロジックとエラー処理を実装するのに役立ちます。

クイックスタート: 1行でOCRの読み取り信頼性を実現

IronTesseractのReadメソッドに画像ファイルのパスを指定し、返されたOcrResultConfidenceプロパティにアクセスすることで、IronOCRのテキスト認識の確かさを確認することができます。 OCR出力の精度を評価し始めるには、シンプルで信頼できる方法です。

Nuget Icon今すぐ NuGet で PDF を作成してみましょう:

  1. NuGet パッケージ マネージャーを使用して IronOCR をインストールします

    PM > Install-Package IronOcr

  2. このコード スニペットをコピーして実行します。

    double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence;
  3. 実際の環境でテストするためにデプロイする

    今すぐ無料トライアルでプロジェクトに IronOCR を使い始めましょう
    arrow pointer


C#に自信を持つにはどうすればよいですか?

入力画像に対して OCR を実行した後、テキストの信頼度レベルがConfidenceプロパティに保存されます。 "using"ステートメントを利用して、使用後にオブジェクトを自動的に破棄します。 画像や PDF などのドキュメントは、それぞれOcrImageInputクラスとOcrPdfInputクラスを使用して追加します。 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;
$vbLabelText   $csharpLabel

返される信頼度の範囲は0~100です:

  • 90-100:優れた信頼性 - テキストの信頼性が高い。
  • 80-89:良好な信頼性 - テキストは、わずかな不確実性はあるが、概ね正確である。
  • 70-79:信頼度は中程度 - テキストには多少の誤りが含まれる可能性があります。
  • 70未満:信頼度が低い - テキストを見直すか、再処理する必要があります。

さまざまなレベルで信頼を得るにはどうすればよいですか?

文書全体の信頼度レベルを取得できるだけでなく、各ページ、段落、行、単語、文字の信頼度レベルにアクセスすることもできます。 さらに、近接して配置された 1 つ以上の段落の集合を表すブロックの信頼度を取得することもできます。

: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;
$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}%)");
}
$vbLabelText   $csharpLabel

OCRにおける文字の選択とは

信頼度の他に、 "Choices"と呼ばれる興味深いプロパティがもう 1 つあります。 選択肢には、代替単語の選択肢とその統計的関連性のリストが含まれます。 この情報により、ユーザーは他の可能な文字にアクセスできるようになります。 この機能は、複数の言語や特殊なフォントを扱う場合に特に役立ちます。

: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;
$vbLabelText   $csharpLabel

代替文字の選択はどのように役立ちますか?

代替文字の選択にはいくつかの利点があります:

1.曖昧さ解決:'O'と'0'、'l'と'1'のような文字が混同される場合。 2.フォントのバリエーション:様式化されたフォントや装飾的なフォントに対するさまざまな解釈 3.品質の問題:劣化したテキストを扱うときの複数の可能性 4.言語コンテキスト:言語ルールに基づく代替解釈

Choices related to 代替文字の選択はどのように役立ちますか?

文字の選択を扱う

以下は、精度を向上させるための文字選択肢の使用方法を示す包括的な例です:

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

まとめ

OCR信頼度スコアを理解し活用することは、堅牢な文書処理アプリケーションを構築するために不可欠です。 IronOCRの信頼性プロパティと文字の選択肢を活用することで、開発者はOCRワークフローにインテリジェントな検証、エラー処理、品質保証メカニズムを実装することができます。 スクリーンショット、または特殊なドキュメントを処理しているかどうかにかかわらず、信頼度スコアは、正確なテキスト抽出を保証するために必要なメトリックを提供します。

よくある質問

OCRの信頼性とは何ですか?

OCR信頼度とは、OCRシステムがテキスト認識の正確さをどの程度確信しているかを示す0から100までの指標です。IronOCRはOcrResultオブジェクトのConfidenceプロパティを通してこの指標を提供し、開発者が認識したテキストの信頼性を評価するのに役立ちます。

C#でOCRの信頼性をすばやく確認するにはどうすればよいですか?

IronOCRを使えば、たった1行のコードでOCRの信頼度を得ることができます: double confidence = new IronOcr.IronTesseract().Read("input.png").Confidence; これはIronOCRがテキスト認識についてどの程度確信しているかを示す0-100の信頼度スコアを返します。

異なる信頼度スコアの範囲は何を意味しますか?

IronOCRの信頼度スコアは以下の通りです:90-100 (Excellent)は、テキストの信頼性が高いことを意味します。80-89 (Good)は、わずかな不確実性はあるものの、テキストが概ね正確であることを意味します。70-79 (Moderate)は、テキストに若干の誤りが含まれている可能性があることを意味します。

さまざまなテキスト要素の信頼レベルにアクセスするにはどうすればよいですか?

IronOCRは、ページ、段落、行、単語、個々の文字など、複数の粒度で信頼度を取得することができます。OCRを実行した後、OcrResultオブジェクト構造を通して各レベルのConfidenceプロパティにアクセスすることができます。

信頼度スコア付きの代替単語候補を入手できますか?

はい、IronOCRは選択肢を信頼度スコアとともに提供するChoicesプロパティを提供しています。この機能は、OCRエンジンが同じテキストについて複数の解釈の可能性を識別した場合に役立ち、スマートな検証ロジックを実装することができます。

アプリケーションに信頼ベースの検証を実装するにはどうすればよいですか?

IronOCRのReadメソッドを使用した後、OcrResultのConfidenceプロパティをチェックしてください。信頼度のしきい値に基づいた条件ロジックを実装する - 例えば、90以上の結果は自動的に受け入れ、70-90の結果はレビューのためにフラグを立て、70以下の結果は再処理または手動で検証する。

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

レビュー済み
Jeff Fritz
Jeffrey T. Fritz
プリンシパルプログラムマネージャー - .NETコミュニティチーム
Jeffはまた、.NETとVisual Studioチームのプリンシパルプログラムマネージャーです。彼は.NET Conf仮想会議シリーズのエグゼクティブプロデューサーであり、週に二回放送される開発者向けライブストリーム『Fritz and Friends』のホストを務め、テクノロジーについて話すことや視聴者と一緒にコードを書くことをしています。Jeffはワークショップ、プレゼンテーション、およびMicrosoft Build、Microsoft Ignite、.NET Conf、Microsoft MVPサミットを含む最大のMicrosoft開発者イベントのコンテンツを企画しています。
準備はできましたか?
Nuget ダウンロード 5,299,091 | バージョン: 2025.12 リリース