C#でコンピュータ ビジョンを使用してテキストを検索する方法
IronOCRはOpenCVコンピュータ・ビジョンを使って、OCR処理の前に画像中のテキスト領域を自動的に検出します。 これは、Tesseractの認識を識別されたテキスト領域のみに集中させることで、ノイズの多いテキスト、複数の領域、ゆがんだテキストに対する精度を向上させ、画像全体を処理する場合と比較して抽出結果を大幅に向上させます。
クイックスタート: 主要なテキスト領域を検出しOCRするこの例は、テキストの即時抽出を示しています:画像をロードし、IronOCRのComputer Visionを使用してメインテキスト領域を.Read(...)を実行して一行でテキストを抽出します。
-
1Install IronOCR with NuGet Package Manager
-
2このコード スニペットをコピーして実行します。
using var result = new IronTesseract().Read(new OcrInput().LoadImage("image.png").FindTextRegion());Using result = New IronTesseract().Read(New OcrInput().LoadImage("image.png").FindTextRegion())Using result = New IronTesseract().Read(New OcrInput().LoadImage("image.png").FindTextRegion()) -
3実際の環境でテストするためにデプロイする
今日プロジェクトで IronOCR を使い始めましょう無料トライアル
- 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 パッケージ マネージャーを使用してインストールするか、パッケージ マネージャー コンソールに次の内容を貼り付けます。
これはIronOCR Computer Visionを我々のモデルファイルと共に使用するために必要なアセンブリを提供します。
IronOCRではどのようなコンピュータビジョンメソッドが利用できますか?
コード例は、このチュートリアルのさらに下に含まれています。 以下は、現在利用可能な方法の一般的な概要です:
| 方法 | 説明 |
|---|---|
FindTextRegion | テキスト要素を含む領域を検出し、テキストが検出された領域内のテキストのみを検索するように Tesseract に指示します。 |
FindMultipleTextRegions | テキスト要素を含む領域を検出し、テキスト領域に基づいてページを個別の画像に分割します。 |
GetTextRegions | Scans the image and returns a list of text regions as List<CropRectangle>. |
テキスト領域を検出するために FindTextRegion を使用するにはどうすればよいですか?
OcrInputオブジェクトの各ページにテキスト要素を含む領域を検出します。 この方法は、テキストが散在している画像を処理する場合や、テキストを含む領域のみに焦点を当てることでパフォーマンスを向上させる必要がある場合に特に有効です。
基本的な FindTextRegion の使用方法は何ですか?
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;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.TextImports 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.TextIronOcr 2025.6.xで非推奨であり、カスタムパラメータを受け入れません。
どのように FindTextRegion パラメータをカスタマイズできますか?
テキスト検出を微調整するために、カスタムパラメータを使用してこのメソッドを呼び出します。 これらのパラメータは、画像フィルタの設定と同様に機能します:
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;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.TextImports 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実際の FindTextRegion はどのようなものですか?
この例では、テキストを含む領域を切り抜く必要があるメソッドに次の画像を使用していますが、入力画像はテキストの位置が異なる場合があります。 FindTextRegionを使用して、Computer Visionがテキストを検出した領域にスキャンを絞り込みます。 このアプローチは、content areas and crop regions tutorial で使用したテクニックに似ています。 これはサンプル画像です:

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);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)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つの出力があります。 最初のものはデバッグに使用される.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 を使用するにはどうすればよいですか?
OcrInputオブジェクトのすべてのページを取得し、コンピュータビジョンを使用してテキスト要素を含む領域を検出し、入力をテキスト領域に基づいて別々の画像に分割します。 これは、read table in document functionalityのように、複数の異なるテキスト領域を持つドキュメントを処理する際に特に役立ちます:
基本的な FindMultipleTextRegions の使用法は何ですか?
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;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.TextImports 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.TextFindMultipleTextRegionsメソッドはカスタムパラメータをサポートしなくなりました。どのように FindMultipleTextRegions パラメータをカスタマイズできますか?
リージョンがどのように検出され、区切られるかを制御するために、カスタムパラメータを使用してこのメソッドを呼び出します:
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;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.TextImports 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の別のオーバーロードメソッドはOCRページを受け取り、そのページ上の各テキスト領域ごとにOCRページのリストを返します。 このアプローチは、マルチページTIFF処理ガイドで説明したテクニックと同様に、複雑なレイアウトを扱うときに役立ちます:
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();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()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("/path/file.png", 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("/path/file.png", 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 = New IronTesseract()
' Load an image into OcrInput
Using input = 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("/path/file.png", region)
Console.WriteLine($"Text in region: {regionResult.Text}")
Next
End UsingImports IronOcr
Imports IronSoftware.Drawing
Imports System
Imports System.Collections.Generic
Imports System.Linq
' Create a new IronTesseract object for OCR
Dim ocr = New IronTesseract()
' Load an image into OcrInput
Using input = 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("/path/file.png", region)
Console.WriteLine($"Text in region: {regionResult.Text}")
Next
End UsingOCRにおけるコンピュータビジョンの一般的な使用例とは
コンピュータビジョンは、困難なシナリオにおいて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処理を実行する前に、どのテキスト領域がコンピューター・ビジョン・アルゴリズムによって検出されたかを確認することができます。
What is the use of the GetTextRegions method in IronOCR?
The GetTextRegions method in IronOCR provides a list of detected text regions as coordinates, useful for further processing or implementing custom OCR workflows.
How can IronOCR assist in processing documents with multiple text areas?
IronOCR uses the FindMultipleTextRegions method to detect and process documents with multiple distinct text areas by automatically separating them into individual sections for better OCR performance.
Why might IronOCR require a separate Computer Vision package?
The separate Computer Vision package for IronOCR, available via NuGet, is necessary to utilize advanced text detection features powered by OpenCV algorithms, enhancing OCR accuracy beyond standard capabilities.
What common uses does computer vision in IronOCR support?
Computer vision in IronOCR can be used for document layout analysis, multi-column text recognition, distinguishing mixed content, performance optimizations, and quality control in OCR processes.
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。