C#でコンピュータ ビジョンを使用してテキスト抽出・文字認識を行う方法
IronOCRはOpenCVコンピュータ・ビジョンを使って、OCR処理の前に画像中のテキスト領域を自動的に検出します。 これは、Tesseractの文字認識を識別されたテキスト領域のみに集中させることで、ノイズの多いテキスト、複数の領域、ゆがんだテキストに対する精度を向上させ、画像全体を処理する場合と比較してテキスト抽出結果を大幅に向上させます。
クイックスタート: 主要なテキスト領域の検出と OCR
この例では、即時テキスト抽出を示します。画像を読み込み、IronOCR の Computer Vision を使用して、FindTextRegion() でメインテキスト領域を自動検出し、次に .Read(...) を実行して 1 行のテキストを抽出します。
- C#でナンバープレートをOCRする方法(チュートリアル)
- C#で請求書からテキストを取得する方法チュートリアル
- C#でスクリーンショットからテキストをOCRで取得する方法
- C#で字幕をOCR処理する方法(チュートリアル)
最小限のワークフロー(5ステップ)
- コンピューター ビジョンで OCR を使用するための C# ライブラリをダウンロードする
- `FindTextRegion`メソッドを利用してテキスト領域を自動検出する
- `StampCropRectangleAndSaveAs`メソッドで検出されたテキスト領域を確認します
- コンピュータービジョンを使用して、 `FindMultipleTextRegions`メソッドで元の画像をテキスト領域に基づいて画像に分割します。
- `GetTextRegions`メソッドを使用して、テキストが検出されたトリミング領域のリストを取得します。
NuGetパッケージを使ってIronOcr.ComputerVisionをインストールするには?
IronOCR でコンピューター ビジョンを実行する OpenCV メソッドは、通常の IronOCR NuGet パッケージで表示されます。 詳細なインストールガイドについては、NuGetインストールガイドを参照してください。
なぜIronOCRは別のコンピュータ・ビジョン・パッケージを必要とするのですか?
これらの方法を使用するには、ソリューションに IronOcr.ComputerVision のNuGetインストールが必要です。 インストールされていない場合はダウンロードするように求められます。 コンピュータ ビジョン機能は、ナンバープレート認識やパスポート スキャン機能で使用されている技術と同様に、テキスト検出精度を大幅に向上させる OpenCV アルゴリズムを活用しています。
どのプラットフォーム固有のパッケージをインストールすべきですか?
- Windows:
IronOcr.ComputerVision.Windows- Windowsセットアップガイドをご覧ください - Linux:
IronOcr.ComputerVision.Linux- Linuxインストールチュートリアルを確認してください - macOS:
IronOcr.ComputerVision.MacOS- macOSのセットアップ手順を確認してください - macOS ARM:
IronOcr.ComputerVision.MacOS.ARM
パッケージマネージャーコンソールを使ってインストールするには?
NuGet パッケージ マネージャーを使用してインストールするか、パッケージ マネージャー コンソールに次の内容を貼り付けます。
Install-Package IronOcr.ComputerVision.Windows
これはIronOCR Computer Visionを我々のモデルファイルと共に使用するために必要なアセンブリを提供します。
IronOCRではどのようなコンピュータビジョンメソッドが利用できますか?
コード例は、このチュートリアルのさらに下に含まれています。 以下は、現在利用可能な方法の一般的な概要です:
| 方法 | 説明 |
|---|---|
| テキスト領域の検索 | テキスト要素を含む領域を検出し、テキストが検出された領域内のテキストのみを検索するように Tesseract に指示します。 |
| 複数のテキスト領域を検索 | テキスト要素を含む領域を検出し、テキスト領域に基づいてページを個別の画像に分割します。 |
| テキスト領域を取得 | Scans the image and returns a list of text regions as `List |
テキスト領域を検出するために FindTextRegion を使用するにはどうすればよいですか?
FindTextRegion はコンピューター ビジョンを使用して、OcrInput オブジェクトの各ページでテキスト要素を含む領域を検出します。 この方法は、テキストが散在している画像を処理する場合や、テキストを含む領域のみに焦点を当てることでパフォーマンスを向上させる必要がある場合に特に有効です。
基本的な FindTextRegion の使用方法は何ですか?
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findtextregion-1.cs
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("/path/file.png");
input.FindTextRegion();
OcrResult result = ocr.Read(input);
string resultText = result.Text;
Imports IronOcr
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("/path/file.png")
input.FindTextRegion()
Dim result As OcrResult = ocr.Read(input)
Dim resultText As String = result.Text
IronOcr 2025.6.x で非推奨となっており、カスタムパラメータは受け付けません。どのように FindTextRegion パラメータをカスタマイズできますか?
テキスト検出を微調整するために、カスタムパラメータを使用してこのメソッドを呼び出します。 これらのパラメータは、画像フィルタの設定と同様に機能します:
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findtextregion-2.cs
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("/path/file.png");
input.FindTextRegion(Scale: 2.0, DilationAmount: 20, Binarize: true, Invert: true);
OcrResult result = ocr.Read(input);
string resultText = result.Text;
Imports IronOcr
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("/path/file.png")
input.FindTextRegion(Scale:= 2.0, DilationAmount:= 20, Binarize:= True, Invert:= True)
Dim result As OcrResult = ocr.Read(input)
Dim resultText As String = result.Text
実際の FindTextRegion はどのようなものですか?
この例では、テキストを含む領域を切り抜く必要があるメソッドに次の画像を使用していますが、入力画像はテキストの位置が異なる場合があります。 Computer Vision がテキストを検出した領域にスキャンを絞り込むために、FindTextRegion を使用します。 このアプローチは、content areas and crop regions tutorial で使用したテクニックに似ています。 これはサンプル画像です:
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findtextregion-3.cs
using IronOcr;
using IronSoftware.Drawing;
using System;
using System.Linq;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("wh-words-sign.jpg");
// Find the text region using Computer Vision
Rectangle textCropArea = input.GetPages().First().FindTextRegion();
// For debugging and demonstration purposes, lets see what region it found:
input.StampCropRectangleAndSaveAs(textCropArea, Color.Red, "image_text_area", AnyBitmap.ImageFormat.Png);
// Looks good, so let us apply this region to hasten the read:
var ocrResult = ocr.Read("wh-words-sign.jpg", textCropArea);
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Imports System.Linq
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("wh-words-sign.jpg")
' Find the text region using Computer Vision
Dim textCropArea As Rectangle = input.GetPages().First().FindTextRegion()
' For debugging and demonstration purposes, lets see what region it found:
input.StampCropRectangleAndSaveAs(textCropArea, Color.Red, "image_text_area", AnyBitmap.ImageFormat.Png)
' Looks good, so let us apply this region to hasten the read:
Dim ocrResult = ocr.Read("wh-words-sign.jpg", textCropArea)
Console.WriteLine(ocrResult.Text)
テキスト領域の検出をデバッグおよび検証するには?
このコードには2つの出力があります。 1 つ目は、デバッグに使用される StampCropRectangleAndSaveAs によって保存された .png ファイルです。 このテクニックは、highlight texts for debugging guide でも扱っています。 IronCV(Computer Vision)がテキストを検出した箇所がわかります:
テキストエリアを正確に検出します。 2つ目のアウトプットは、テキストそのものです:
IRONSOFTWARE
50,000+
Developers in our active community
10,777,061 19,313
NuGet downloads Support tickets resolved
50%+ 80%+
Engineering Team growth Support Team growth
$25,000+
Raised with #TEAMSEAS to clean our beaches & waterways
複数のテキスト領域に対して FindMultipleTextRegions を使用するにはどうすればよいですか?
FindMultipleTextRegions は、OcrInput オブジェクトのすべてのページを取得し、コンピューター ビジョンを使用してテキスト要素を含む領域を検出し、入力をテキスト領域に基づいて個別の画像に分割します。 これは、read table in document functionalityのように、複数の異なるテキスト領域を持つドキュメントを処理する際に特に役立ちます:
基本的な FindMultipleTextRegions の使用法は何ですか?
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findmultipletextregions-1.cs
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("/path/file.png");
input.FindMultipleTextRegions();
OcrResult result = ocr.Read(input);
string resultText = result.Text;
Imports IronOcr
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("/path/file.png")
input.FindMultipleTextRegions()
Dim result As OcrResult = ocr.Read(input)
Dim resultText As String = result.Text
FindMultipleTextRegions メソッドはカスタム パラメータをサポートしなくなりました。どのように FindMultipleTextRegions パラメータをカスタマイズできますか?
リージョンがどのように検出され、区切られるかを制御するために、カスタムパラメータを使用してこのメソッドを呼び出します:
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findmultipletextregions-2.cs
using IronOcr;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("/path/file.png");
input.FindMultipleTextRegions(Scale: 2.0, DilationAmount: -1, Binarize: true, Invert: false);
OcrResult result = ocr.Read(input);
string resultText = result.Text;
Imports IronOcr
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("/path/file.png")
input.FindMultipleTextRegions(Scale:= 2.0, DilationAmount:= -1, Binarize:= True, Invert:= False)
Dim result As OcrResult = ocr.Read(input)
Dim resultText As String = result.Text
個々のページを FindMultipleTextRegions で処理するにはどうすればよいですか?
FindMultipleTextRegions の別のオーバーロード メソッドは、OCR ページを受け取り、その上のテキスト領域ごとに 1 つずつ OCR ページのリストを返します。 このアプローチは、マルチページTIFF処理ガイドで説明したテクニックと同様に、複雑なレイアウトを扱うときに役立ちます:
:path=/static-assets/ocr/content-code-examples/how-to/computer-vision-findmultipletextregions-3.cs
using IronOcr;
using System.Collections.Generic;
using System.Linq;
int pageIndex = 0;
using var input = new OcrInput();
input.LoadImage("/path/file.png");
var selectedPage = input.GetPages().ElementAt(pageIndex);
List<OcrInputPage> textRegionsOnPage = selectedPage.FindMultipleTextRegions();
Imports IronOcr
Imports System.Collections.Generic
Imports System.Linq
Private pageIndex As Integer = 0
Private input = New OcrInput()
input.LoadImage("/path/file.png")
Dim selectedPage = input.GetPages().ElementAt(pageIndex)
Dim textRegionsOnPage As List(Of OcrInputPage) = selectedPage.FindMultipleTextRegions()
テキスト領域の座標を取得するために GetTextRegions を使用するにはどうすればよいですか?
GetTextRegions は、ページ上でテキストが検出されたトリミング領域のリストを返します。 この方法は、さらなる処理のためにテキスト領域の座標が必要な場合や、カスタムOCRワークフローを実装する場合に特に便利です。 結果を扱う詳細については、OcrResultクラスのドキュメントを参照してください:
どのような場合に FindTextRegion ではなく GetTextRegions を使用すべきですか?
/* :path=/static-assets/ocr/content-code-examples/how-to/computer-vision-gettextregions.cs */
using IronOcr;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
// Create a new IronTesseract object for OCR
var ocr = new IronTesseract();
// Load an image into OcrInput
using var input = new OcrInput();
input.LoadImage("/path/file.png");
// Get the first page from the input
var firstPage = input.GetPages().First();
// Get all text regions detected on this page
List<Rectangle> textRegions = firstPage.GetTextRegions();
// Display information about each detected region
Console.WriteLine($"Found {textRegions.Count} text regions:");
foreach (var region in textRegions)
{
Console.WriteLine($"Region at X:{region.X}, Y:{region.Y}, Width:{region.Width}, Height:{region.Height}");
}
// You can also process each region individually
foreach (var region in textRegions)
{
var regionResult = ocr.Read(input, region);
Console.WriteLine($"Text in region: {regionResult.Text}");
}
/* :path=/static-assets/ocr/content-code-examples/how-to/computer-vision-gettextregions.cs */
using IronOcr;
using IronSoftware.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
// Create a new IronTesseract object for OCR
var ocr = new IronTesseract();
// Load an image into OcrInput
using var input = new OcrInput();
input.LoadImage("/path/file.png");
// Get the first page from the input
var firstPage = input.GetPages().First();
// Get all text regions detected on this page
List<Rectangle> textRegions = firstPage.GetTextRegions();
// Display information about each detected region
Console.WriteLine($"Found {textRegions.Count} text regions:");
foreach (var region in textRegions)
{
Console.WriteLine($"Region at X:{region.X}, Y:{region.Y}, Width:{region.Width}, Height:{region.Height}");
}
// You can also process each region individually
foreach (var region in textRegions)
{
var regionResult = ocr.Read(input, region);
Console.WriteLine($"Text in region: {regionResult.Text}");
}
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
Imports System.Linq
' Create a new IronTesseract object for OCR
Dim ocr As New IronTesseract()
' Load an image into OcrInput
Using input As New OcrInput()
input.LoadImage("/path/file.png")
' Get the first page from the input
Dim firstPage = input.GetPages().First()
' Get all text regions detected on this page
Dim textRegions As List(Of Rectangle) = firstPage.GetTextRegions()
' Display information about each detected region
Console.WriteLine($"Found {textRegions.Count} text regions:")
For Each region In textRegions
Console.WriteLine($"Region at X:{region.X}, Y:{region.Y}, Width:{region.Width}, Height:{region.Height}")
Next
' You can also process each region individually
For Each region In textRegions
Dim regionResult = ocr.Read(input, region)
Console.WriteLine($"Text in region: {regionResult.Text}")
Next
End Using
OCRにおけるコンピュータビジョンの一般的な使用例とは
コンピュータビジョンは、困難なシナリオにおいてOCRの精度を大幅に向上させます。 実用的なアプリケーションを紹介します:
1.ドキュメントレイアウト分析: 複雑なドキュメントのさまざまなセクションを識別し、自動的に処理します。 特に、スキャンしたドキュメントで役立ちます。
2.複数コラムのテキスト: 新聞や雑誌のコラムを独立させて読む。 より速い結果を得るために、マルチスレッド処理を使用してください。
3.ミックスコンテンツ:文書内のテキスト領域とグラフィックを区別する。 テキストが埋め込まれた写真を処理する際に役立ちます。
4.パフォーマンスの最適化:テキストを含む領域のみにOCR処理を集中させます。 高速 OCR 設定ガイドを参照してください。
5.品質管理:完全なOCR処理の前にテキスト検出を検証します。 当社の進捗追跡機能は、各ステージを監視します。
適切な設定と入力ファイルがあれば、OCRは人間に近い読み取り能力を実現できます。 最適な結果を得るには、コンピュータビジョンと画像最適化フィルターを組み合わせて、可能な限り最高のOCR精度を達成してください。 低画質の画像を扱う場合、低画質スキャンの修正に関するガイドでは、貴重な前処理テクニックを提供しています。
高度なコンピュータ ビジョン技術
OCR精度の限界に挑戦したい開発者は、以下の高度なアプローチを検討してください:
- カスタムトレーニング: カスタム言語ファイルガイドを使用して、特殊なフォントのOCRエンジンをトレーニングします。
- 多言語サポート:多言語機能で多言語ドキュメントを処理します。
- バーコード統合:バーコード読み取り機能付きOCRを使用して、テキスト認識とバーコード読み取りを組み合わせます。
よくある質問
OCRにおけるコンピュータ・ビジョンとは何ですか?
IronOCRのコンピュータ・ビジョンは、OpenCVアルゴリズムを使用して、OCR処理の前に画像内のテキスト領域を自動的に検出します。これにより、画像全体を処理するのではなく、特定されたテキスト領域のみにTesseract認識を集中させることで、ノイズの多いテキスト、複数の領域、ゆがんだテキストに対する精度を大幅に向上させます。
C#でComputer Vision OCRを素早く実装するには?
FindTextRegion()メソッドでIronTesseractを使用し、主要なテキスト領域を自動検出し、.Read()を実行してテキストを即座に抽出します。
なぜComputer Visionパッケージを別にインストールする必要があるのですか?
IronOCRは、コンピュータ・ビジョン機能がOpenCVアルゴリズムを活用しているため、個別のIronOcr.ComputerVision NuGetパッケージが必要です。これらのアルゴリズムはテキスト検出精度を大幅に向上させ、ナンバープレート認識やパスポートスキャニングのような機能に不可欠です。
どのプラットフォーム固有のComputer Visionパッケージをインストールすべきですか?
IronOCRはプラットフォーム別のパッケージを提供しています:IronOcr.ComputerVision.WindowsはWindowsシステム用、IronOcr.ComputerVision.LinuxはLinuxディストリビューション用、IronOcr.ComputerVision.MacOSはmacOS環境用です。
画像内の複数のテキスト領域を検出する方法を教えてください。
IronOCRはFindMultipleTextRegionsメソッドを提供し、検出されたテキスト領域に基づいて元の画像を複数の画像に分割します。また、GetTextRegionsを使ってテキストが検出されたクロップ領域のリストを取得することもできます。
処理前にどのテキスト領域が検出されたかを確認できますか。
はい、IronOCRにはStampCropRectangleAndSaveAsメソッドがあり、実際のOCR処理を実行する前に、どのテキスト領域がコンピューター・ビジョン・アルゴリズムによって検出されたかを確認することができます。

