Jak korzystać z funkcji śledzenia postępów w języku C# za pomocą IronOCR
IronOCR zapewnia system śledzenia postępu oparty na zdarzeniach dla operacji OCR, umożliwiający programistom monitorowanie postępu odczytu za pomocą zdarzenia OcrProgress, które informuje o procentowym ukończeniu, przetworzonych stronach oraz metrykach czasu w czasie rzeczywistym.
Ten przykład pokazuje, jak monitorować postęp OCR za pomocą IronOCR: subskrybując wbudowane zdarzenie OcrProgress i otrzymując natychmiastową opinię, w tym procent, ukończone strony oraz całkowitą liczbę stron podczas odczytywania pliku PDF. Aby rozpocząć, wystarczy kilka wierszy.
-
1Zainstaluj IronOCR z NuGet Package Manager
-
2Skopiuj i uruchom ten fragment kodu.
using System; var ocr = new IronOcr.IronTesseract(); ocr.OcrProgress += (s, e) => Console.WriteLine(e.ProgressPercent + "% (" + e.PagesComplete + "/" + e.TotalPages + ")"); var input = new IronOcr.OcrInput(); input.LoadPdf("file.pdf"); var result = ocr.Read(input);Imports System Dim ocr = New IronOcr.IronTesseract() AddHandler ocr.OcrProgress, Sub(s, e) Console.WriteLine(e.ProgressPercent & "% (" & e.PagesComplete & "/" & e.TotalPages & ")") Dim input = New IronOcr.OcrInput() input.LoadPdf("file.pdf") Dim result = ocr.Read(input)Imports System Dim ocr = New IronOcr.IronTesseract() AddHandler ocr.OcrProgress, Sub(s, e) Console.WriteLine(e.ProgressPercent & "% (" & e.PagesComplete & "/" & e.TotalPages & ")") Dim input = New IronOcr.OcrInput() input.LoadPdf("file.pdf") Dim result = ocr.Read(input) -
3Wdrożenie do testowania w środowisku produkcyjnym
Rozpocznij korzystanie z IronOCR w swoim projekcie już dziś z darmową wersją próbną
Minimalny proces (5 kroków)
- Pobierz bibliotekę C# do śledzenia postępu odczytu
- Zapisz się do zdarzenia OcrProgress
- Wykorzystaj instancję przekazaną przez zdarzenie, aby pobrać informacje o postępie
- Podaj postęp w procentach i całkowity czas trwania
- Pobierz godziny rozpoczęcia i zakończenia, a także całkowitą liczbę stron
Jak wdrożyć śledzenie postępów w mojej aplikacji OCR?
Śledzenie postępów jest niezbędne podczas przetwarzania dużych dokumentów lub partii plików za pomocą OCR. Zdarzenie OcrProgress można subskrybować, aby otrzymywać aktualizacje postępu procesu odczytu. Jest to szczególnie przydatne w operacjach OCR na plikach PDF oraz podczas pracy z wielostronicowymi plikami TIFF.
Zdarzenie przekazuje instancję zawierającą informacje o postępie zadania OCR, takie jak czas rozpoczęcia, całkowita liczba stron, postęp jako procent, czas trwania i godzina zakończenia. Ta funkcjonalność działa z operacjami asynchronicznymi i może być połączona z wielowątkowością dla poprawy wydajności.
Następujący przykład używa tego dokumentu jako próbki: "Experiences in Biodiversity Research: A Field Course" autorstwa Thea B. Gessler, Uniwersytet Stanowy w Iowa.
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);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);Imports IronOcr
Imports System
Private ocrTesseract = New IronTesseract()
' Subscribe to OcrProgress event
Private ocrTesseract.OcrProgress += Sub(underscore, 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("----------------------------------------------")
End Sub
Private input = New OcrInput()
input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf")
' Progress events will fire during the read operation
Dim result = ocrTesseract.Read(input)Imports IronOcr
Imports System
Private ocrTesseract = New IronTesseract()
' Subscribe to OcrProgress event
Private ocrTesseract.OcrProgress += Sub(underscore, 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("----------------------------------------------")
End Sub
Private input = New OcrInput()
input.LoadPdf("Experiences-in-Biodiversity-Research-A-Field-Course.pdf")
' Progress events will fire during the read operation
Dim result = ocrTesseract.Read(input)Jakie informacje o postępach mogę uzyskać podczas wydarzenia?
Zdarzenie OcrProgress zapewnia kompleksowe dane o postępie, które pomagają monitorować i optymalizować wydajność OCR. Każda właściwość służy konkretnemu celowi w śledzeniu operacji:
ProgressPercent: Postęp zadania OCR jako procent ukończonych stron, w przedziale od 0 do 100. Przydatne do aktualizacji paska postępu w aplikacjach GUI.TotalPages: Całkowita liczba stron przetwarzanych przez silnik OCR. Niezbędne do obliczania szacowanych czasów zakończenia.PagesComplete: Liczba stron, na których odczyt OCR został całkowicie zakończony. Liczba ta rośnie stopniowo w miarę przetwarzania stron.Duration: Całkowity czas trwania zadania OCR, wskazujący na czas potrzebny na ukończenie całego procesu. Mierzone w formacieTimeSpani aktualizowane za każdym razem, gdy zdarzenie jest wywoływane.StartTimeUTC: Data i godzina rozpoczęcia zadania OCR, przedstawione w formacie Czasu Uniwersalnego (UTC).EndTimeUTC: Data i godzina, kiedy zadanie OCR zostało w 100% ukończone w formacie UTC. Ta właściwość ma wartość null podczas trwania procesu OCR i zostaje wypełniona po zakończeniu procesu.
Zaawansowane wdrożenie śledzenia postępów
W przypadku aplikacji produkcyjnych należy wdrożyć bardziej zaawansowane śledzenie postępów. Ten przykład obejmuje obsługę błędów i szczegółowe logowanie:
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;
}
}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;
}
}Imports IronOcr
Imports System
Imports System.Diagnostics
Public Class OcrProgressTracker
Private ReadOnly _tesseract As IronTesseract
Private _stopwatch As Stopwatch
Private _lastReportedPercent As Integer = 0
Public Sub New()
_tesseract = New IronTesseract()
' Configure for optimal performance
_tesseract.Language = OcrLanguage.EnglishBest
_tesseract.Configuration.ReadBarCodes = False
' Subscribe to progress event
AddHandler _tesseract.OcrProgress, AddressOf OnOcrProgress
End Sub
Private Sub OnOcrProgress(sender As Object, e As OcrProgressEventsArgs)
' Only report significant progress changes (every 10%)
If e.ProgressPercent - _lastReportedPercent >= 10 OrElse e.ProgressPercent = 100 Then
_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 AndAlso e.ProgressPercent < 100 Then
Dim estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0)
Dim remaining = estimatedTotal - e.Duration.TotalSeconds
Console.WriteLine($"Estimated remaining: {remaining:F1}s")
End If
Console.WriteLine("---")
End If
End Sub
Public Function ProcessDocument(filePath As String) As OcrResult
_stopwatch = Stopwatch.StartNew()
Using input As New OcrInput()
input.LoadPdf(filePath)
' Apply image filters for better accuracy
input.Deskew()
input.DeNoise()
Dim result = _tesseract.Read(input)
_stopwatch.Stop()
Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s")
Return result
End Using
End Function
End ClassImports IronOcr
Imports System
Imports System.Diagnostics
Public Class OcrProgressTracker
Private ReadOnly _tesseract As IronTesseract
Private _stopwatch As Stopwatch
Private _lastReportedPercent As Integer = 0
Public Sub New()
_tesseract = New IronTesseract()
' Configure for optimal performance
_tesseract.Language = OcrLanguage.EnglishBest
_tesseract.Configuration.ReadBarCodes = False
' Subscribe to progress event
AddHandler _tesseract.OcrProgress, AddressOf OnOcrProgress
End Sub
Private Sub OnOcrProgress(sender As Object, e As OcrProgressEventsArgs)
' Only report significant progress changes (every 10%)
If e.ProgressPercent - _lastReportedPercent >= 10 OrElse e.ProgressPercent = 100 Then
_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 AndAlso e.ProgressPercent < 100 Then
Dim estimatedTotal = e.Duration.TotalSeconds / (e.ProgressPercent / 100.0)
Dim remaining = estimatedTotal - e.Duration.TotalSeconds
Console.WriteLine($"Estimated remaining: {remaining:F1}s")
End If
Console.WriteLine("---")
End If
End Sub
Public Function ProcessDocument(filePath As String) As OcrResult
_stopwatch = Stopwatch.StartNew()
Using input As New OcrInput()
input.LoadPdf(filePath)
' Apply image filters for better accuracy
input.Deskew()
input.DeNoise()
Dim result = _tesseract.Read(input)
_stopwatch.Stop()
Console.WriteLine($"Total processing time: {_stopwatch.Elapsed.TotalSeconds:F1}s")
Return result
End Using
End Function
End ClassIntegracja śledzenia postępów z aplikacjami UI
Podczas tworzenia aplikacji desktopowych przy użyciu Windows Forms lub WPF śledzenie postępów ma kluczowe znaczenie dla komfortu użytkowania. Zdarzenie progress może bezpiecznie aktualizować elementy interfejsu użytkownika:
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 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");
}
}
}Imports System
Imports System.Windows.Forms
Imports IronOcr
Public Partial Class OcrForm
Inherits Form
Private _tesseract As IronTesseract
Private progressBar As ProgressBar
Private statusLabel As Label
Public Sub New()
InitializeComponent()
_tesseract = New IronTesseract()
AddHandler _tesseract.OcrProgress, AddressOf UpdateProgress
End Sub
Private Sub UpdateProgress(sender As Object, e As OcrProgressEventsArgs)
' Ensure UI updates happen on the main thread
If InvokeRequired Then
BeginInvoke(New Action(Sub() UpdateProgress(sender, e)))
Return
End If
progressBar.Value = e.ProgressPercent
statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}"
' Show completion message
If e.ProgressPercent = 100 Then
MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds")
End If
End Sub
End ClassImports System
Imports System.Windows.Forms
Imports IronOcr
Public Partial Class OcrForm
Inherits Form
Private _tesseract As IronTesseract
Private progressBar As ProgressBar
Private statusLabel As Label
Public Sub New()
InitializeComponent()
_tesseract = New IronTesseract()
AddHandler _tesseract.OcrProgress, AddressOf UpdateProgress
End Sub
Private Sub UpdateProgress(sender As Object, e As OcrProgressEventsArgs)
' Ensure UI updates happen on the main thread
If InvokeRequired Then
BeginInvoke(New Action(Sub() UpdateProgress(sender, e)))
Return
End If
progressBar.Value = e.ProgressPercent
statusLabel.Text = $"Processing page {e.PagesComplete} of {e.TotalPages}"
' Show completion message
If e.ProgressPercent = 100 Then
MessageBox.Show($"OCR completed in {e.Duration.TotalSeconds:F1} seconds")
End If
End Sub
End ClassPraca z dużymi dokumentami i limitami czasu
Podczas przetwarzania obszernych dokumentów śledzenie postępów staje się jeszcze bardziej cenne. Połącz to z ustawieniami limitu czasu i tokenami przerwania dla lepszej kontroli:
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);
Console.WriteLine("OCR completed successfully");
}
catch (OperationCanceledException)
{
Console.WriteLine("OCR operation was cancelled");
}
}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);
Console.WriteLine("OCR completed successfully");
}
catch (OperationCanceledException)
{
Console.WriteLine("OCR operation was cancelled");
}
}Imports IronOcr
Imports System
Imports System.Threading
Public Async Function ProcessLargeDocumentWithTimeout() As Task
Dim cts = New CancellationTokenSource()
Dim tesseract = New IronTesseract()
' Set a timeout of 5 minutes
cts.CancelAfter(TimeSpan.FromMinutes(5))
AddHandler tesseract.OcrProgress, Sub(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 AndAlso e.ProgressPercent < 50 Then
Console.WriteLine("Processing too slow, cancelling...")
cts.Cancel()
End If
End Sub
Try
Using input = New OcrInput()
input.LoadPdf("large-document.pdf")
Dim result = Await Task.Run(Function() tesseract.Read(input), cts.Token)
Console.WriteLine("OCR completed successfully")
End Using
Catch ex As OperationCanceledException
Console.WriteLine("OCR operation was cancelled")
End Try
End FunctionImports IronOcr
Imports System
Imports System.Threading
Public Async Function ProcessLargeDocumentWithTimeout() As Task
Dim cts = New CancellationTokenSource()
Dim tesseract = New IronTesseract()
' Set a timeout of 5 minutes
cts.CancelAfter(TimeSpan.FromMinutes(5))
AddHandler tesseract.OcrProgress, Sub(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 AndAlso e.ProgressPercent < 50 Then
Console.WriteLine("Processing too slow, cancelling...")
cts.Cancel()
End If
End Sub
Try
Using input = New OcrInput()
input.LoadPdf("large-document.pdf")
Dim result = Await Task.Run(Function() tesseract.Read(input), cts.Token)
Console.WriteLine("OCR completed successfully")
End Using
Catch ex As OperationCanceledException
Console.WriteLine("OCR operation was cancelled")
End Try
End FunctionNajlepsze praktyki w zakresie śledzenia postępów
- Częstotliwość aktualizacji: Zdarzenie
OcrProgressjest często wywoływane podczas przetwarzania. Rozważ filtrowanie aktualizacji, aby uniknąć przeładowania interfejsu użytkownika lub logów. - Wpływ na wydajność: Śledzenie postępu ma minimalne obciążenie wydajnościowe, ale nadmierne logowanie lub aktualizacje interfejsu mogą spowolnić proces OCR.
- Zarządzanie pamięcią: W przypadku dużych plików TIFF lub PDF należy monitorować zużycie pamięci wraz z postępem, aby zapewnić optymalną wydajność.
- Obsługa błędów: Zawsze uwzględniaj obsługę błędów w obsłudze zdarzeń postępu, aby zapobiec przerwom w procesie OCR.
- Bezpieczeństwo wątków: Podczas aktualizowania elementów interfejsu użytkownika z zdarzenia postępu, należy zapewnić właściwą synchronizację wątków, używając metod
InvokelubBeginInvoke.
Wnioski
Śledzenie postępów w IronOCR zapewnia niezbędny wgląd w operacje OCR, umożliwiając programistom tworzenie responsywnych aplikacji, które na bieżąco informują użytkowników o statusie przetwarzania. Wykorzystując efektywnie zdarzenie OcrProgress, możesz zbudować profesjonalne aplikacje, które obsługują wszystko, od dokumentów jednostronicowych po obszerne pliki PDF z pewnością.
Aby uzyskać zaawansowane techniki OCR, zapoznaj się z naszymi przewodnikami na temat filtrów obrazu i obiektów wynikowych, aby dodatkowo ulepszyć swoje implementacje OCR.
Najczęściej zadawane pytania
Co to jest zdarzenie OcrProgress w IronOCR?
Zdarzenie OcrProgress w IronOCR to system śledzenia postępów oparty na zdarzeniach, który dostarcza aktualizacje dotyczące procesu OCR, w tym procent ukończenia, przetworzone strony oraz metryki czasu w czasie rzeczywistym.
Jak mogę monitorować postępy OCR w czasie rzeczywistym za pomocą IronOCR?
Możesz monitorować postępy OCR w czasie rzeczywistym, subskrybując zdarzenie OcrProgress, które zapewnia natychmiastową informację zwrotną na temat procentu ukończenia, liczby przetworzonych stron oraz ogólnej liczby przeczytanych stron.
Jakie dane o postępach dostarcza zdarzenie OcrProgress?
Zdarzenie OcrProgress dostarcza danych o procentach ukończenia, całkowitej liczbie przetwarzanych stron, ukończonych stronach, czasie trwania zadania, czasach rozpoczęcia i zakończenia w UTC, co pomaga w śledzeniu operacji OCR.
Czy śledzenie postępów w IronOCR może być używane w operacjach asynchronicznych?
Tak, śledzenie postępów w IronOCR może być zintegrowane z operacjami asynchronicznymi, co czyni je odpowiednim do efektywnego przetwarzania dużych dokumentów.
Jak zintegrować śledzenie postępów w aplikacji Windows Forms za pomocą IronOCR?
W aplikacji Windows Forms można użyć zdarzenia OcrProgress do bezpiecznej aktualizacji elementów interfejsu użytkownika, takich jak paski postępu i etykiety, korzystając z metod Invoke lub BeginInvoke dla bezpieczeństwa wątków.
Czy istnieje zalecana częstotliwość aktualizacji OcrProgress?
Chociaż zdarzenie OcrProgress jest wywoływane często, zaleca się filtrowanie aktualizacji, aby nie przeciążać interfejsu użytkownika ani logów, co mogłoby wpłynąć na wydajność.
W jaki sposób śledzenie postępów w IronOCR może poprawić przetwarzanie dużych dokumentów?
Przy pracy z dużymi dokumentami śledzenie postępów w IronOCR pozwala na lepszą kontrolę z ustawieniami limitów czasu i tokenami anulowania, zapewniając mechanizm do efektywnego zarządzania wolnym przetwarzaniem.
Czy śledzenie postępów w IronOCR wpływa na wydajność?
Śledzenie postępów w IronOCR ma minimalny wpływ na wydajność, choć nadmierne logowanie lub aktualizacje interfejsu użytkownika oparte na zdarzeniach postępu mogą spowolnić ogólny proces OCR.
Jakie najlepsze praktyki należy stosować przy używaniu śledzenia postępów w IronOCR?
Najlepsze praktyki obejmują zarządzanie częstością aktualizacji, zapewnienie bezpieczeństwa wątków przy aktualizacji elementów interfejsu użytkownika oraz wprowadzenie obsługi błędów, aby utrzymać płynność operacji OCR.
Czy IronOCR może być używany do śledzenia postępów w środowiskach wielowątkowych?
Tak, śledzenie postępów w IronOCR można łączyć z wielowątkowością, aby zwiększyć wydajność OCR, efektywnie obsługując wiele dokumentów lub duże pliki.
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.