C#でIronOCRを使ってスクリーンショットを読む方法</#35;

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

IronOCRのReadScreenshotメソッドは、スクリーンショットからテキストを効率的に抽出します。さまざまなサイズやノイズの問題に対応しつつ、PNG、JPG、BMPなどの一般的なファイル形式をサポートしています。

スクリーンショットは、情報を共有し、重要なデータをキャプチャする迅速な方法を提供します。 しかし、スクリーンショットからテキストを抽出することは、さまざまなサイズやノイズのために困難であることが判明しています。このため、スクリーンショットはOCRにとって難しい媒体となっています。

IronOCRは、ReadScreenshotのような特殊なメソッドを提供することで、この問題を解決します。 この方法は、一般的なファイル形式を受け入れながら、スクリーンショットを読み取り、そこから情報を抽出するために最適化されています。 標準的な OCR メソッドとは異なり、このメソッドは、自動ノイズ除去やコントラスト強調など、スクリーンショットのコンテンツに合わせた特定の前処理最適化を適用します。

この機能を使用するには、[IronOcr.Extension.AdvancedScan] パッケージをインストールしてください。 この拡張機能は、特に最新のアプリケーションのUI要素、システムフォント、アンチエイリアステキストに対して、スクリーンショットのテキスト認識精度を高める高度なコンピュータビジョン機能を提供します。

クイックスタート: スクリーンショットからテキストを読み取る

Using IronOCR's ReadScreenshot, you can start in seconds. Upload your screenshot to OcrInput, call ReadScreenShot, and immediately access the extracted text, trust score, and text regions via OcrPhotoResult. 最小限のセットアップで、画像を使用可能なテキストに変換する最速の方法です。

  1. IronOCR をNuGetパッケージマネージャでインストール

    PM > Install-Package IronOcr
  2. このコード スニペットをコピーして実行します。

    OcrPhotoResult result = new IronTesseract().ReadScreenShot(new OcrInput().LoadImage("screenshot.png"));
  3. 実際の環境でテストするためにデプロイする

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

    arrow pointer

このガイドでは、IronOCRをスクリーンショットのテキスト認識に使用する方法を、例と結果オブジェクトのプロパティを通して説明します。 特定地域の処理、多言語コンテンツの処理、バッチ処理のパフォーマンスの最適化など、高度なシナリオを探ります。

ReadScreenshot を使用してスクリーンショットからテキストを抽出するにはどうすればよいですか?

IronOCRでスクリーンショットを読み込むには、OcrInputをパラメータとして受け取ります。 この方法は、ライブラリの標準的な Read よりもスクリーンショットに適しています。 最適化には、UI要素の自動検出、アンチエイリアスフォントの処理の改善、異なるオペレーティングシステム間でのシステムフォントの認識の改善などが含まれます。

ご注意

  • この方法は現在、英語、中国語、日本語、韓国語、ラテン文字ベースのアルファベットなどの言語で機能します。
  • .NET Framework で詳細スキャンを使用するには、プロジェクトを x64 アーキテクチャで実行する必要があります。

)}]

どのようなスクリーンショットが最適ですか?

以下はコード例の入力です。 異なるフォントやサイズのテキストを混在させることで、この方法の汎用性を実証しています。 ReadScreenshot メソッドは、以下の認識に優れています:

  • システムUIフォント(Windows、macOS、Linux)
  • 最新アプリケーションのアンチエイリアステキスト
  • フォントサイズとスタイルの混在
  • 複雑な背景に重ねられたテキスト
  • コンソール出力とターミナルのスクリーンショット
  • さまざまなウェブフォントを使用したブラウザコンテンツ

最適な結果を得るためには、圧縮せずにネイティブ解像度でスクリーンショットをキャプチャしてください。 このメソッドでは、さまざまな画像形式を扱いますが、PNG形式は可逆圧縮のため、テキストの鮮明さを最もよく保ちます。

IronOCR C# OCRライブラリのホームページ。テキスト認識におけるプラットフォームの互換性と主な機能を紹介

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

複雑なシナリオの場合は、前処理を追加してスクリーンショットの読み取り処理を強化します:

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", 96); // Standard screen DPI

// 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}");
}
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", 96); // Standard screen DPI

// 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", 96) ' Standard screen DPI

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

OcrPhotoResult はどのようなプロパティを返しますか?

Visual Studio デバッガーに表示された IronOCRライブラリの詳細(バージョン 2024.9、精度スコア 0.937)

コンソール出力は、スクリーンショットからのすべてのテキストインスタンスの抽出を示しています。 OcrPhotoResult のプロパティと、それらを効果的に活用する方法について見ていきましょう:

  • Text: OCR入力から抽出されたテキスト。 このプロパティには、認識されたすべてのテキストが1つの文字列として含まれ、改行とスペーシングを含む元のレイアウトが保持されます。
  • Confidence: 0から1のスケールで統計的な精度の信頼度を示すダブル型プロパティ。1は最高の信頼度を表します。 アプリケーションの品質管理を実施するために使用してください。
  • TextRegion: スクリーンショット上のテキストが検出された領域を返すプロパティを持つ、TextRegion オブジェクトの配列。 デフォルトでは、すべての TextRegion は、IronOCR モデルから派生した Rectangle クラスです。 これには、widthが含まれます。

TextRegions を使用すると、以下のことが可能になります:

  • 特定のスクリーンショット領域からテキストを抽出
  • UI要素の位置の特定
  • テキスト位置に基づいてクリック可能なオーバーレイを作成
  • 地域固有の OCR 処理を実装します。

以下は、個々のテキスト領域を処理する例です:

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.Text}");
    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.Confidence:P2}");
    Console.WriteLine("---");
}

// Find specific UI elements by text content
var buttonRegion = result.TextRegions
    .FirstOrDefault(r => r.Text.Contains("Submit", StringComparison.OrdinalIgnoreCase));

if (buttonRegion != null)
{
    Console.WriteLine($"Found button at: {buttonRegion.Region.X}, {buttonRegion.Region.Y}");
}
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.Text}");
    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.Confidence:P2}");
    Console.WriteLine("---");
}

// Find specific UI elements by text content
var buttonRegion = result.TextRegions
    .FirstOrDefault(r => r.Text.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.Text}")
        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.Confidence:P2}")
        Console.WriteLine("---")
    Next

    ' Find specific UI elements by text content
    Dim buttonRegion = result.TextRegions _
        .FirstOrDefault(Function(r) r.Text.Contains("Submit", StringComparison.OrdinalIgnoreCase))

    If buttonRegion IsNot Nothing Then
        Console.WriteLine($"Found button at: {buttonRegion.Region.X}, {buttonRegion.Region.Y}")
    End If
End Using
$vbLabelText   $csharpLabel

高度なスクリーンショット処理テクニック

多言語のスクリーンショットを扱う

複数の言語を含むスクリーンショットを扱う場合、IronOCRは堅牢な多言語サポートを提供します。 これは、国際的なアプリケーションや多言語ユーザーインターフェイスのスクリーンショットに役立ちます:

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}");
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
$vbLabelText   $csharpLabel

バッチ処理のパフォーマンス最適化

複数のスクリーンショットを処理する場合は、以下の最適化戦略を実行してください:

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

スクリーンショット OCR のベスト プラクティス

  1. キャプチャ品質: ネイティブ解像度でスケーリングせずにスクリーンショットをキャプチャします
  2. フォーマット選択: PNG形式を使用してロスレスな品質保存を行います
  3. 前処理: スクリーンショットの内容に基づいて適切なフィルターを適用します
  4. 信頼度しきい値: 重要なアプリケーションのための信頼度ベースの検証を実装します 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の無料トライアルを提供しており、ユーザーが購入決定をする前にその機能と能力をテストできます。

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

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

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

準備はできましたか?
Nuget ダウンロード 5,896,332 | バージョン: 2026.5 just released
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package IronOcr
サンプルを実行 あなたの画像が検索可能なテキストになるのをご覧ください。