OCR Progress and Performance Tracking
The IronTesseract
object has an OcrProgress
event that can be used to track OCR progress. We can track progress using the OcrProgressEventArgs
object sent to this event after any page of OCR text has finished reading.
This is useful in GUI applications, Web Applications, and CLI alike to keep users informed of how long they may need to wait.
How to Track OCR Progress and Performance
- Install an OCR library for OCR performance and progress tracking.
- Build an
IronTesseract
object. - Verify progress using a
OcrProgress
instance. - Add the necessary Tesseract parameters and the photo path into the object.
- Apply all necessary image-processing methods.
- Use the Read method to read text from a
OcrInput
object.
using IronOcr;
using System;
class OcrExample
{
public static void Main()
{
// Instantiation of the IronTesseract object to perform OCR
var Ocr = new IronTesseract();
// Event handler to track progress of the OCR process
Ocr.OcrProgress += OcrProgressHandler;
// Define the input image for OCR
var Input = new OcrInput(@"path\to\image.png");
// Apply necessary image processing methods (e.g., deskewing)
Input.Deskew(); // Example function to deskew the image
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Output recognized text to console
Console.WriteLine(Result.Text);
}
// Handler for the OcrProgress event
private static void OcrProgressHandler(object sender, OcrProgressEventArgs e)
{
// Display the progress percentage in console
Console.WriteLine($"OCR Progress: {e.Progress}%");
}
}
using IronOcr;
using System;
class OcrExample
{
public static void Main()
{
// Instantiation of the IronTesseract object to perform OCR
var Ocr = new IronTesseract();
// Event handler to track progress of the OCR process
Ocr.OcrProgress += OcrProgressHandler;
// Define the input image for OCR
var Input = new OcrInput(@"path\to\image.png");
// Apply necessary image processing methods (e.g., deskewing)
Input.Deskew(); // Example function to deskew the image
// Perform OCR on the input image
var Result = Ocr.Read(Input);
// Output recognized text to console
Console.WriteLine(Result.Text);
}
// Handler for the OcrProgress event
private static void OcrProgressHandler(object sender, OcrProgressEventArgs e)
{
// Display the progress percentage in console
Console.WriteLine($"OCR Progress: {e.Progress}%");
}
}
Imports IronOcr
Imports System
Friend Class OcrExample
Public Shared Sub Main()
' Instantiation of the IronTesseract object to perform OCR
Dim Ocr = New IronTesseract()
' Event handler to track progress of the OCR process
AddHandler Ocr.OcrProgress, AddressOf OcrProgressHandler
' Define the input image for OCR
Dim Input = New OcrInput("path\to\image.png")
' Apply necessary image processing methods (e.g., deskewing)
Input.Deskew() ' Example function to deskew the image
' Perform OCR on the input image
Dim Result = Ocr.Read(Input)
' Output recognized text to console
Console.WriteLine(Result.Text)
End Sub
' Handler for the OcrProgress event
Private Shared Sub OcrProgressHandler(ByVal sender As Object, ByVal e As OcrProgressEventArgs)
' Display the progress percentage in console
Console.WriteLine($"OCR Progress: {e.Progress}%")
End Sub
End Class
Code Explanation
- IronOcr Library: The script begins by importing the
IronOcr
library, which is necessary for OCR operations. - Main Method:
- Create an instance of
IronTesseract
, the main object used for OCR tasks. - Attach an event handler
OcrProgressHandler
to listen for progress updates during the OCR process. - Create an
OcrInput
object by specifying the path to the image file that needs processing. - Optionally apply image processing like deskewing to improve OCR accuracy.
- Call the
Read
method on theIronTesseract
object with theOcrInput
to process the image and extract text. - The resulting recognized text is printed to the console.
- Create an instance of
- OcrProgressHandler Method:
- This function is triggered during the OCR process, providing updates on the completion percentage of the OCR operation.
- The current progress is printed to the console, keeping the user informed about the OCR progress in real-time.