Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we explore how to use computer vision to detect text in images using the Iron OCR library in C#. We begin by setting up a C# console application in Visual Studio, ensuring the Iron OCR and Iron Doomu Vision packages are installed via the NuGet Package Manager. First, we import the Iron OCR library to access OCR functionalities and create an instance of the Iron Tesa class for OCR operations. We open an input image file and define an OCR input object, using computer vision to detect text regions. The Read
method of the Iron Tesa object is then used to perform OCR, storing results in a variable for display.
Below is a corrected and documented C# code snippet demonstrating this process:
// Import necessary namespaces
using IronOcr; // Namespace for Iron OCR library
class OCRExample
{
static void Main(string[] args)
{
// Create an instance of the Iron Tesseract class for handling OCR operations
var Ocr = new IronTesseract();
// Specify the path to the image file to be processed
string inputImagePath = @"C:\path\to\your\image.jpg";
// Perform OCR on the image
using (var Input = new OcrInput(inputImagePath))
{
// Detect and read the text from the image using the Read method
var Result = Ocr.Read(Input);
// Output the detected text to the console
Console.WriteLine(Result.Text);
}
}
}
// Import necessary namespaces
using IronOcr; // Namespace for Iron OCR library
class OCRExample
{
static void Main(string[] args)
{
// Create an instance of the Iron Tesseract class for handling OCR operations
var Ocr = new IronTesseract();
// Specify the path to the image file to be processed
string inputImagePath = @"C:\path\to\your\image.jpg";
// Perform OCR on the image
using (var Input = new OcrInput(inputImagePath))
{
// Detect and read the text from the image using the Read method
var Result = Ocr.Read(Input);
// Output the detected text to the console
Console.WriteLine(Result.Text);
}
}
}
' Import necessary namespaces
Imports IronOcr ' Namespace for Iron OCR library
Friend Class OCRExample
Shared Sub Main(ByVal args() As String)
' Create an instance of the Iron Tesseract class for handling OCR operations
Dim Ocr = New IronTesseract()
' Specify the path to the image file to be processed
Dim inputImagePath As String = "C:\path\to\your\image.jpg"
' Perform OCR on the image
Using Input = New OcrInput(inputImagePath)
' Detect and read the text from the image using the Read method
Dim Result = Ocr.Read(Input)
' Output the detected text to the console
Console.WriteLine(Result.Text)
End Using
End Sub
End Class
The tutorial also covers using the Crop Rectangle class to focus on identified text regions, applying a red stamp for visual inspection, and further processing with the Read
method. Additionally, we demonstrate detecting multiple text regions, dividing input into separate images, and using the GetTextRegions
method for comprehensive text extraction. With the right settings and input files, Iron OCR combined with computer vision can become a potent tool for text detection. The tutorial concludes by encouraging viewers to download a trial version of Iron OCR for further exploration.
Further Reading: How to use Computer Vision to Find Text