C#でフィルターウィザードを使用してOCRを向上させる方法
IronOCRのフィルターウィザードは、対象画像ですべての前処理フィルターの組み合わせをテストし、最適なOCR設定を見つけます。最も高い信頼度スコアと、結果を再現するためのC#コードを返します。
OCR向けの画像の前処理は難しい作業です。複数のフィルターを組み合わせると認識精度を高められますが、適切な組み合わせを見つけるには試行錯誤が必要です。画像ごとに問題が異なるため、手作業でのテストには時間がかかります。特に、低品質のスキャン画像や、ノイズや歪みの程度が異なる画像を扱う場合に顕著です。
IronOCRのOcrInputFilterWizardはこの問題を解決します。フィルターウィザードは、OCRの信頼度と精度が最も高くなるよう、フィルターの組み合わせを自動で評価します。さまざまな設定を網羅的にテストし、最適な組み合わせをコードスニペットとして返すため、結果を簡単に再現できます。OcrInputクラスと連携し、画像にフィルターを簡単に適用できます。
このガイドでは、フィルターウィザードの動作と、使用するコードスニペットやパラメーターを紹介します。OCRワークフローをさらに最適化するには、画像品質補正のガイドをご覧ください。
クイックスタート:最適な画像フィルターチェーンの自動検出IronOCRのフィルターウィザードを使うと、前処理フィルターのすべての組み合わせをテストし、最良の結果を得られた設定をコードスニペットとして取得できます。1行のコードで、最も高い信頼度スコアと、類似画像に適用できるC#のフィルターチェーンが返ります。
-
1IronOCR を NuGet Package Manager でインストールします
-
2このコード スニペットをコピーして実行します。
string code = OcrInputFilterWizard.Run("image.png", out double confidence, new IronTesseract());Dim code As String = OcrInputFilterWizard.Run("image.png", confidence, New IronTesseract())Dim code As String = OcrInputFilterWizard.Run("image.png", confidence, New IronTesseract()) -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronOCRを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- フィルターウィザードを使用するためのC#ライブラリをダウンロードします。
IronTesseractエンジンをインスタンス化します。- 入力画像を
OcrInputFilterWizardに読み込みます。 Runでフィルターウィザードを実行し、信頼度などの出力を確認します。- 返されたコードを入力画像に適用し、結果を確認します。
フィルターウィザードはどのように動作しますか?
OcrInputFilterWizard.Runメソッドは、入力画像、結果の信頼度を受け取る出力パラメーター、Tesseractエンジンのインスタンスの3つを受け取ります。エンジンを細かく制御するには、Tesseractの詳細な設定をご覧ください。
前処理フィルターの組み合わせを複数テストし、信頼度スコアが最も高かった組み合わせを入力画像に適用します。この方法は、画像の向き補正など、複雑な前処理が必要な画像にも有効です。
フィルターウィザードには、プリセットや組み合わせ数の上限はありません。フィルターの組み合わせを網羅的にテストし、最も高い信頼度スコアを目指します。ウィザードの処理状況をリアルタイムで確認するには、進捗追跡を実装してください。
組み合わせのテストに使用できるフィルターは以下のとおりです。
input.Contrast()- 文字が読みやすくなるようにコントラストを調整しますinput.Sharpen()- 輪郭を強調しますinput.Binarize()- 白黒に変換しますinput.ToGrayScale()- カラー情報を除去しますinput.Invert()- 色を反転しますinput.Deskew()- 傾斜した文字を修正しますinput.Scale(...)- 最適な寸法にリサイズしますinput.DeNoise()- ピクセルノイズを除去しますinput.Despeckle()- 高度なノイズ除去を行いますinput.EnhanceResolution()- 低解像度の画像の解像度を高めますinput.Dilate(),input.Erode()- 文字の形状を調整します
画像フィルターに関するチュートリアルをご覧ください。 画像補正フィルターガイドで、追加の前処理技術を利用できます。
この詳細なテスト方法は処理時間を必要とします。大規模な操作には、マルチスレッドサポートを使用して、複数の画像を同時に処理してください。
テストにどの種類の画像を使用すべきですか?
この例では、フィルターウィザードの機能を示すために、人工ノイズの多いスクリーンショットを使用しています。 フィルターウィザードは、スキャンされた文書から文字を含む写真まで、さまざまな画像タイプを効果的に処理します。

テスト画像を選ぶ際は、以下の点を考慮してください。
- 画像解像度:通常、DPIが高い画像ほど結果が良くなります。 最適化のヒントについては、DPI設定に関するガイドをご覧ください。
- 文書タイプ: 異なる文書タイプには特定のフィルターの組み合わせが有効です。 身分証明書は、標準のテキスト文書とは異なる前処理が必要になる場合があります。
- 元画像の品質: フィルターウィザードは品質に問題のある画像にも有効ですが、可能であれば入手できる中で最も高品質な元画像を使用してください。
コードでフィルターウィザードを実行する方法
using IronOcr;
using System;
// Initialize the Tesseract engine
var ocr = new IronTesseract();
// 1. Pass the image path ("noise.png").
// 2. Pass an 'out' variable to store the best confidence score found.
// 3. Pass the tesseract instance to be used for testing.
string codeToRun = OcrInputFilterWizard.Run("noise.png", out double confidence, ocr);
// The 'confidence' variable is now populated with the highest score achieved.
Console.WriteLine($"Best Confidence Score: {confidence}");
// 'codeToRun' holds the exact C# code snippet that achieved this score.
// The returned string is the code you can use to filter similar images.
Console.WriteLine("Recommended Filter Code:");
Console.WriteLine(codeToRun);using IronOcr;
using System;
// Initialize the Tesseract engine
var ocr = new IronTesseract();
// 1. Pass the image path ("noise.png").
// 2. Pass an 'out' variable to store the best confidence score found.
// 3. Pass the tesseract instance to be used for testing.
string codeToRun = OcrInputFilterWizard.Run("noise.png", out double confidence, ocr);
// The 'confidence' variable is now populated with the highest score achieved.
Console.WriteLine($"Best Confidence Score: {confidence}");
// 'codeToRun' holds the exact C# code snippet that achieved this score.
// The returned string is the code you can use to filter similar images.
Console.WriteLine("Recommended Filter Code:");
Console.WriteLine(codeToRun);Imports IronOcr
Imports System
' Initialize the Tesseract engine
Dim ocr As New IronTesseract()
' 1. Pass the image path ("noise.png").
' 2. Pass an 'out' variable to store the best confidence score found.
' 3. Pass the tesseract instance to be used for testing.
Dim confidence As Double
Dim codeToRun As String = OcrInputFilterWizard.Run("noise.png", confidence, ocr)
' The 'confidence' variable is now populated with the highest score achieved.
Console.WriteLine($"Best Confidence Score: {confidence}")
' 'codeToRun' holds the exact C# code snippet that achieved this score.
' The returned string is the code you can use to filter similar images.
Console.WriteLine("Recommended Filter Code:")
Console.WriteLine(codeToRun)Imports IronOcr
Imports System
' Initialize the Tesseract engine
Dim ocr As New IronTesseract()
' 1. Pass the image path ("noise.png").
' 2. Pass an 'out' variable to store the best confidence score found.
' 3. Pass the tesseract instance to be used for testing.
Dim confidence As Double
Dim codeToRun As String = OcrInputFilterWizard.Run("noise.png", confidence, ocr)
' The 'confidence' variable is now populated with the highest score achieved.
Console.WriteLine($"Best Confidence Score: {confidence}")
' 'codeToRun' holds the exact C# code snippet that achieved this score.
' The returned string is the code you can use to filter similar images.
Console.WriteLine("Recommended Filter Code:")
Console.WriteLine(codeToRun)フィルターウィザードは、さまざまな入力形式に対応しています。対応形式については、入力画像のガイドをご覧ください。PDFファイルも処理でき、動的に取得する画像はストリームから直接読み取れます。
バッチ処理には、次の応用例を参照してください。
/* :path=/static-assets/ocr/content-code-examples/how-to/filter-wizard-batch.cs */
using IronOcr;
using System;
using System.IO;
// Process multiple similar images
var ocr = new IronTesseract();
string[] imageFiles = Directory.GetFiles(@"C:\Images", "*.png");
// Run Filter Wizard on first image to discover optimal settings
string optimalCode = OcrInputFilterWizard.Run(imageFiles[0], out double baselineConfidence, ocr);
Console.WriteLine($"Baseline confidence: {baselineConfidence:P2}");
Console.WriteLine($"Optimal filter sequence discovered");
// Apply discovered filters to all images
foreach (string imagePath in imageFiles)
{
using (var input = new OcrImageInput(imagePath))
{
// Apply the filter sequence discovered by the wizard
// The actual filters would be applied here based on the wizard output
var result = ocr.Read(input);
Console.WriteLine($"Processed: {Path.GetFileName(imagePath)} - Confidence: {result.Confidence:P2}");
}
}/* :path=/static-assets/ocr/content-code-examples/how-to/filter-wizard-batch.cs */
using IronOcr;
using System;
using System.IO;
// Process multiple similar images
var ocr = new IronTesseract();
string[] imageFiles = Directory.GetFiles(@"C:\Images", "*.png");
// Run Filter Wizard on first image to discover optimal settings
string optimalCode = OcrInputFilterWizard.Run(imageFiles[0], out double baselineConfidence, ocr);
Console.WriteLine($"Baseline confidence: {baselineConfidence:P2}");
Console.WriteLine($"Optimal filter sequence discovered");
// Apply discovered filters to all images
foreach (string imagePath in imageFiles)
{
using (var input = new OcrImageInput(imagePath))
{
// Apply the filter sequence discovered by the wizard
// The actual filters would be applied here based on the wizard output
var result = ocr.Read(input);
Console.WriteLine($"Processed: {Path.GetFileName(imagePath)} - Confidence: {result.Confidence:P2}");
}
}Imports IronOcr
Imports System
Imports System.IO
' Process multiple similar images
Dim ocr As New IronTesseract()
Dim imageFiles As String() = Directory.GetFiles("C:\Images", "*.png")
' Run Filter Wizard on first image to discover optimal settings
Dim baselineConfidence As Double
Dim optimalCode As String = OcrInputFilterWizard.Run(imageFiles(0), baselineConfidence, ocr)
Console.WriteLine($"Baseline confidence: {baselineConfidence:P2}")
Console.WriteLine("Optimal filter sequence discovered")
' Apply discovered filters to all images
For Each imagePath As String In imageFiles
Using input As New OcrImageInput(imagePath)
' Apply the filter sequence discovered by the wizard
' The actual filters would be applied here based on the wizard output
Dim result = ocr.Read(input)
Console.WriteLine($"Processed: {Path.GetFileName(imagePath)} - Confidence: {result.Confidence:P2}")
End Using
NextImports IronOcr
Imports System
Imports System.IO
' Process multiple similar images
Dim ocr As New IronTesseract()
Dim imageFiles As String() = Directory.GetFiles("C:\Images", "*.png")
' Run Filter Wizard on first image to discover optimal settings
Dim baselineConfidence As Double
Dim optimalCode As String = OcrInputFilterWizard.Run(imageFiles(0), baselineConfidence, ocr)
Console.WriteLine($"Baseline confidence: {baselineConfidence:P2}")
Console.WriteLine("Optimal filter sequence discovered")
' Apply discovered filters to all images
For Each imagePath As String In imageFiles
Using input As New OcrImageInput(imagePath)
' Apply the filter sequence discovered by the wizard
' The actual filters would be applied here based on the wizard output
Dim result = ocr.Read(input)
Console.WriteLine($"Processed: {Path.GetFileName(imagePath)} - Confidence: {result.Confidence:P2}")
End Using
Nextフィルターウィザードはどのような結果を返しますか?

この画像に対してフィルターウィザードが得た最高の信頼度は65%です。信頼度スコアはOCRの精度を評価するための重要な指標です。詳しくは、結果の信頼度のガイドをご覧ください。
入力画像には大きな歪みと人工的なノイズがあり、認識が難しい画像でのフィルターウィザードの動作を確認できます。本番環境では、可能な限り高品質な元画像を使用してください。
生成されたコードスニペットには、以下の特長があります。
- 正確なフィルター順序:最適な結果のためには操作の順番が重要です
- メソッドチェーン:簡潔で読みやすく、実装が容易なコード
- パラメーターの推測が不要: 各フィルターは最良の結果が得られるように設定されています
推奨されたフィルターの組み合わせをどのように適用しますか?
フィルターウィザードを実行したら、出力されたコードスニペットを入力画像に適用し、結果と信頼度を確認してください。これにより、文書処理パイプラインで類似画像を扱う際にも結果を再現できます。
推奨されたコードをどのように実装しますか?
using IronOcr;
using System;
// Initialize the Tesseract engine
var ocrTesseract = new IronTesseract();
// Load the image into an OcrInput object
using (var input = new OcrImageInput("noise.png"))
{
// Apply the exact filter chain recommended by the Wizard's output
input.Invert();
input.DeNoise();
input.Contrast();
input.AdaptiveThreshold();
// Run OCR on the pre-processed image
OcrResult result = ocrTesseract.Read(input);
// Print the final result and confidence
Console.WriteLine($"Result: {result.Text}");
Console.WriteLine($"Confidence: {result.Confidence}");
}using IronOcr;
using System;
// Initialize the Tesseract engine
var ocrTesseract = new IronTesseract();
// Load the image into an OcrInput object
using (var input = new OcrImageInput("noise.png"))
{
// Apply the exact filter chain recommended by the Wizard's output
input.Invert();
input.DeNoise();
input.Contrast();
input.AdaptiveThreshold();
// Run OCR on the pre-processed image
OcrResult result = ocrTesseract.Read(input);
// Print the final result and confidence
Console.WriteLine($"Result: {result.Text}");
Console.WriteLine($"Confidence: {result.Confidence}");
}Imports IronOcr
Imports System
' Initialize the Tesseract engine
Dim ocrTesseract As New IronTesseract()
' Load the image into an OcrInput object
Using input As New OcrImageInput("noise.png")
' Apply the exact filter chain recommended by the Wizard's output
input.Invert()
input.DeNoise()
input.Contrast()
input.AdaptiveThreshold()
' Run OCR on the pre-processed image
Dim result As OcrResult = ocrTesseract.Read(input)
' Print the final result and confidence
Console.WriteLine($"Result: {result.Text}")
Console.WriteLine($"Confidence: {result.Confidence}")
End UsingImports IronOcr
Imports System
' Initialize the Tesseract engine
Dim ocrTesseract As New IronTesseract()
' Load the image into an OcrInput object
Using input As New OcrImageInput("noise.png")
' Apply the exact filter chain recommended by the Wizard's output
input.Invert()
input.DeNoise()
input.Contrast()
input.AdaptiveThreshold()
' Run OCR on the pre-processed image
Dim result As OcrResult = ocrTesseract.Read(input)
' Print the final result and confidence
Console.WriteLine($"Result: {result.Text}")
Console.WriteLine($"Confidence: {result.Confidence}")
End Usingフィルターを適用する順序は結果に大きく影響します。フィルターウィザードは使用するフィルターと最適な適用順序を決定するため、複雑な前処理にも役立ちます。
OCR処理をより細かく制御するには、エラー処理と検証の実装を検討してください。
/* :path=/static-assets/ocr/content-code-examples/how-to/filter-wizard-validation.cs */
using IronOcr;
using System;
var ocrEngine = new IronTesseract();
try
{
using (var input = new OcrImageInput(@"C:\Images\document.png"))
{
// Apply Filter Wizard recommended sequence
input.Invert();
input.DeNoise();
input.Contrast();
input.AdaptiveThreshold();
// Configure additional OCR settings
ocrEngine.Configuration.ReadBarCodes = false;
ocrEngine.Configuration.RenderSearchablePdf = true;
// Perform OCR with timeout protection
var result = ocrEngine.Read(input);
// Validate results
if (result.Confidence >= 0.6)
{
Console.WriteLine("OCR successful with high confidence");
// Process the extracted text
}
else
{
Console.WriteLine("Low confidence result - consider manual review");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"OCR processing error: {ex.Message}");
}/* :path=/static-assets/ocr/content-code-examples/how-to/filter-wizard-validation.cs */
using IronOcr;
using System;
var ocrEngine = new IronTesseract();
try
{
using (var input = new OcrImageInput(@"C:\Images\document.png"))
{
// Apply Filter Wizard recommended sequence
input.Invert();
input.DeNoise();
input.Contrast();
input.AdaptiveThreshold();
// Configure additional OCR settings
ocrEngine.Configuration.ReadBarCodes = false;
ocrEngine.Configuration.RenderSearchablePdf = true;
// Perform OCR with timeout protection
var result = ocrEngine.Read(input);
// Validate results
if (result.Confidence >= 0.6)
{
Console.WriteLine("OCR successful with high confidence");
// Process the extracted text
}
else
{
Console.WriteLine("Low confidence result - consider manual review");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"OCR processing error: {ex.Message}");
}Imports IronOcr
Imports System
Dim ocrEngine As New IronTesseract()
Try
Using input As New OcrImageInput("C:\Images\document.png")
' Apply Filter Wizard recommended sequence
input.Invert()
input.DeNoise()
input.Contrast()
input.AdaptiveThreshold()
' Configure additional OCR settings
ocrEngine.Configuration.ReadBarCodes = False
ocrEngine.Configuration.RenderSearchablePdf = True
' Perform OCR with timeout protection
Dim result = ocrEngine.Read(input)
' Validate results
If result.Confidence >= 0.6 Then
Console.WriteLine("OCR successful with high confidence")
' Process the extracted text
Else
Console.WriteLine("Low confidence result - consider manual review")
End If
End Using
Catch ex As Exception
Console.WriteLine($"OCR processing error: {ex.Message}")
End TryImports IronOcr
Imports System
Dim ocrEngine As New IronTesseract()
Try
Using input As New OcrImageInput("C:\Images\document.png")
' Apply Filter Wizard recommended sequence
input.Invert()
input.DeNoise()
input.Contrast()
input.AdaptiveThreshold()
' Configure additional OCR settings
ocrEngine.Configuration.ReadBarCodes = False
ocrEngine.Configuration.RenderSearchablePdf = True
' Perform OCR with timeout protection
Dim result = ocrEngine.Read(input)
' Validate results
If result.Confidence >= 0.6 Then
Console.WriteLine("OCR successful with high confidence")
' Process the extracted text
Else
Console.WriteLine("Low confidence result - consider manual review")
End If
End Using
Catch ex As Exception
Console.WriteLine($"OCR processing error: {ex.Message}")
End Tryフィルターを適用した後の最終的なOCR結果は何ですか?

画像に大きな歪みがあっても、IronOCRはテキストの大部分を抽出します。信頼度はフィルターウィザードの出力と一致します。OCR結果の扱いについて詳しくは、データ出力のガイドをご覧ください。
フィルターウィザードの実運用のヒント
フィルターウィザードを実運用で使用する際は、以下を参考にしてください。
- バッチ処理:代表サンプルでテストし、類似した画像にフィルターチェーンを適用します。
- パフォーマンスの最適化: フィルターウィザードは組み合わせを網羅的にテストするため、時間がかかります。OCR処理を高速化するには、高速OCR設定をご覧ください。
- カスタム言語サポート: 英語以外のテキストの認識精度を最適化するには、複数言語のサポートをご覧ください。
- API統合: 詳細なドキュメントは、APIリファレンスをご覧ください。
- 文書別最適化:特定の文書タイプには専門的なアプローチが有効です:
- フォーム用には、テーブルの読み取りを検討してください
- 内容が混在する文書では、バーコードの読み取りを有効にしてください
- 複数ページの文書については、TIFF処理を参照してください
- メモリ管理:
OcrInputオブジェクトをusingステートメントを使って適切に破棄してください。 - エラーの回復:低信頼度の結果にはフォールバック戦略を実装してください。 重要な文書については、手作業によるレビューを検討してください。
フィルターウィザードは、対象の画像に最適な前処理パイプラインを自動で見つけます。画像の前処理を手探りで決める必要がなくなり、アプリケーション全体で一貫して高品質のテキストを抽出できます。
よくある質問
IronOCR フィルタウィザードの主な機能は何ですか?
IronOCR フィルタウィザードは、最適な OCR 設定を見つけるために様々な画像前処理フィルタの組み合わせを自動的にテストし、最高の信頼スコアと効果的な結果のために必要な正確な C# コードを返します。
OCR 作業において前処理はなぜ必要ですか?
前処理は、ノイズを減らし、歪みを修正し、OCR プロセスに最適化することで、テキスト認識の精度を大幅に向上させるため、OCR 作業において重要です。
OcrInputFilterWizard.Run メソッドはどのように機能しますか?
OcrInputFilterWizard.Run メソッドは、Tesseract エンジンを使用して入力画像に対する複数の前処理フィルタの組み合わせを評価し、最高の信頼スコアと最良のフィルタ構成の C# コードを返します。
フィルタウィザードは低品質の画像を効果的に扱えますか?
はい、フィルタウィザードは、ノイズや歪みを含む低品質の画像を含むチャレンジングなシナリオに対応するように設計されており、OCR 精度を最大化するための最適なフィルタの組み合わせを見つけ出します。
IronOCR にはどのような種類の画像フィルタがありますか?
IronOCR には、コントラスト、シャープ、バイナライズ、グレースケール化、反転、デスクュー、スケール、ノイズ除去、デスペックル、解像度の向上、ダイレート、エロージョンなど、OCR パフォーマンスを向上させるためのさまざまなフィルタが含まれています。
推奨されるフィルタの組み合わせを C# でどのように適用できますか?
フィルタウィザードを実行した後、提供された C# コードスニペットを使用して推奨されるフィルタの組み合わせを適用できます。これには、最適な OCR 結果のために調整されたイメージ処理メソッドのシーケンスが含まれています。
フィルタウィザードのテスト画像を選択する際に考慮すべき要素は何ですか?
テスト画像を選択する際には、画像の解像度、文書の種類、ソースの品質などが、フィルタ評価プロセスと OCR パフォーマンスに影響を与える可能性があるため、考慮することが重要です。
大規模な操作のためにフィルタウィザードをどのように最適化できますか?
大規模な操作のためには、マルチスレッドを使用して複数の画像を同時に処理し、処理時間を短縮するために高速 OCR 構成などのパフォーマンス最適化を実装することを検討してください。
フィルタウィザードを使用するために推奨される高度な使用のヒントは何ですか?
高度なヒントには、バッチ処理、パフォーマンスの最適化、カスタム言語のサポート、API 統合、文書固有の最適化、メモリ管理、エラー回復戦略などが含まれます。
フィルタウィザードは異なるドキュメントタイプの処理に適してますか?
はい、フィルタウィザードは、フォーム、混合コンテンツ、多ページ文書などに適用される最適な前処理パイプラインを自動的に見つけることで、さまざまなドキュメントタイプの OCR 処理を最適化できます。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。