高度な読み取りのためのOCR設定
IronOCR provides advanced scan reading methods such as ReadPassport, ReadLicensePlate, and ReadPhoto that go beyond standard OCR. これらのメソッドは IronOcr.Extensions.AdvancedScan パッケージによって提供されます。 To fine-tune how these methods process text, IronOCR exposes the TesseractConfiguration class, giving developers full control over character whitelisting, blacklisting, barcode detection, data table reading, and more.
This article covers the TesseractConfiguration properties available for advanced reading and practical examples for configuring OCR in real-world scenarios.
クイックスタート: OCR出力を文字ホワイトリストに制限する
Set WhiteListCharacters on TesseractConfiguration before calling Read. ホワイトリストに含まれていない文字はすべて結果から自動的に削除され、後処理なしでノイズが除去されます。
-
IronOCR をNuGetパッケージマネージャでインストール
PM > Install-Package IronOcr -
このコード スニペットをコピーして実行します。
var result = new IronTesseract() { Configuration = new TesseractConfiguration { WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- " } }.Read(new OcrInput("image.png")); Console.WriteLine(result.Text); -
実際の環境でテストするためにデプロイする
今日プロジェクトで IronOCR を使い始めましょう無料トライアル
高度な読み取りのためのOCRの設定方法
- NuGetからIronOCRをインストール
- IronOcr.Extensions.AdvancedScanパッケージをインストール
TesseractConfigurationのプロパティ、例えばWhiteListCharactersとReadBarCodesを設定しますOcrInputを使用して入力画像を読み込みます- 高度なメソッド
ReadPhoto、ReadLicensePlate、またはReadPassportを使用して画像を読み取ります
TesseractConfigurationプロパティ
The TesseractConfiguration class provides the following properties for customizing OCR behavior. These are set through IronTesseract.Configuration.
| プロパティ | タイプ | 翻訳内容 |
|---|---|---|
WhiteListCharacters |
文字列 | この文字列に含まれる文字のみがOCR出力で認識されます。他のすべての文字は除外されます。 |
BlackListCharacters |
文字列 | この文字列に含まれる文字は積極的に無視され、OCR出力から除去されます。 |
ReadBarCodes |
ブール | OCR処理中にドキュメント内のバーコードを検出するかどうかを有効/無効にします。 |
ReadDataTables |
ブール | Tesseractを使用してドキュメント内のテーブル構造を検出するかどうかを有効/無効にします。 |
PageSegmentationMode |
TesseractPageSegmentationMode | Tesseractが入力画像をどのようにセグメント化するかを決定します。オプションにはAutoOsd、Auto、SingleBlock、SingleLine、SingleWordなどがあります。 |
RenderSearchablePdf |
ブール | 有効にすると、OCR出力は見えないテキスト層を持つ検索可能なPDFとして保存できます。 |
RenderHocr |
ブール | 有効にすると、OCR出力にさらなる処理またはエクスポートのためのhOCRデータが含まれます。 |
TesseractVariables |
Dictionary<文字列, object> | Provides direct access to low-level Tesseract configuration variables for fine-grained control. |
The TesseractVariables dictionary goes further still, exposing hundreds of underlying Tesseract engine parameters for cases where the high-level properties are not sufficient.
以下の例では、文字ホワイトリスト化から始めて、各プロパティグループについて説明します。
ナンバープレートのためのキャラクターホワイトリストの設定
A common use case for WhiteListCharacters is restricting OCR output to only the characters that can appear on a license plate: uppercase letters, digits, hyphens, and spaces. 予想される文字セット外のものをエンジンに無視させることによってノイズを除去し、精度を向上させます。
入力
The following vehicle registration record contains a mix of uppercase text, lowercase text, special symbols (@, $, #, |, ~, ^, *), and punctuation.
BlackListCharacters supplements the whitelist by actively excluding known noise symbols like `, ~, @, #, $, %, &, and *.
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading.cs
using IronOcr;
// Initialize the Tesseract OCR engine
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
// Whitelist only characters that appear on license plates
WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ",
// Blacklist common noise characters
BlackListCharacters = "`~@#$%&*",
};
var ocrInput = new OcrInput();
// Load the input image
ocrInput.LoadImage("advanced-input.png");
// Perform OCR on the input image with ReadPhoto method
var results = ocr.ReadPhoto(ocrInput);
// Print the filtered text result to the console
Console.WriteLine(results.Text);
Imports IronOcr
' Initialize the Tesseract OCR engine
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
' Whitelist only characters that appear on license plates
.WhiteListCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ",
' Blacklist common noise characters
.BlackListCharacters = "`~@#$%&*"
}
Dim ocrInput As New OcrInput()
' Load the input image
ocrInput.LoadImage("advanced-input.png")
' Perform OCR on the input image with ReadPhoto method
Dim results = ocr.ReadPhoto(ocrInput)
' Print the filtered text result to the console
Console.WriteLine(results.Text)
出力
結果にホワイトリストフィルタリングが明確に見えます:
- "Plate: ABC-1234" は "P ABC-1234" になります。 小文字の単語 "late:" は省略され、プレート番号は正確に保持されます。
- "VIN: 1HGBH41JXMN109186" は "VIN 1HGBH41JXMN109186" になります。 コロンは省略されますが、大文字のVINと完全な番号は保持されます。
- "Owner: john.doe@email.com" は "O" になります。 メール全体の小文字と句読点が削除されます。
-地域: CA-90210 | Zone #5" は "R CA-90210 Z 5" になります。 パイプ (
|) and hash (#) are removed, while the uppercase letters and numbers survive. - *"Fee: $125.00 + tax" は "F 12500"** になります。 ドル記号、小数点、プラス記号、および小文字の "tax" はすべて削除されます。
- "Ref: ~record_v2^final" は "R 2" になります。 The tilde (
~), underscore, caret (^), and all lowercase characters are stripped.
The same WhiteListCharacters and BlackListCharacters approach works for any document type, not just license plates. 次のセクションでは、読み取り処理を拡張して、同じパスでバーコードとテーブル構造を検出する方法を示します。
バーコードとデータテーブルの読み取りを設定
IronOCRは、テキストと一緒にドキュメント内のバーコードおよび構造化テーブルを検出できます。 These features are controlled through TesseractConfiguration:
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
// Enable barcode detection within documents
ReadBarCodes = true,
// Enable table structure detection
ReadDataTables = true,
};
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
// Enable barcode detection within documents
ReadBarCodes = true,
// Enable table structure detection
ReadDataTables = true,
};
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.ReadBarCodes = True,
.ReadDataTables = True
}
- ReadBarCodes: When set to
true, IronOCR scans the document for barcodes in addition to text. Set tofalseto skip barcode detection and speed up processing when barcodes are not expected. - ReadDataTables: When set to
true, Tesseract attempts to detect and preserve table structures in the document. これは請求書、レポート、その他の表形式のドキュメントに役立ちます。
These options can be combined with WhiteListCharacters and BlackListCharacters for precise control over what is extracted from complex documents.
フィルタリングと検出は抽出対象を制御するものであり、レイアウトの解釈は別の問題である。 The next section covers how to select the right PageSegmentationMode for the document type.
ページセグメンテーションモードの制御
PageSegmentationMode tells Tesseract how to segment the input image before recognition. 特定のレイアウトに対して誤ったモードを選択すると、エンジンがテキストを誤って読み取ったり、完全にスキップしたりする原因となります。
| モード | 使用例 |
|---|---|
AutoOsd |
自動レイアウト分析と方向とスクリプト検出 |
Auto |
OSDなしの自動レイアウト分析(デフォルト) |
SingleColumn |
画像が単一のテキスト列であると仮定します |
SingleBlock |
画像が単一の均一なテキストブロックであると仮定します |
SingleLine |
画像が単一のテキスト行であると仮定します |
SparseText |
任意の順序で可能な限り多くのテキストを発見します |
For a label or banner that contains a single line, SingleLine eliminates multi-block analysis and improves both speed and accuracy.
入力
single-line-label.png is a narrow shipping label with exactly one line of bold Courier text: SHIPPING LABEL: TRK-2024-XR9-001.
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
PageSegmentationMode = TesseractPageSegmentationMode.SingleLine,
};
using OcrInput input = new OcrInput();
input.LoadImage("single-line-label.png");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
PageSegmentationMode = TesseractPageSegmentationMode.SingleLine,
};
using OcrInput input = new OcrInput();
input.LoadImage("single-line-label.png");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronOcr
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.PageSegmentationMode = TesseractPageSegmentationMode.SingleLine
}
Using input As New OcrInput()
input.LoadImage("single-line-label.png")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
For a scanned page with irregular text placement, SparseText recovers more content than Auto.
入力
receipt-scan.png is a Corner Market thermal receipt with four line items (coffee, muffin, juice, granola bar), a dashed separator, subtotal, tax, and total. これは、固定ブロック分割では水平方向の異なる位置にあるエントリが欠落してしまうタイプのレイアウトです。
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
PageSegmentationMode = TesseractPageSegmentationMode.SparseText,
};
using OcrInput input = new OcrInput();
input.LoadImage("receipt-scan.png");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
PageSegmentationMode = TesseractPageSegmentationMode.SparseText,
};
using OcrInput input = new OcrInput();
input.LoadImage("receipt-scan.png");
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronTesseract
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.PageSegmentationMode = TesseractPageSegmentationMode.SparseText
}
Using input As New OcrInput()
input.LoadImage("receipt-scan.png")
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
ドキュメントの種類に合わせてレイアウト分割を調整したら、次のステップは後続処理のための出力フォーマットを制御することです。
検索可能なPDFおよびhOCR出力を生成
RenderSearchablePdf and RenderHocr control the output formats that IronOCR produces alongside the plain text result.
RenderSearchablePdf embeds an invisible text layer over the original image, producing a PDF where users can search and copy text while the scanned image remains visible. これはドキュメントアーカイブワークフローの標準出力形式です。
入力
scanned-document.pdf is a single-page business letter from IronOCR Solutions Ltd. (dated 15 March 2024, reference DOC-2024-OCR-0315). The result is saved as searchable-output.pdf.
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
RenderSearchablePdf = true,
};
using OcrInput input = new OcrInput();
input.LoadPdf("scanned-document.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable-output.pdf");
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
RenderSearchablePdf = true,
};
using OcrInput input = new OcrInput();
input.LoadPdf("scanned-document.pdf");
OcrResult result = ocr.Read(input);
result.SaveAsSearchablePdf("searchable-output.pdf");
Imports IronOcr
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.RenderSearchablePdf = True
}
Using input As New OcrInput()
input.LoadPdf("scanned-document.pdf")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsSearchablePdf("searchable-output.pdf")
End Using
出力
出力は入力と見た目は全く同じですが、非表示のテキストレイヤーを含むPDFファイルです。 Open searchable-output.pdf and use Ctrl+F to verify that the embedded text is searchable and copyable.
RenderHocr produces an hOCR document, an HTML file that encodes the text content together with bounding box coordinates for every word. これは、例えば墨消しエンジンや文書レイアウト分析など、下流のツールで単語の正確な位置決めが必要な場合に役立ちます。
入力
document-page.png is a document page with the heading "Quarterly Summary Q1 2024" and two paragraphs of financial data covering revenue, operating costs, and growth drivers. The result is saved as output.html.
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
RenderHocr = true,
};
using OcrInput input = new OcrInput();
input.LoadImage("document-page.png");
OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("output.html");
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
RenderHocr = true,
};
using OcrInput input = new OcrInput();
input.LoadImage("document-page.png");
OcrResult result = ocr.Read(input);
result.SaveAsHocrFile("output.html");
Imports IronOcr
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.RenderHocr = True
}
Using input As New OcrInput()
input.LoadImage("document-page.png")
Dim result As OcrResult = ocr.Read(input)
result.SaveAsHocrFile("output.html")
End Using
出力
output.html encodes each recognized word with its bounding box coordinates. ファイルをブラウザで開いてhOCR構造を検査するか、レイアウト解析や墨消しのために下流のツールに渡してください。
すべての3つの出力形式(プレーンテキスト、検索可能なPDF、およびhOCR)を単一の読み取り呼び出しから取得する必要がある場合、両方のフラグを同時に有効にすることができます。
これらの出力フラグは、ラテン文字以外の文字体系を含む、読み込まれる言語に関係なく機能します。次のセクションでは、日本語テキストに文字フィルタリングを適用する方法を示します。
国際文書向けUnicode文字フィルタリング
For international documents in Chinese, Japanese, or Korean, the WhiteListCharacters and BlackListCharacters properties work with Unicode characters. これにより、日本語でひらがなとカタカナのみのスクリプトに出力を制限することが可能になります。
入力
文書には、タイトル (テスト)、濁点の異体字 (プ、デ) を含むひらがなとカタカナの混合日本語文、ブラックリストに登録されたノイズ記号 (★、■) と漢字 (価格) を含む価格行、およびブラックリストに登録された別の記号 (§)、追加の漢字 (購入)、追加の濁点の異体字 (プ、デ)、および基本カタカナ (メモ、アール) を含むメモ行が含まれています。 ホワイトリストでは、基本ひらがな、基本カタカナ、数字、および一般的な日本語の句読点のみが通過します。 3つの騒音シンボルは明確にブラックリストに登録されている。
The Unicode character ranges for Hiragana and Katakana are passed as 文字列 literals in WhiteListCharacters, with the noise symbols listed in BlackListCharacters.
:path=/static-assets/ocr/content-code-examples/how-to/ocr-configurations-for-advanced-reading-jp.cs
using IronOcr;
using System.IO;
IronTesseract ocr = new IronTesseract();
ocr.Configuration = new TesseractConfiguration
{
// Whitelist only Hiragana, Katakana, numbers, and common Japanese punctuation
WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" +
"アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" +
"0123456789、。?!()¥ー",
// Blacklist common noise/symbols you want to ignore
BlackListCharacters = "★■§",
};
var ocrInput = new OcrInput();
// Load Japanese input image
ocrInput.LoadImage("jp.png");
// Perform OCR on the input image with ReadPhoto method
var results = ocr.ReadPhoto(ocrInput);
// Write the text result directly to a file named "output.txt"
File.WriteAllText("output.txt", results.Text);
// You can add this line to confirm the file was saved:
Console.WriteLine("OCR results saved to output.txt");
Imports IronOcr
Imports System.IO
Dim ocr As New IronTesseract()
ocr.Configuration = New TesseractConfiguration With {
.WhiteListCharacters = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん" &
"アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲン" &
"0123456789、。?!()¥ー",
.BlackListCharacters = "★■§"
}
Dim ocrInput As New OcrInput()
' Load Japanese input image
ocrInput.LoadImage("jp.png")
' Perform OCR on the input image with ReadPhoto method
Dim results = ocr.ReadPhoto(ocrInput)
' Write the text result directly to a file named "output.txt"
File.WriteAllText("output.txt", results.Text)
' You can add this line to confirm the file was saved:
Console.WriteLine("OCR results saved to output.txt")
出力
フィルタリングされた出力全体は、 jp-output.txtというテキストファイルとして入手できます。
ホワイトリストには基本的なひらがなとカタカナの文字のみが含まれているため、プ(pu)やデ(de)などの派生的な有声記号は除外されます。 価格(price)や購入(purchase)などの漢字も、ホワイトリストに登録された文字セットに含まれていないため除外されます。 Blacklisted symbols like ★, ■, and § are actively removed regardless of the whitelist.
次はどこへ行くべきでしょうか?
高度な読解シナリオ向けにIronOCRを設定する方法が理解できたので、以下を試してみてください。
パスポートやナンバープレートなどの特定の種類の書類を読み取る
- スタンドアロンのOCRユースケースとしてのバーコードおよびQRコードの読み取り
- 処理結果からhOCRおよび検索可能なPDFをエクスポートする
本番環境で使用する場合は、ライセンスを取得することを忘れないでください。
よくある質問
IronOCRにおけるTesseractConfigurationとは何ですか?
IronOCRのTesseractConfigurationを使用すると、ユーザーはOCR設定をカスタマイズでき、文字のホワイトリスト、BarCode読み取り、多言語サポートなどの高度な読み取り機能を利用できます。
IronOCRで文字のホワイトリストを設定するにはどうすればよいですか?
IronOCRでは、TesseractConfigurationを使用して文字のホワイトリストを設定できます。これにより、OCRエンジンが認識すべき文字を指定することができ、ナンバープレートの読み取りなどのタスクに役立ちます。
IronOCRはBARCODEやデータ表を読み取ることができますか?
はい、IronOCRは、TesseractConfigurationプロパティの特定の設定を調整することで、BarCodeやデータテーブルを読み取るように構成でき、正確なOCRデータ抽出が可能です。
IronOCRは、中国語、日本語、韓国語などの国際言語に対応していますか?
IronOCRは、多言語対応のTesseractConfigurationオプションを通じて、中国語、日本語、韓国語を含む国際言語をサポートしています。
IronOCRで高度なOCR設定を使用するメリットは何ですか?
IronOCRの高度なOCR設定を活用することで、より正確かつ効率的なテキスト認識が可能となり、言語固有のテキスト認識や構造化データの抽出といった特殊なタスクに対応できます。
特定のOCRタスクに合わせてIronOCRを最適化することは可能ですか?
はい、IronOCRは、文字のホワイトリスト設定やBARCODE・表の認識機能の有効化といった設定を行うことで、特定のOCRタスク向けに最適化でき、対象となるアプリケーションでのパフォーマンスを向上させることができます。
IronOCRで多言語サポートを有効にするにはどうすればよいですか?
IronOCRで多言語対応を有効にするには、TesseractConfigurationの言語設定を調整することで、OCRエンジンが複数の言語のテキストを認識できるようにします。
文字のホワイトリストとは何ですか?また、IronOCRではどのように使用されますか?
IronOCRの文字ホワイトリストは、OCRエンジンが認識するように設定された特定の文字のリストであり、数字や特定のテキストパターンの読み取りなど、特定のタスクに最適です。
IronOCRは構造化データ形式の読み取りに使用できますか?
はい、IronOCRはBARCODEや表などの構造化データ形式を読み取り、処理するように設定可能です。これにより、様々なデータ抽出ニーズに対応する多機能なOCR機能を提供します。
IronOCRでは、高度なテキスト認識のためにどのような設定が利用できますか?
IronOCRは、文字のホワイトリスト、多言語対応、BarCode認識などの設定機能を提供し、特定の要件に合わせた高度なテキスト認識機能を強化します。

