特定のドキュメントを読む方法
標準テキスト文書、ナンバープレート、パスポート、写真などの特定の文書を正確に読み取ることは、一般的な単一の方法では非常に困難です。 これらの課題は、各文書タイプの多様な形式、レイアウト、内容、および画像の品質、歪み、専門的な内容の変動から生じます。 さらに、文書の種類が広がると、コンテキストの理解を達成し、パフォーマンスと効率のバランスを取ることがますます複雑になります。
IronOCRは、標準のテキストドキュメント、ナンバープレート、パスポート、および写真などの特定のドキュメントに対して、最適な精度とパフォーマンスを実現するための特定のOCR方法を導入します。
IronOCRを始めましょう
今日から無料トライアルでIronOCRをあなたのプロジェクトで使い始めましょう。
特定のドキュメントを読む方法
パッケージについて
メソッドReadLicensePlate
、ReadPassport
、ReadPhoto
、およびReadScreenShot
は、基本的なIronOCRパッケージへの拡張メソッドであり、IronOcr.Extensions.AdvancedScanパッケージのインストールが必要です。 現在、この拡張機能はWindowsでのみ利用可能です。
メソッドはブラックリストやホワイトリストなどの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パッケージのインストールが必要です。 現在、この拡張機能はWindowsでのみ利用可能です。
ナンバープレートを読む例
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].FrameNumber;
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).FrameNumber
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)