C#でIronOCRを使ってスクリーンショットを読む方法</#35;
IronOCRのReadScreenshotメソッドは、さまざまな寸法やノイズの課題を処理しながら、PNG、JPG、BMPなどの一般的なファイル形式をサポートし、スクリーンショットから効率的にテキストを抽出します。
スクリーンショットは、情報を共有し、重要なデータをキャプチャする迅速な方法を提供します。 しかし、スクリーンショットからテキストを抽出することは、さまざまなサイズやノイズのために困難であることが判明しています。このため、スクリーンショットはOCRにとって難しい媒体となっています。
IronOCRは、ReadScreenshotのような特殊なメソッドを提供することで、この問題を解決します。 この方法は、一般的なファイル形式を受け入れながら、スクリーンショットを読み取り、そこから情報を抽出するために最適化されています。 標準的な OCR メソッドとは異なり、このメソッドは、自動ノイズ除去やコントラスト強調など、スクリーンショットのコンテンツに合わせた特定の前処理最適化を適用します。
この機能を使用するには、[IronOcr.Extension.AdvancedScan]パッケージをインストールしてください。 この拡張機能は、特に最新のアプリケーションのUI要素、システムフォント、アンチエイリアステキストに対して、スクリーンショットのテキスト認識精度を高める高度なコンピュータビジョン機能を提供します。
クイックスタート: スクリーンショットからテキストを読み取る
IronOCRのOcrPhotoResultを介して抽出されたテキスト、信頼度スコア、およびテキスト領域に即座にアクセスできます。 最小限のセットアップで、画像を使用可能なテキストに変換する最速の方法です。
このガイドでは、IronOCRをスクリーンショットのテキスト認識に使用する方法を、例と結果オブジェクトのプロパティを通して説明します。 特定地域の処理、多言語コンテンツの処理、バッチ処理のパフォーマンスの最適化など、高度なシナリオを探ります。
最小限のワークフロー(5ステップ)
- スクリーンショットを読むためのC#ライブラリをダウンロードする
- 処理のためにスクリーンショット画像をインポートする
ReadScreenshotメソッドを使用して画像からテキストを抽出します- OcrPhotoResultプロパティを使用して抽出されたデータを取得し、さらに処理します。
- 必要に応じて抽出したテキストを保存またはエクスポートする
ReadScreenshotを使用してスクリーンショットからテキストを抜き出す方法は?
IronOCRでスクリーンショットを読み込むには、OcrInputがパラメータとして必要です。 このメソッドは、ライブラリの標準Read対応よりもスクリーンショットに最適化されています。 最適化には、UI要素の自動検出、アンチエイリアスフォントの処理の改善、異なるオペレーティングシステム間でのシステムフォントの認識の改善などが含まれます。
- この方法は現在、英語、中国語、日本語、韓国語、ラテン文字ベースのアルファベットなどの言語で機能します。
- .NET Framework で詳細スキャンを使用するには、プロジェクトを x64 アーキテクチャで実行する必要があります。
)}]
どのようなスクリーンショットが最適ですか?
以下はコード例の入力です。 異なるフォントやサイズのテキストを混在させることで、この方法の汎用性を実証しています。 ReadScreenshotメソッドは次の認識に優れています:
- システムUIフォント(Windows、macOS、Linux)
- 最新アプリケーションのアンチエイリアステキスト
- フォントサイズとスタイルの混在
- 複雑な背景に重ねられたテキスト
- コンソール出力とターミナルのスクリーンショット
- さまざまなウェブフォントを使用したブラウザコンテンツ
最適な結果を得るためには、圧縮せずにネイティブ解像度でスクリーンショットをキャプチャしてください。 このメソッドでは、さまざまな画像形式を扱いますが、PNG形式は可逆圧縮のため、テキストの鮮明さを最もよく保ちます。

ReadScreenshotメソッドを実装する方法は?
:path=/static-assets/ocr/content-code-examples/how-to/read-screenshot-read-screenshot.cs
using IronOcr;
using System;
using System.Linq;
// Instantiate OCR engine
var ocr = new IronTesseract();
using var inputScreenshot = new OcrInput();
inputScreenshot.LoadImage("screenshotOCR.png");
// Perform OCR
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);
// Output screenshot 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("screenshotOCR.png")
' Perform OCR
Dim result As OcrPhotoResult = ocr.ReadScreenShot(inputScreenshot)
' Output screenshot information
Console.WriteLine(result.Text)
Console.WriteLine(result.TextRegions.First().Region.X)
Console.WriteLine(result.TextRegions.Last().Region.Width)
Console.WriteLine(result.Confidence)
複雑なシナリオの場合は、前処理を追加してスクリーンショットの読み取り処理を強化します:
:path=/static-assets/ocr/content-code-examples/how-to/read-screenshot-3.cs
using IronOcr;
using System;
// Configure OCR engine with specific settings for screenshots
var ocr = new IronTesseract()
{
// Set language for better accuracy with non-English content
Language = OcrLanguage.English,
// Configure for screen-resolution images
Configuration = new TesseractConfiguration()
{
PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd,
// Enable whitelist for specific characters if needed
WhiteListCharacters = null
}
};
using var inputScreenshot = new OcrInput();
// Load screenshot with specific DPI setting for consistency
inputScreenshot.LoadImage("screenshotOCR.png");
// Apply preprocessing for better accuracy
inputScreenshot.DeNoise(); // Remove screenshot artifacts
inputScreenshot.Sharpen(); // Enhance text edges
// Perform OCR with error handling
try
{
OcrPhotoResult result = ocr.ReadScreenShot(inputScreenshot);
// Process results with confidence threshold
if (result.Confidence > 0.8)
{
Console.WriteLine($"High confidence text extraction: {result.Text}");
}
else
{
Console.WriteLine("Low confidence - consider image preprocessing");
}
}
catch (Exception ex)
{
Console.WriteLine($"OCR Error: {ex.Message}");
}
Imports IronOcr
Imports System
' Configure OCR engine with specific settings for screenshots
Dim ocr As New IronTesseract() With {
' Set language for better accuracy with non-English content
.Language = OcrLanguage.English,
' Configure for screen-resolution images
.Configuration = New TesseractConfiguration() With {
.PageSegmentationMode = TesseractPageSegmentationMode.AutoOsd,
' Enable whitelist for specific characters if needed
.WhiteListCharacters = Nothing
}
}
Using inputScreenshot As New OcrInput()
' Load screenshot with specific DPI setting for consistency
inputScreenshot.LoadImage("screenshotOCR.png")
' Apply preprocessing for better accuracy
inputScreenshot.DeNoise() ' Remove screenshot artifacts
inputScreenshot.Sharpen() ' Enhance text edges
' Perform OCR with error handling
Try
Dim result As OcrPhotoResult = ocr.ReadScreenShot(inputScreenshot)
' Process results with confidence threshold
If result.Confidence > 0.8 Then
Console.WriteLine($"High confidence text extraction: {result.Text}")
Else
Console.WriteLine("Low confidence - consider image preprocessing")
End If
Catch ex As Exception
Console.WriteLine($"OCR Error: {ex.Message}")
End Try
End Using
OcrPhotoResultが返すプロパティとは?

コンソール出力は、スクリーンショットからのすべてのテキストインスタンスの抽出を示しています。 OcrPhotoResultのプロパティを探求し、それらを効果的に活用する方法を見てみましょう:
Text: OCR入力から抽出されたテキスト。 このプロパティには、認識されたすべてのテキストが1つの文字列として含まれ、改行とスペーシングを含む元のレイアウトが保持されます。Confidence: 0から1のスケールで統計的な精度信頼度を示すダブルプロパティで、1は最高の信頼度を表します。 アプリケーションの品質管理を実施するために使用してください。TextRegion: スクリーンショット上でテキストが存在するエリアを返すプロパティを持つTextRegionオブジェクトの配列。 デフォルトで、すべてのRectangleクラスです。 それには、直交座標widthが含まれます。
TextRegionsを使用することで、次を可能にします:
- 特定のスクリーンショット領域からテキストを抽出
- UI要素の位置の特定
- テキスト位置に基づいてクリック可能なオーバーレイを作成
- 地域固有の OCR 処理を実装します。
以下は、個々のテキスト領域を処理する例です:
:path=/static-assets/ocr/content-code-examples/how-to/read-screenshot-4.cs
using IronOcr;
using System;
using System.Linq;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("screenshot.png");
OcrPhotoResult result = ocr.ReadScreenShot(input);
// Process each text region individually
foreach (var region in result.TextRegions)
{
Console.WriteLine($"Text: {region.TextInRegion}");
Console.WriteLine($"Location: X={region.Region.X}, Y={region.Region.Y}");
Console.WriteLine($"Size: {region.Region.Width}x{region.Region.Height}");
Console.WriteLine($"Confidence: {region.RegionConf:P2}");
Console.WriteLine("---");
}
// Find specific UI elements by text content
var buttonRegion = result.TextRegions
.FirstOrDefault(r => r.TextInRegion.Contains("Submit", StringComparison.OrdinalIgnoreCase));
if (buttonRegion != null)
{
Console.WriteLine($"Found button at: {buttonRegion.Region.X}, {buttonRegion.Region.Y}");
}
Imports IronOcr
Imports System
Imports System.Linq
Dim ocr As New IronTesseract()
Using input As New OcrInput()
input.LoadImage("screenshot.png")
Dim result As OcrPhotoResult = ocr.ReadScreenShot(input)
' Process each text region individually
For Each region In result.TextRegions
Console.WriteLine($"Text: {region.TextInRegion}")
Console.WriteLine($"Location: X={region.Region.X}, Y={region.Region.Y}")
Console.WriteLine($"Size: {region.Region.Width}x{region.Region.Height}")
Console.WriteLine($"Confidence: {region.RegionConf:P2}")
Console.WriteLine("---")
Next
' Find specific UI elements by text content
Dim buttonRegion = result.TextRegions _
.FirstOrDefault(Function(r) r.TextInRegion.Contains("Submit", StringComparison.OrdinalIgnoreCase))
If buttonRegion IsNot Nothing Then
Console.WriteLine($"Found button at: {buttonRegion.Region.X}, {buttonRegion.Region.Y}")
End If
End Using
高度なスクリーンショット処理テクニック
多言語のスクリーンショットを扱う
複数の言語を含むスクリーンショットを扱う場合、IronOCRは堅牢な多言語サポートを提供します。 これは、国際的なアプリケーションや多言語ユーザーインターフェイスのスクリーンショットに役立ちます:
:path=/static-assets/ocr/content-code-examples/how-to/read-screenshot-5.cs
using IronOcr;
// Configure for multiple languages
var ocr = new IronTesseract();
ocr.AddSecondaryLanguage(OcrLanguage.ChineseSimplified);
ocr.AddSecondaryLanguage(OcrLanguage.Japanese);
using var input = new OcrInput();
input.LoadImage("multilingual-screenshot.png");
// Process with language detection
OcrPhotoResult result = ocr.ReadScreenShot(input);
Console.WriteLine($"Extracted multilingual text: {result.Text}");
Imports IronOcr
' Configure for multiple languages
Dim ocr As New IronTesseract()
ocr.AddSecondaryLanguage(OcrLanguage.ChineseSimplified)
ocr.AddSecondaryLanguage(OcrLanguage.Japanese)
Using input As New OcrInput()
input.LoadImage("multilingual-screenshot.png")
' Process with language detection
Dim result As OcrPhotoResult = ocr.ReadScreenShot(input)
Console.WriteLine($"Extracted multilingual text: {result.Text}")
End Using
バッチ処理のパフォーマンス最適化
複数のスクリーンショットを処理する場合は、以下の最適化戦略を実行してください:
using IronOcr;
using System.Collections.Generic;
using System.Threading.Tasks;
public async Task ProcessScreenshotBatchAsync(List<string> screenshotPaths)
{
var ocr = new IronTesseract();
// Process screenshots in parallel for better performance
var tasks = screenshotPaths.Select(async path =>
{
using var input = new OcrInput();
input.LoadImage(path);
// Apply consistent preprocessing
input.DeNoise();
var result = await Task.Run(() => ocr.ReadScreenShot(input));
return new { Path = path, Result = result };
});
var results = await Task.WhenAll(tasks);
// Process results
foreach (var item in results)
{
Console.WriteLine($"File: {item.Path}");
Console.WriteLine($"Text: {item.Result.Text}");
Console.WriteLine($"Confidence: {item.Result.Confidence:P2}");
}
}
using IronOcr;
using System.Collections.Generic;
using System.Threading.Tasks;
public async Task ProcessScreenshotBatchAsync(List<string> screenshotPaths)
{
var ocr = new IronTesseract();
// Process screenshots in parallel for better performance
var tasks = screenshotPaths.Select(async path =>
{
using var input = new OcrInput();
input.LoadImage(path);
// Apply consistent preprocessing
input.DeNoise();
var result = await Task.Run(() => ocr.ReadScreenShot(input));
return new { Path = path, Result = result };
});
var results = await Task.WhenAll(tasks);
// Process results
foreach (var item in results)
{
Console.WriteLine($"File: {item.Path}");
Console.WriteLine($"Text: {item.Result.Text}");
Console.WriteLine($"Confidence: {item.Result.Confidence:P2}");
}
}
Imports IronOcr
Imports System.Collections.Generic
Imports System.Threading.Tasks
Public Async Function ProcessScreenshotBatchAsync(screenshotPaths As List(Of String)) As Task
Dim ocr As New IronTesseract()
' Process screenshots in parallel for better performance
Dim tasks = screenshotPaths.Select(Async Function(path)
Using input As New OcrInput()
input.LoadImage(path)
' Apply consistent preprocessing
input.DeNoise()
Dim result = Await Task.Run(Function() ocr.ReadScreenShot(input))
Return New With {Key .Path = path, Key .Result = result}
End Using
End Function)
Dim results = Await Task.WhenAll(tasks)
' Process results
For Each item In results
Console.WriteLine($"File: {item.Path}")
Console.WriteLine($"Text: {item.Result.Text}")
Console.WriteLine($"Confidence: {item.Result.Confidence:P2}")
Next
End Function
スクリーンショット OCR のベスト プラクティス
- キャプチャ品質: ネイティブ解像度でスケーリングせずにスクリーンショットをキャプチャします
- フォーマット選択: PNG形式を使用してロスレスな品質保存を行います
- 前処理: スクリーンショットの内容に基づいて適切なフィルターを適用します
- 信頼度しきい値: 重要なアプリケーションのための信頼度ベースの検証を実装します 5.進捗追跡:長い作業には、進捗追跡を実装してください。
一般的なユースケース
ReadScreenshotメソッドは以下に最適です:
- 自動UIテストと検証
- デジタル資産管理システム
- エラーメッセージをキャプチャするためのカスタマーサポートツール
- ドキュメント自動化
- スクリーンリーダー用のアクセシビリティツール
- ゲームおよびストリーミングアプリケーション
IronOCRの特徴との統合
スクリーンショットの読み取り機能は、IronOCRの他の機能とシームレスに統合されています。 データをさまざまな形式でエクスポートするための包括的なOCR結果の操作や、認識精度を微調整するための高度なTesseract設定をご覧ください。
まとめ
IronOCRのReadScreenshotメソッドは、スクリーンショットからのテキスト抽出における強力で最適化されたソリューションを提供します。 専門的な前処理、高い精度、包括的な結果データにより、開発者はスクリーンショットのコンテンツを確実に処理する堅牢なアプリケーションを構築できます。 自動化ツール、アクセシビリティソリューション、またはデータ抽出システムの構築に使用するかどうかにかかわらず、ReadScreenshotメソッドは、製品化環境に必要な性能と精度を提供します。
よくある質問
スクリーンショットからのOCR抽出が難しい理由は何ですか?
スクリーンショットは、寸法やノイズレベルが異なるため、OCRには独特の課題があります。IronOCRは、スクリーンショットコンテンツに最適化された自動ノイズ除去およびコントラスト強調を適用する特殊なReadScreenshotメソッドにより、これらの問題に対処します。
スクリーンショットOCRでサポートされているファイル形式は何ですか?
IronOCRのReadScreenshotメソッドはPNG、JPG、BMPなどの一般的な画像ファイル形式をサポートしており、ほとんどのスクリーンショットキャプチャツールやアプリケーションと互換性があります。
ReadScreenshotメソッドは、標準的なOCRメソッドとどう違うのですか?
IronOCRの標準的なOCRメソッドとは異なり、ReadScreenshotメソッドは、自動ノイズ除去、コントラスト強調、アンチエイリアスフォントやUI要素のより良い処理など、スクリーンショットコンテンツに合わせた特定の前処理最適化を適用します。
スクリーンショットOCR機能に必要な追加パッケージは何ですか?
IronOCRのReadScreenshot関数を使用するには、IronOcr.Extension.AdvancedScanパッケージをインストールする必要があります。このパッケージは、スクリーンショットのテキスト認識精度を高める高度なコンピューター・ビジョン機能を提供します。
スクリーンショットからテキストを抽出するには、どのくらい時間がかかりますか?
IronOCRを使えば、スクリーンショットをOcrInputに読み込み、ReadScreenShotを呼び出し、抽出されたテキスト、信頼度スコア、テキスト領域にOcrPhotoResultを介して即座にアクセスすることで、スクリーンショットからテキストを数秒で抽出することができます。
スクリーンショット OCR は、どのようなコンテンツに最適化されますか?
IronOCRのスクリーンショット最適化には、UI要素の自動検出、異なるオペレーティング・システム間でのシステム・フォントの認識向上、最新のアプリケーションで一般的なアンチエイリアス・テキストの処理向上が含まれます。
スクリーンショットの特定の領域を処理できますか?
IronOCRはスクリーンショットの特定の領域を処理することをサポートしています。
スクリーンショットOCRで多言語コンテンツはサポートされていますか?
IronOCRのReadScreenshotメソッドはスクリーンショットの多言語コンテンツを扱うことができ、国際的なアプリケーションや多言語ユーザーインターフェースに適しています。
IronOCRはデータ精度をどのように向上させますか?
IronOCRはその高度な認識アルゴリズムと画像補正機能により、信頼性が高く正確なテキスト抽出プロセスを保証します。
IronOCRの無料トライアルを利用できますか?
はい、Iron SoftwareはIronOCRの無料トライアルを提供しており、ユーザーが購入決定をする前にその機能と能力をテストできます。

