IRONSOFTWAREHOME

IronOCRを使ったC#での進捗追跡の使い方

Curtis Chau
Curtis Chau
Updated: 2026年6月29日

IronOCR は、開発者が進行パーセント、処理済みページ、およびリアルタイムの時間メトリックを通して読み取り進行状況を監視することを可能にするイベントベースの進捗追跡システムを提供しています。

クイックスタート: OcrProgressにサブスクライブしてPDFを読む

この例では、IronOCR で OCR の進行状況を監視する方法を示しています: 組み込みの OcrProgress イベントを購読し、パーセンテージ、完了したページ数、PDF 読み取り中の合計ページ数を含む即座のフィードバックを受け取ります。 ほんの数行で始められます。

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

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

    var ocr = new IronOcr.IronTesseract();
    ocr.OcrProgress += (s, e) => Console.WriteLine(e.ProgressPercent + "% (" + e.PagesComplete + "/" + e.TotalPages + ")");
    var result = ocr.Read(new IronOcr.OcrInput().LoadPdf("file.pdf"));
    C#
  3. 3実際の環境でテストするためにデプロイする

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

私の OCR アプリケーションに進捗追跡を実装するにはどうすればよいですか?

OCRで大規模な文書やバッチファイルを処理する場合、進行状況の追跡は不可欠です。 OcrProgress イベントに購読して読み取りプロセスの進捗更新を受け取ることができます。 これは、PDFのOCR操作や、複数ページのTIFFファイルを扱うときに特に役立ちます。

このイベントは、開始時間、総ページ数、パーセンテージとしての進捗、継続時間、終了時間など、OCRジョブの進捗に関する情報を含むインスタンスを渡します。この機能は、async オペレーションとシームレスに動作し、multithreading と組み合わせてパフォーマンスを向上させることができます。

次の例では、この文書をサンプルとして使用しています:"生物多様性研究の経験:A Field Course" by Thea B. アイオワ州立大学のゲスラー氏。

using IronOcr;
using System;

var ocrTesseract = new IronTesseract();

// Subscribe to OcrProgress event
ocrTesseract.OcrProgress += (_, ocrProgressEventsArgs) =>
{
    Console.WriteLine("Start time: " + ocrProgressEventsArgs.StartTimeUTC.ToString());
    Console.WriteLine("Total pages number: " + ocrProgressEventsArgs.TotalPages);
    Console.WriteLine("Progress(%) | Duration");
    Console.WriteLine("    " + ocrProgressEventsArgs.ProgressPercent + "%     | " + ocrProgressEventsArgs.Duration.TotalSeconds + "s");
    Console.WriteLine("End time: " + ocrProgressEventsArgs.EndTimeUTC.ToString());
    Console.WriteLine("----------------------------------------------");
};

using var input = new OcrInput();
input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf");

// Progress events will fire during the read operation
var result = ocrTesseract.Read(input);
95%から100%完了までの進捗状況をタイムスタンプと期間データで追跡するコンソール出力

イベントからどのような進捗情報にアクセスできますか?

OCR のパフォーマンスを監視および最適化するのに役立つ包括的な進捗データを OcrProgress イベントが提供します。 各プロパティは、操作の追跡において特定の目的を果たします:

  • ProgressPercent: 完了したページのパーセンテージとしての OCR ジョブの進捗状況。GUI アプリケーションでのプログレスバー更新に役立ちます。
  • TotalPages: OCR エンジンで処理されているページの合計数。推定完了時間の計算に不可欠です。
  • PagesComplete: OCR 読み取りが完全に完了したページの数。 このカウントは、ページが処理されるにつれて徐々に増えていきます。
  • Duration: OCR ジョブの全期間。プロセス全体が完了するのにかかった時間を示します。 TimeSpan 形式で測定され、イベントがトリガーされるたびに更新されます。
  • StartTimeUTC: UTC 形式で表される OCR ジョブの開始日と時刻。
  • EndTimeUTC: OCR ジョブが 100% 完了した時の UTC 形式での日付と時刻。 このプロパティは、OCRの処理中はNULLで、処理が終了すると入力されます。

高度な進捗追跡の実装

本番アプリケーションでは、より洗練された進捗管理を実装します。 この例には、エラー処理と詳細なロギングが含まれています:

using IronOcr;
using System;
using System.Diagnostics;

public class OcrProgressTracker
{
    private readonly IronTesseract _tesseract;
    private Stopwatch _stopwatch;
    private int _lastReportedPercent = 0;

    public OcrProgressTracker()
    {
        _tesseract = new IronTesseract();
        
        // Configure for optimal performance
        _tesseract.Language = OcrLanguage.EnglishBest;
        _tesseract.Configuration.ReadBarCodes = false;
        
        // Subscribe to progress event
        _tesseract.OcrProgress += OnOcrProgress;
    }

    private void OnOcrProgress(object sender, OcrProgressEventsArgs e)
    {
        // Only report significant progress changes (every 10%)
        if (e.ProgressPercent - _lastReportedPercent >= 10 || e.ProgressPercent == 100)
        {
            _lastReportedPercent = e.ProgressPercent;
            
            Console.WriteLine($"Progress: {e.ProgressPercent}%");
            Console.WriteLine($"Pages: {e.PagesComplete}/{e.TotalPages}");
            Console.WriteLine($"Elapsed: {e.Duration.TotalSeconds:F1}s");
            
            // Estimate remaining time
            if (e.ProgressPercent > 0 && e.ProgressPercent < 100)
            {
                var estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0);
                var remaining = estimatedTotal - e.Duration.TotalSeconds;
                Console.WriteLine($"Estimated remaining: {remaining:F1}s");
            }
            
            Console.WriteLine("---");
        }
    }

    public OcrResult ProcessDocument(string filePath)
    {
        _stopwatch = Stopwatch.StartNew();
        
        using var input = new OcrInput();
        input.LoadPdf(filePath);
        
        // Apply image filters for better accuracy
        input.Deskew();
        input.DeNoise();
        
        var result = _tesseract.Read(input);
        
        _stopwatch.Stop();
        Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s");
        
        return result;
    }
}

進捗追跡を UI アプリケーションに統合する

Windows FormsやWPFでデスクトップアプリケーションを構築する場合、進捗管理はユーザーエクスペリエンスにとって非常に重要です。 progressイベントは、UI要素を安全に更新することができます:

using System;
using System.Windows.Forms;
using IronOcr;

public partial class OcrForm : Form
{
    private IronTesseract _tesseract;
    private ProgressBar progressBar;
    private Label statusLabel;

    public OcrForm()
    {
        InitializeComponent();
        _tesseract = new IronTesseract();
        _tesseract.OcrProgress += UpdateProgress;
    }

    private void UpdateProgress(object sender, OcrProgressEventsArgs e)
    {
        // Ensure UI updates happen on the main thread
        if (InvokeRequired)
        {
            BeginInvoke(new Action(() => UpdateProgress(sender, e)));
            return;
        }

        progressBar.Value = e.ProgressPercent;
        statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}";
        
        // Show completion message
        if (e.ProgressPercent == 100)
        {
            MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds");
        }
    }
}

大きなドキュメントとタイムアウトを扱う

広範なドキュメントを処理する場合、進行状況の追跡がさらに重要になります。 タイムアウト設定アボートトークンと組み合わせることで、より優れた制御が可能になります:

using IronOcr;
using System;
using System.Threading;

public async Task ProcessLargeDocumentWithTimeout()
{
    var cts = new CancellationTokenSource();
    var tesseract = new IronTesseract();
    
    // Set a timeout of 5 minutes
    cts.CancelAfter(TimeSpan.FromMinutes(5));
    
    tesseract.OcrProgress += (s, e) =>
    {
        Console.WriteLine($"Progress: {e.ProgressPercent}% - Page {e.PagesComplete}/{e.TotalPages}");
        
        // Check if we should cancel based on progress
        if (e.Duration.TotalMinutes > 4 && e.ProgressPercent < 50)
        {
            Console.WriteLine("Processing too slow, cancelling...");
            cts.Cancel();
        }
    };
    
    try
    {
        using var input = new OcrInput();
        input.LoadPdf("large-document.pdf");
        
        var result = await Task.Run(() => 
            tesseract.Read(input, cts.Token), cts.Token);
            
        Console.WriteLine("OCR completed successfully");
    }
    catch (OperationCanceledException)
    {
        Console.WriteLine("OCR operation was cancelled");
    }
}

進捗追跡のベストプラクティス

  1. 更新頻度: OcrProgress イベントは処理中に頻繁に発生します。 UIやログを圧迫しないよう、更新のフィルタリングを検討してください。

2.パフォーマンスへの影響:進行状況の追跡はパフォーマンスのオーバーヘッドを最小限に抑えますが、過剰なロギングや UI の更新は OCR プロセスを遅くする可能性があります。

3.メモリ管理大きな TIFF ファイルまたは PDF の場合、最適なパフォーマンスを確保するために、進行状況とともにメモリ使用量を監視します。

4.エラー処理:例外によって OCR プロセスが中断されるのを防ぐため、進行イベントハンドラには常にエラー処理を含めてください。

  1. スレッドセーフティ: プログレスイベントから UI エレメントを更新する際には、Invoke または BeginInvoke メソッドを使用して適切なスレッド同期を保証してください。

結論

IronOCRのプログレス・トラッキングはOCR処理に必要不可欠な可視性を提供し、開発者は処理状況をユーザーに知らせる応答性の高いアプリケーションを作成することができます。 OcrProgress イベントを効果的に活用することで、1 ページの文書から広範な PDF ファイルまで自信を持って処理できるプロフェッショナルなアプリケーションを構築できます。

より高度な OCR テクニックについては、画像フィルターおよび 結果オブジェクトに関するガイドを参照して、OCR 実装をさらに強化してください。

よくある質問

OCRの進捗状況をリアルタイムで追跡するにはどうすればよいですか?

IronOCRはOcrProgressイベントを通してイベントベースの進捗管理システムを提供します。IronTesseractインスタンス上でこのイベントをサブスクライブするだけで、OCR処理中の完了率、処理されたページ、時間メトリクスを含むリアルタイムの最新情報を受け取ることができます。

OcrProgressイベントはどのような情報を提供しますか?

IronOCRのOcrProgressイベントは、ProgressPercent (0-100%)、TotalPagesカウント、PagesCompleteカウント、開始・終了時刻、総所要時間を含む包括的なデータを提供します。この情報は、GUIアプリケーションでプログレスバーを更新したり、OCRのパフォーマンスを監視したりする際に特に役立ちます。

非同期 OCR 操作で進捗管理を使用できますか?

IronOCRの進捗管理機能は非同期処理とシームレスに連動します。OcrProgressイベントを通してリアルタイムの進捗アップデートを受け取りながら、非同期処理やマルチスレッドと組み合わせてパフォーマンスを向上させることができます。

PDF OCRの簡単な進捗管理機能を実装するにはどうすればよいですか?

IronOCRで基本的な進捗トラッキングを実装するには、IronTesseractインスタンスを作成し、ラムダ式またはイベントハンドラでOcrProgressイベントをサブスクライブし、PDFでReadメソッドを呼び出します。イベントは定期的に発生し、完了率と処理されたページの情報を提供します。

進捗管理は大規模な文書処理に役立ちますか?

IronOCRで大きな文書やバッチファイルを処理する場合、進捗管理は不可欠です。特にPDFのOCR処理や複数ページのTIFFファイルの処理に有効で、処理状況の監視、完了時間の見積もり、長時間の処理中のユーザーフィードバックが可能です。

Is there a recommended frequency for OcrProgress updates?

While the OcrProgress event fires frequently, it's recommended to filter updates to avoid overwhelming your UI or logs, which can impact performance.

How can IronOCR's progress tracking improve the processing of large documents?

When dealing with large documents, IronOCR's progress tracking allows for better control with timeout settings and abort tokens, providing a mechanism to handle slow processing efficiently.

Does progress tracking in IronOCR affect performance?

Progress tracking in IronOCR has minimal performance overhead, although excessive logging or UI updates based on progress events may slow down the overall OCR process.

What best practices should I follow for using progress tracking in IronOCR?

Best practices include managing update frequencies, ensuring thread safety when updating UI elements, and incorporating error handling to maintain smooth OCR operations.

Can IronOCR be used for tracking progress in multi-threaded environments?

Yes, IronOCR's progress tracking can be combined with multi-threading to enhance OCR performance, handling multiple documents or large files more efficiently.

Curtis Chau
テクニカルライター

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

...
詳しく読む

準備はできましたか?

Nuget Downloads 6,236,385バージョン:2026.9リリースされたばかり

無料をゲット

30日間の試用キーをすぐに取得。

bullet_checkedクレジットカードやアカウントの作成は不要です。
bullet_test製品版でのテスト
透かしなし
bullet_calendar30日間
完全機能の製品
bullet_support試用期間中の
24/5テクニカルサポート
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。
PDF用C# NuGetライブラリ
NuGetでインストール

バージョン: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. ソリューションエクスプローラーで参照を右クリックし、NuGetパッケージを管理を選択
  2. 「参照」を選択して「IronOCR」を検索
  3. パッケージを選択してインストール
C# PDF DLL
DLLをダウンロード

バージョン: 2026.9

または、Windowsインストーラーをこちらからダウンロード。

  1. IronOCRをダウンロードして、ソリューションディレクトリ内の~/Libsなどの場所に解凍します
  2. Visual Studioソリューションエクスプローラーで、リファレンスを右クリックします。「参照」、「IronOCR.dll」を選択

$999からのライセンス

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。