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 video tutorial, viewers learn how to perform Optical Character Recognition (OCR) in C# using the Iron OCR library. The tutorial begins by setting up the necessary environment, including installing the Iron OCR package and setting the license key. It guides users through the process of importing required namespaces and instantiating an IronTesseract
object, which is crucial for performing OCR on images.
The tutorial demonstrates how to read text from an image file named 'label.png' by using an OCR image input class. It explains the read method, which processes the image and extracts text, subsequently printing it to the console.
The tutorial also shows how to handle images stored as byte arrays, which is useful when images are sourced from streams or other non-file inputs. It further discusses performing OCR on a specific region of an image by defining the area with coordinates and dimensions, enabling selective text extraction. The video concludes with a demonstration of the tutorial's examples, showing outputs of extracted text from full images, byte arrays, and specified regions. Viewers are encouraged to integrate these techniques into their projects to enhance OCR capabilities. The tutorial ends with a call to action, inviting viewers to download the Iron OCR package and explore its features.
Here is an example code that demonstrates the key concepts from the tutorial:
// Import the Iron OCR library
using IronOcr;
class Program
{
static void Main()
{
// Instantiate the IronTesseract class
var Ocr = new IronTesseract();
// Set the license key for Iron OCR
Ocr.LicenseKey = "YOUR_LICENSE_KEY_HERE";
// Perform OCR on a full image file
using (var Input = new OcrInput(@"label.png"))
{
// Read the text from the image
var Result = Ocr.Read(Input);
// Print the extracted text to the console
Console.WriteLine(Result.Text);
}
// Example of performing OCR on an image stored as a byte array
byte[] imageBytes = System.IO.File.ReadAllBytes("label.png");
using (var Input = new OcrInput(imageBytes))
{
// Read the text from the byte array image
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
// Perform OCR on a specific region within an image
using (var Input = new OcrInput(@"label.png"))
{
// Define the specific region of interest
Input.AddRegion(new System.Drawing.Rectangle(0, 0, 100, 100));
// Read text from the defined region
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
}
}
// Import the Iron OCR library
using IronOcr;
class Program
{
static void Main()
{
// Instantiate the IronTesseract class
var Ocr = new IronTesseract();
// Set the license key for Iron OCR
Ocr.LicenseKey = "YOUR_LICENSE_KEY_HERE";
// Perform OCR on a full image file
using (var Input = new OcrInput(@"label.png"))
{
// Read the text from the image
var Result = Ocr.Read(Input);
// Print the extracted text to the console
Console.WriteLine(Result.Text);
}
// Example of performing OCR on an image stored as a byte array
byte[] imageBytes = System.IO.File.ReadAllBytes("label.png");
using (var Input = new OcrInput(imageBytes))
{
// Read the text from the byte array image
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
// Perform OCR on a specific region within an image
using (var Input = new OcrInput(@"label.png"))
{
// Define the specific region of interest
Input.AddRegion(new System.Drawing.Rectangle(0, 0, 100, 100));
// Read text from the defined region
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
}
}
Further Reading: How to Read from Streams