更新済み 2025年2月17日
共有:

特定のドキュメントを読む方法

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

作成者: Chaknith Bin

標準テキスト文書、ナンバープレート、パスポート、写真などの特定の文書を正確に読み取ることは、一般的な単一の方法では非常に困難です。 これらの課題は、各文書タイプの多様な形式、レイアウト、内容、および画像の品質、歪み、専門的な内容の変動から生じます。 さらに、文書の種類が広がると、コンテキストの理解を達成し、パフォーマンスと効率のバランスを取ることがますます複雑になります。

IronOCRは、標準のテキストドキュメント、ナンバープレート、パスポート、および写真などの特定のドキュメントに対して、最適な精度とパフォーマンスを実現するための特定のOCR方法を導入します。

IronOCRを始めましょう

今日から無料トライアルでIronOCRをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer



パッケージについて

メソッドReadLicensePlateReadPassportReadPhoto、およびReadScreenShotは、基本的なIronOCRパッケージへの拡張メソッドであり、IronOcr.Extensions.AdvancedScanパッケージのインストールが必要です。 現在、この拡張機能はWindowsでのみ利用可能です。

メソッドはブラックリストやホワイトリストなどのOCRエンジンの構成を使用します。中国語、日本語、韓国語、ラテンアルファベットを含む複数の言語が、ReadPassportメソッドを除くすべてのメソッドでサポートされています。 各言語には追加の言語パッケージが必要です。IronOcr.Languages

高度なスキャンを .NET Framework で使用するには、プロジェクトを x64アーキテクチャで実行する必要があります。 プロジェクトの設定に移動し、「32ビットを優先」のオプションのチェックを外してください。 次のトラブルシューティングガイドで詳細をご確認ください:.NET Framework における高度なスキャン

ドキュメント読み取り例

ReadDocument メソッドは、スキャンされたドキュメントや多くの文章を含む紙のドキュメントの写真を専門とする堅牢なドキュメント読み取りメソッドです。 PageSegmentationMode設定は、さまざまなレイアウトを持つテキストドキュメントを読む際に非常に重要です。 たとえば、SingleBlockSparseText タイプは、テーブルレイアウトから多くの情報を取得することができます。 これは、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)
$vbLabelText   $csharpLabel

以下のメソッドは、基本的な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
$vbLabelText   $csharpLabel

パスポートの例を読む

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)
$vbLabelText   $csharpLabel

結果

パスポートを読む

ドキュメントにはパスポートの画像のみが含まれるようにしてください。 ヘッダーとフッターのテキストはメソッドを混乱させ、予期しない出力を引き起こす可能性があります。

写真の例を読む

ReadPhoto メソッドは、読みにくいテキストを含む画像を読み取るために最適化されています。 このメソッドはTextRegionsプロパティを返します。これは、RegionTextInRegionFrameNumberなどの検出されたテキストに関する有用な情報を含んでいます。

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

スクリーンショットを読み取る例

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)
$vbLabelText   $csharpLabel
チャクニット・ビン

チャクニット・ビン

ソフトウェアエンジニア

 LinkedIn

ChaknithはIronXLとIronBarcodeで作業しています。彼はC#と.NETに深い専門知識を持ち、ソフトウェアの改善と顧客サポートを支援しています。ユーザーとの対話から得た彼の洞察は、より良い製品、文書、および全体的な体験に貢献しています。