C#でテキストを見つけるためにコンピュータビジョンを使用する方法

C#でコンピュータ ビジョンを使用してテキストを検索する方法</#35;

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

IronOCRはOpenCVコンピュータ・ビジョンを使って、OCR処理の前に画像中のテキスト領域を自動的に検出します。 これは、Tesseractの認識を識別されたテキスト領域のみに集中させることで、ノイズの多いテキスト、複数の領域、ゆがんだテキストに対する精度を向上させ、画像全体を処理する場合と比較して抽出結果を大幅に向上させます。

クイックスタート: 主要なテキスト領域の検出とOCR

この例では、画像を読み込み、IronOCRのコンピュータ・ビジョンを使ってFindTextRegion()で主要なテキスト領域を自動検出し、.Read(...)を実行して1行でテキストを抽出します。

Nuget Icon今すぐ NuGet で PDF を作成してみましょう:

  1. NuGet パッケージ マネージャーを使用して IronOCR をインストールします

    PM > Install-Package IronOcr

  2. このコード スニペットをコピーして実行します。

    using var result = new IronTesseract().Read(new OcrInput().LoadImage("image.png").FindTextRegion());
  3. 実際の環境でテストするためにデプロイする

    今すぐ無料トライアルでプロジェクトに IronOCR を使い始めましょう
    arrow pointer

NuGetパッケージを使ってIronOCR.ComputerVisionをインストールするには?

IronOCR でコンピューター ビジョンを実行する OpenCV メソッドは、通常の IronOCR NuGet パッケージで表示されます。 詳細なインストールガイドについては、NuGetインストールガイドを参照してください。

なぜIronOCRは別のコンピュータ・ビジョン・パッケージを必要とするのですか?

これらの方法を使用するには、ソリューションにIronOcr.ComputerVisionをNuGetインストールする必要があります。 インストールされていない場合はダウンロードするように求められます。 コンピュータ ビジョン機能は、ナンバープレート認識パスポート スキャン機能で使用されている技術と同様に、テキスト検出精度を大幅に向上させる OpenCV アルゴリズムを活用しています。

どのプラットフォーム固有のパッケージをインストールすべきですか?

パッケージマネージャーコンソールを使ってインストールするには?

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

このメソッドのオーバーロードは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
$vbLabelText   $csharpLabel

実際の FindTextRegion はどのようなものですか?

この例では、テキストを含む領域を切り抜く必要があるメソッドに次の画像を使用していますが、入力画像はテキストの位置が異なる場合があります。 私はFindTextRegionを使って、Computer Visionがテキストを検出した領域にスキャンを絞り込んでいます。 このアプローチは、content areas and crop regions tutorial で使用したテクニックに似ています。 これはサンプル画像です:

IronSoftware 2022の開発者メトリクスとビジネスパフォーマンスデータを示す会社統計.
: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)
$vbLabelText   $csharpLabel

テキスト領域の検出をデバッグおよび検証するには?

このコードには2つの出力があります。 1つ目は、StampCropRectangleAndSaveAsによって保存された.pngファイルで、デバッグに使用されます。 このテクニックは、highlight texts for debugging guide でも扱っています。 IronCV(Computer Vision)がテキストを検出した箇所がわかります:

FindTextRegionテキスト検出機能を示す赤い境界ボックスのあるIronSoftware 2022の統計

テキストエリアを正確に検出します。 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
$vbLabelText   $csharpLabel

注意 IronOcr v2025.6.x 以降、 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
$vbLabelText   $csharpLabel

個々のページを FindMultipleTextRegions で処理するにはどうすればよいですか?

FindMultipleTextRegionsのもうひとつのオーバーロードメソッドは、OCR Pageを受け取り、OCR Pageのリストを返します。 このアプローチは、マルチページ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()
$vbLabelText   $csharpLabel

テキスト領域の座標を取得するために 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
$vbLabelText   $csharpLabel

OCRにおけるコンピュータビジョンの一般的な使用例とは

コンピュータビジョンは、困難なシナリオにおいてOCRの精度を大幅に向上させます。 実用的なアプリケーションを紹介します:

1.ドキュメントレイアウト分析: 複雑なドキュメントのさまざまなセクションを識別し、自動的に処理します。 特に、スキャンしたドキュメントで役立ちます。

2.複数コラムのテキスト: 新聞や雑誌のコラムを独立させて読む。 より速い結果を得るために、マルチスレッド処理を使用してください。

3.ミックスコンテンツ:文書内のテキスト領域とグラフィックを区別する。 テキストが埋め込まれた写真を処理する際に役立ちます。

4.パフォーマンスの最適化:テキストを含む領域のみにOCR処理を集中させます。 高速 OCR 設定ガイドを参照してください。

5.品質管理:完全な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処理を実行する前に、どのテキスト領域がコンピューター・ビジョン・アルゴリズムによって検出されたかを確認することができます。

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 5,384,824 | バージョン: 2026.2 リリース