C#とIronOCRで特定文書の文字認識・テキスト抽出を行う方法
標準的なテキスト文書、ナンバープレート、パスポート、写真などの特定の文書から文字認識・テキスト抽出を一般的な単一の方法で正確に行うのは非常に困難です。 これらの課題は、各ドキュメント タイプの形式、レイアウト、コンテンツの多様性、および画像品質、歪み、特殊なコンテンツのばらつきに起因します。 さらに、ドキュメントの種類が広くなると、コンテキストの理解を実現し、パフォーマンスと効率性のバランスをとることがより複雑になります。
IronOCR は、標準のテキスト ドキュメント、ナンバー プレート、パスポート、写真などの特定のドキュメントに対して OCR を実行し、最適な精度とパフォーマンスを実現するための具体的な方法を導入します。
クイックスタート: パスポートを 1 行で読む
IronOCRのReadPassport拡張機能を使えば、最小限の設定でパスポートの主要な詳細情報をすべて抽出できます。たった1行のコードで( IronOCRとAdvancedScanがインストールされている場合)、氏名、パスポート番号、国名などの構造化された結果データを迅速かつ簡単に取得できます。
最小限のワークフロー(5ステップ)
- ナンバープレート、パスポート、写真を読み取るための C# ライブラリをダウンロードする
- OCRのための画像とPDFドキュメントを準備
- ナンバープレートを読み取るために`ReadLicensePlate`メソッドを設定する
- パスポートから情報を取得するために`ReadPassport`メソッドを設定します
- Leverage the `ReadPhoto` and `ReadScreenShot` methods to read images that contain hard-to-read text
パッケージについて
メソッド ReadPhoto、および ReadScreenShot は基本IronOCRパッケージの拡張メソッドであり、 IronOcr.Extensions.AdvancedScanパッケージがインストールされている必要があります。
これらのメソッドは、ブラックリストやホワイトリストなどのOCRエンジン設定に対応しています。ReadPassportメソッドを除くすべてのメソッドで、中国語、日本語、韓国語、ラテンアルファベットなど複数の言語がサポートされています。 各言語には追加の言語パッケージIronOcr.Languagesが必要であることに注意してください。
.NET Framework で詳細スキャンを使用するには、プロジェクトを x64 アーキテクチャで実行する必要があります。 これを実現するには、プロジェクト構成に移動し、"32 ビットを優先"オプションのチェックを外します。 詳細については、次のトラブルシューティング ガイドを参照してください:". NET Framework の高度なスキャン"。
ドキュメントの例を読む
ReadDocument 方式は、スキャンされた文書や大量のテキストを含む紙文書の写真に特化した堅牢な文書読み取り方式です。 PageSegmentationMode構成は、異なるレイアウトのテキスト ドキュメントを読み取る際に非常に重要です。
たとえば、 SingleBlock型とSparseText型では、テーブル レイアウトから多くの情報を取得できます。 これは、 SingleBlock ではテキストがブロックとして残っていると想定しているのに対し、 SparseText ではテキストがドキュメント全体に散らばっていると想定しているためです。
:path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-document.cs
using IronOcr;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
// Configure OCR engine
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock;
using var input = new OcrInput();
input.LoadPdf("Five.pdf");
// Perform OCR
OcrResult result = ocr.ReadDocument(input);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
' Configure OCR engine
ocr.Configuration.PageSegmentationMode = TesseractPageSegmentationMode.SingleBlock
Dim input = New OcrInput()
input.LoadPdf("Five.pdf")
' Perform OCR
Dim result As OcrResult = ocr.ReadDocument(input)
Console.WriteLine(result.Text)
以下のメソッドは基本 IronOCR パッケージの拡張メソッドであり、 IronOcr.Extensions.AdvancedScanパッケージがインストールされている必要があります。
ナンバープレートの読み取り例
ReadLicensePlate メソッドは、写真からナンバープレートを読み取るために最適化されています。 このメソッドから返される特別な情報はLicenseplateプロパティであり、これには提供されたドキュメント内のナンバー プレートの位置の情報が含まれます。
:path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-license-plate.cs
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("LicensePlate.jpeg");
// Perform OCR
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate coordinates
Rectangle rectangle = result.Licenseplate;
// Retrieve license plate value
string output = result.Text;
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("LicensePlate.jpeg")
' Perform OCR
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate coordinates
Dim rectangle As Rectangle = result.Licenseplate
' Retrieve license plate value
Dim output As String = result.Text
パスポートの例を読む
ReadPassport メソッドは読み取り用に最適化されており、機械可読領域 (MRZ) の内容をスキャンしてパスポート写真からパスポート情報を抽出します。 MRZ は、パスポート、ID カード、ビザなどの公式文書内で特別に定義されたゾーンです。 MRZ には通常、保有者の名前、生年月日、国籍、文書番号などの重要な個人情報が含まれています。 現在、この方法は英語のみをサポートしています。
:path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-passport.cs
using IronOcr;
using System;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPassport = new OcrInput();
inputPassport.LoadImage("Passport.jpg");
// Perform OCR
OcrPassportResult result = ocr.ReadPassport(inputPassport);
// Output passport information
Console.WriteLine(result.PassportInfo.GivenNames);
Console.WriteLine(result.PassportInfo.Country);
Console.WriteLine(result.PassportInfo.PassportNumber);
Console.WriteLine(result.PassportInfo.Surname);
Console.WriteLine(result.PassportInfo.DateOfBirth);
Console.WriteLine(result.PassportInfo.DateOfExpiry);
Imports IronOcr
Imports System
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPassport = New OcrInput()
inputPassport.LoadImage("Passport.jpg")
' Perform OCR
Dim result As OcrPassportResult = ocr.ReadPassport(inputPassport)
' Output passport information
Console.WriteLine(result.PassportInfo.GivenNames)
Console.WriteLine(result.PassportInfo.Country)
Console.WriteLine(result.PassportInfo.PassportNumber)
Console.WriteLine(result.PassportInfo.Surname)
Console.WriteLine(result.PassportInfo.DateOfBirth)
Console.WriteLine(result.PassportInfo.DateOfExpiry)
結果
書類にはパスポートの画像のみが含まれていることを確認してください。 ヘッダーとフッターのテキストによりメソッドが混乱し、予期しない出力が発生する可能性があります。
写真の例を読む
ReadPhoto メソッドは、読みにくいテキストを含む画像の読み取りに最適化されています。 このメソッドはTextRegionsプロパティを返します。このプロパティには、 Region 、 TextInRegion 、 FrameNumberなど、検出されたテキストに関する有用な情報が含まれています。
:path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-photo.cs
using IronOcr;
using IronSoftware.Drawing;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputPhoto = new OcrInput();
inputPhoto.LoadImageFrame("photo.tif", 2);
// Perform OCR
OcrPhotoResult result = ocr.ReadPhoto(inputPhoto);
// index number refer to region order in the page
int number = result.TextRegions[0].PageNumber;
string textinregion = result.TextRegions[0].TextInRegion;
Rectangle region = result.TextRegions[0].Region;
Imports IronOcr
Imports IronSoftware.Drawing
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputPhoto = New OcrInput()
inputPhoto.LoadImageFrame("photo.tif", 2)
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadPhoto(inputPhoto)
' index number refer to region order in the page
Dim number As Integer = result.TextRegions(0).PageNumber
Dim textinregion As String = result.TextRegions(0).TextInRegion
Dim region As Rectangle = result.TextRegions(0).Region
スクリーンショットの例を読む
ReadScreenShot メソッドは、読みにくいテキストを含むスクリーンショットの読み取りに最適化されています。 ReadPhoto メソッドと同様に、 TextRegionsプロパティも返します。
:path=/static-assets/ocr/content-code-examples/how-to/read-specific-document-screenshot.cs
}
using IronOcr;
using System;
using System.Linq;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputScreenshot = new OcrInput();
inputScreenshot.LoadImage("screenshot.png");
// Perform OCR
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);
// Output screenshoot information
Console.WriteLine(result.Text);
Console.WriteLine(result.TextRegions.First().Region.X);
Console.WriteLine(result.TextRegions.Last().Region.Width);
Console.WriteLine(result.Confidence);
}
Imports IronOcr
Imports System
Imports System.Linq
' Instantiate OCR engine
Private ocr = New IronTesseract()
Private inputScreenshot = New OcrInput()
inputScreenshot.LoadImage("screenshot.png")
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadScreenShot(inputScreenshot)
' Output screenshoot information
Console.WriteLine(result.Text)
Console.WriteLine(result.TextRegions.First().Region.X)
Console.WriteLine(result.TextRegions.Last().Region.Width)
Console.WriteLine(result.Confidence)
}
よくある質問
C# で OCR を使用してナンバープレートを読むにはどうすればよいですか?
IronOCR が提供する ReadLicensePlate メソッドを使用すると、写真からナンバープレートを正確に読み取ることができます。このメソッドは、ナンバープレートテキストとその位置情報を返します。
パスポート写真から情報を抽出する最良の方法は何ですか?
IronOCR の ReadPassport メソッドは、パスポート写真の機械可読領域(MRZ)をスキャンして、名前、生年月日、文書番号などの重要な情報を抽出することを目的としています。
IronOCR は読みづらいテキストが含まれる写真からテキストを読み取れますか?
はい、IronOCR の ReadPhoto メソッドは、読みづらいテキストのある画像を読むように最適化されており、検出されたテキストとその領域についての詳細データを提供します。
IronOCR を使用してスクリーンショットからテキストを読み取ることは可能ですか?
もちろん、IronOCR の ReadScreenShot メソッドは、スクリーンショットのテキスト処理に特化して最適化されており、詳細なテキスト領域情報を提供します。
複雑なレイアウトのドキュメントで OCR の精度を向上させるにはどうすればよいですか?
複雑なドキュメントレイアウトの OCR 精度を高めるためには、IronOCR の PageSegmentationMode を設定します。SingleBlock や SparseText などのオプションは、表形式のレイアウトからの情報抽出に特に有用です。
IronOCR の高度なスキャン機能が .NET Framework プロジェクトで動作しない場合、どうすればよいですか?
.NET Framework 上の IronOCR の高度なスキャン機能に関する問題を解決するには、プロジェクト設定で「32 ビット優先」オプションのチェックを外して、プロジェクトを x64 アーキテクチャで実行するように設定します。
IronOCR に言語サポートの制約はありますか?
IronOCR は、中国語、日本語、韓国語、ラテンアルファベットを含む複数の言語をサポートしています。ただし、ReadPassport メソッドは現在、英語の文書のみをサポートしています。
IronOCR の高度なスキャン機能を使用するにはどうすればよいですか?
IronOCR の高度なスキャン機能を使用するには、IronOcr.Extensions.AdvancedScan パッケージが必要で、これは Windows でのみ利用可能です。

