# C#でコンピュータ ビジョンを使用してテキストを検索する方法
IronOCRはOpenCVコンピュータ・ビジョンを使って、OCR処理の前に画像中のテキスト領域を自動的に検出します。 これは、Tesseractの認識を識別されたテキスト領域のみに集中させることで、ノイズの多いテキスト、複数の領域、ゆがんだテキストに対する精度を向上させ、画像全体を処理する場合と比較して抽出結果を大幅に向上させます。
*as-heading:2(クイックスタート: 主要なテキスト領域を検出しOCRする)*
この例は、テキストの即時抽出を示しています:画像をロードし、IronOCRのComputer Visionを使用してメインテキスト領域を`.Read(...)`を実行して一行でテキストを抽出します。
```cs
:title=Start OCR with Computer Vision in One Line
using var result = new IronTesseract().Read(new OcrInput().LoadImage("image.png").FindTextRegion());
```
- [C#でナンバープレートをOCRする方法(チュートリアル)](/csharp/ocr/blog/using-ironocr/license-plate-ocr-csharp-tutorial/)
- [C#で請求書からテキストを取得する方法チュートリアル](/csharp/ocr/blog/using-ironocr/invoice-ocr-csharp-tutorial/)
- [C#でスクリーンショットからテキストをOCRで取得する方法](/csharp/ocr/blog/using-ironocr/get-text-ocr-screenshot-csharp-tutorial/)
- [C#で字幕をOCR処理する方法(チュートリアル)](/csharp/ocr/blog/using-ironocr/subtitle-ocr-csharp-tutorial/)
<div class="hsg-featured-snippet">
<h3>最小限のワークフロー(5ステップ)</h3>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronOcr/">コンピューター ビジョンで OCR を使用するための C# ライブラリをダウンロードする</a></li>
<li><code>FindTextRegion</code> メソッドを利用して、テキスト領域を自動検出します</li>
<li><code>StampCropRectangleAndSaveAs</code>メソッドで検出されたテキスト領域を確認します</li>
<li>コンピュータービジョンを使用して、 <code>FindMultipleTextRegions</code>メソッドで元の画像をテキスト領域に基づいて画像に分割します。</li>
<li><code>GetTextRegions</code>メソッドを使用して、テキストが検出されたトリミング領域のリストを取得します。</li>
</ol>
</div>
## NuGetパッケージを使ってIronOcr.ComputerVisionをインストールするには?
IronOCR でコンピューター ビジョンを実行する OpenCV メソッドは、通常の IronOCR NuGet パッケージで表示されます。 詳細なインストールガイドについては、[NuGetインストールガイド](https://ironsoftware.com/csharp/ocr/get-started/advanced-installation-nuget/)を参照してください。
### なぜIronOCRは別のコンピュータ・ビジョン・パッケージを必要とするのですか?
これらのメソッドを使用するには、ソリューションに`IronOcr.ComputerVision`のNuGetインストールが必要です。 インストールされていない場合はダウンロードするように求められます。 コンピュータ ビジョン機能は、[ナンバープレート認識](https://ironsoftware.com/csharp/ocr/how-to/read-license-plate/)や[パスポート スキャン](https://ironsoftware.com/csharp/ocr/how-to/read-passport/)機能で使用されている技術と同様に、テキスト検出精度を大幅に向上させる OpenCV アルゴリズムを活用しています。
### どのプラットフォーム固有のパッケージをインストールすべきですか?
- Windows: `IronOcr.ComputerVision.Windows` - [Windows設定ガイド](https://ironsoftware.com/csharp/ocr/get-started/windows/)を参照してください。
- Linux: `IronOcr.ComputerVision.Linux` - [Linuxインストールチュートリアル](https://ironsoftware.com/csharp/ocr/get-started/linux/)を確認してください。
- macOS: `IronOcr.ComputerVision.MacOS` - [macOS設定説明書](https://ironsoftware.com/csharp/ocr/get-started/mac/)を確認してください。
- macOS ARM: `IronOcr.ComputerVision.MacOS.ARM`
### パッケージマネージャーコンソールを使ってインストールするには?
NuGet パッケージ マネージャーを使用してインストールするか、パッケージ マネージャー コンソールに次の内容を貼り付けます。
```shell
:InstallCmd Install-Package IronOcr.ComputerVision.Windows
```
これはIronOCR Computer Visionを我々のモデルファイルと共に使用するために必要なアセンブリを提供します。
## IronOCRではどのようなコンピュータビジョンメソッドが利用できますか?
コード例は、このチュートリアルのさらに下に含まれています。 以下は、現在利用可能な方法の一般的な概要です:
<table class="table table__configuration-variables">
<tr>
<th scope="col">方法</th>
<th scope="col">説明</th>
</tr>
<tr>
<td><a href="#anchor-findtextregion"><code>FindTextRegion</code></a></td>
<td class="word-break--break-word">テキスト要素を含む領域を検出し、テキストが検出された領域内のテキストのみを検索するように Tesseract に指示します。</td>
</tr>
<tr>
<td><a href="#anchor-findmultipletextregions"><code>FindMultipleTextRegions</code></a></td>
<td class="word-break--break-word">テキスト要素を含む領域を検出し、テキスト領域に基づいてページを個別の画像に分割します。</td>
</tr>
<tr>
<td><a href="#anchor-gettextregions"><code>GetTextRegions</code></a></td>
<td class="word-break--break-word">Scans the image and returns a list of text regions as <code>List<CropRectangle></code>.</td>
</tr>
</table>
## テキスト領域を検出するために FindTextRegion を使用するにはどうすればよいですか?
`OcrInput`オブジェクトの各ページにテキスト要素を含む領域を検出します。 この方法は、テキストが散在している画像を処理する場合や、テキストを含む領域のみに焦点を当てることでパフォーマンスを向上させる必要がある場合に特に有効です。
### 基本的な FindTextRegion の使用方法は何ですか?
```csharp
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;
```
`IronOcr 2025.6.x`で非推奨であり、カスタムパラメータを受け入れません。
### どのように FindTextRegion パラメータをカスタマイズできますか?
テキスト検出を微調整するために、カスタムパラメータを使用してこのメソッドを呼び出します。 これらのパラメータは、[画像フィルタの設定](https://ironsoftware.com/csharp/ocr/how-to/image-quality-correction/)と同様に機能します:
```csharp
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;
```
### 実際の FindTextRegion はどのようなものですか?
この例では、テキストを含む領域を切り抜く必要があるメソッドに次の画像を使用していますが、入力画像はテキストの位置が異なる場合があります。 `FindTextRegion`を使用して、Computer Visionがテキストを検出した領域にスキャンを絞り込みます。 このアプローチは、[content areas and crop regions tutorial](https://ironsoftware.com/csharp/ocr/troubleshooting/crop-regions-rectangles/) で使用したテクニックに似ています。 これはサンプル画像です:
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/ocr/how-to/computer-vision/iron-2022.webp" alt="Iron Software の2022年の会社統計データは、開発者の指標と業務成果データを示しています。" class="img-responsive add-shadow" />
</div>
</div>
```csharp
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);
```
### テキスト領域の検出をデバッグおよび検証するには?
このコードには2つの出力があります。 最初のものはデバッグに使用される`.png`ファイルです。 このテクニックは、[highlight texts for debugging guide](https://ironsoftware.com/csharp/ocr/examples/highlight-texts-for-debugging/) でも扱っています。 IronCV(Computer Vision)がテキストを検出した箇所がわかります:
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/ocr/how-to/computer-vision/text_area_0.PNG" alt="Iron Software の2022年の統計に赤い境界ボックスがあり、FindTextRegion のテキスト検出機能を示しています。" class="img-responsive add-shadow" />
</div>
</div>
テキストエリアを正確に検出します。 2つ目のアウトプットは、テキストそのものです:
```text
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](https://ironsoftware.com/csharp/ocr/examples/read-table-in-document/)のように、複数の異なるテキスト領域を持つドキュメントを処理する際に特に役立ちます:
### 基本的な FindMultipleTextRegions の使用法は何ですか?
```csharp
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;
```
[[e:(IronOCR v2025.6.xからは、`FindMultipleTextRegions`メソッドはカスタムパラメータをサポートしなくなりました。)]]
### どのように FindMultipleTextRegions パラメータをカスタマイズできますか?
リージョンがどのように検出され、区切られるかを制御するために、カスタムパラメータを使用してこのメソッドを呼び出します:
```csharp
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;
```
### 個々のページを FindMultipleTextRegions で処理するにはどうすればよいですか?
`FindMultipleTextRegions`の別のオーバーロードメソッドはOCRページを受け取り、そのページ上の各テキスト領域ごとにOCRページのリストを返します。 このアプローチは、[マルチページTIFF処理ガイド](https://ironsoftware.com/csharp/ocr/examples/csharp-tesseract-multipage-tiff/)で説明したテクニックと同様に、複雑なレイアウトを扱うときに役立ちます:
```csharp
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();
```
## テキスト領域の座標を取得するために GetTextRegions を使用するにはどうすればよいですか?
`GetTextRegions`は、ページ上でテキストが検出されたクロップ領域のリストを返します。 この方法は、さらなる処理のためにテキスト領域の座標が必要な場合や、カスタムOCRワークフローを実装する場合に特に便利です。 結果を扱う詳細については、[OcrResultクラスのドキュメント](https://ironsoftware.com/csharp/ocr/examples/results-objects/)を参照してください:
### どのような場合に FindTextRegion ではなく GetTextRegions を使用すべきですか?
```csharp
/* :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}");
}
```
### OCRにおけるコンピュータビジョンの一般的な使用例とは
コンピュータビジョンは、困難なシナリオにおいてOCRの精度を大幅に向上させます。 実用的なアプリケーションを紹介します:
1.**ドキュメントレイアウト分析**: 複雑なドキュメントのさまざまなセクションを識別し、自動的に処理します。 特に、[スキャンしたドキュメント](https://ironsoftware.com/csharp/ocr/examples/read-scanned-document/)で役立ちます。
2.**複数コラムのテキスト**: 新聞や雑誌のコラムを独立させて読む。 より速い結果を得るために、[マルチスレッド処理](https://ironsoftware.com/csharp/ocr/examples/csharp-tesseract-multithreading-for-speed/)を使用してください。
3.**ミックスコンテンツ**:文書内のテキスト領域とグラフィックを区別する。 [テキストが埋め込まれた写真](https://ironsoftware.com/csharp/ocr/examples/read-photo/)を処理する際に役立ちます。
4.**パフォーマンスの最適化**:テキストを含む領域のみにOCR処理を集中させます。 [高速 OCR 設定ガイド](https://ironsoftware.com/csharp/ocr/examples/tune-tesseract-for-speed-in-dotnet/)を参照してください。
5.**品質管理**:完全なOCR処理の前にテキスト検出を検証します。 当社の[進捗追跡機能](https://ironsoftware.com/csharp/ocr/examples/progress-tracking/)は、各ステージを監視します。
適切な設定と入力ファイルがあれば、OCRは人間に近い読み取り能力を実現できます。 最適な結果を得るには、コンピュータビジョンと[画像最適化フィルター](https://ironsoftware.com/csharp/ocr/examples/ocr-image-filters-for-net-tesseract/)を組み合わせて、可能な限り最高のOCR精度を達成してください。 低画質の画像を扱う場合、[低画質スキャンの修正](https://ironsoftware.com/csharp/ocr/examples/ocr-low-quality-scans-tesseract/)に関するガイドでは、貴重な前処理テクニックを提供しています。
### 高度なコンピュータ ビジョン技術
OCR精度の限界に挑戦したい開発者は、以下の高度なアプローチを検討してください:
- **カスタムトレーニング**: [カスタム言語ファイルガイド](https://ironsoftware.com/csharp/ocr/examples/ocr-tesseract-custom-languages/)を使用して、特殊なフォントのOCRエンジンをトレーニングします。
- **多言語サポート**:[多言語機能](https://ironsoftware.com/csharp/ocr/examples/ocr-tesseract-multiple-languages/)で多言語ドキュメントを処理します。
- **バーコード統合**:[バーコード読み取り機能付きOCR](https://ironsoftware.com/csharp/ocr/examples/csharp-ocr-barcodes/)を使用して、テキスト認識とバーコード読み取りを組み合わせます。
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;
ImportsIronOcrPrivate ocr = New IronTesseract()Private input = New OcrInput()input.LoadImage("/path/file.png")input.FindTextRegion()Dim result AsOcrResult = ocr.Read(input)Dim resultText AsString = 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
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;
ImportsIronOcrPrivate ocr = New IronTesseract()Private input = New OcrInput()input.LoadImage("/path/file.png")input.FindTextRegion()Dim result AsOcrResult = ocr.Read(input)Dim resultText AsString = 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
実際の 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 VisionRectangle 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);
ImportsIronOcrImportsIronSoftware.DrawingImportsSystemImportsSystem.LinqPrivate ocr = New IronTesseract()Private input = New OcrInput()input.LoadImage("wh-words-sign.jpg")' Find the text region using Computer VisionDim textCropArea AsRectangle = 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つ目のアウトプットは、テキストそのものです:
IRONSOFTWARE50,000+Developers in our active community10,777,061 19,313NuGet downloads Support tickets resolved50%+ 80%+Engineering Team growth Support Team growth$25,000+Raised with #TEAMSEAS to clean our beaches & waterways
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
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;
ImportsIronOcrPrivate ocr = New IronTesseract()Private input = New OcrInput()input.LoadImage("/path/file.png")input.FindMultipleTextRegions()Dim result AsOcrResult = ocr.Read(input)Dim resultText AsString = 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
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;
ImportsIronOcrPrivate ocr = New IronTesseract()Private input = New OcrInput()input.LoadImage("/path/file.png")input.FindMultipleTextRegions()Dim result AsOcrResult = ocr.Read(input)Dim resultText AsString = 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
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();
/* :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 OCRvar ocr = new IronTesseract();// Load an image into OcrInputusing var input = new OcrInput();input.LoadImage("/path/file.png");// Get the first page from the inputvar firstPage = input.GetPages().First();// Get all text regions detected on this pageList<Rectangle> textRegions = firstPage.GetTextRegions();// Display information about each detected regionConsole.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 individuallyforeach (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}");
}
ImportsIronOcrImportsIronSoftware.DrawingImportsSystemImportsSystem.Collections.GenericImportsSystem.Linq' Create a new IronTesseract object for OCRDim ocr As New IronTesseract()' Load an image into OcrInputUsing 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 AsList(OfRectangle) = firstPage.GetTextRegions() ' Display information about each detected regionConsole.WriteLine($"Found {textRegions.Count} text regions:") For Each region In textRegionsConsole.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}") NextEndUsing
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
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.