OCR with Barcode & QR Reading
The Iron Tesseract OcrResult
object can read barcodes and QR Codes during OCR if you set Ocr.Configuration.ReadBarCodes = true;
.
This is just one of Iron Software's valuable additions to the vanilla/free Tesseract functionality.
How to do OCR on your QR Code
- Install the C# library to perform OCR with QR Code
- Instantiate an
IronTesseract
object and set theReadBarCodes
field to true. - Import the targeted image or PDF containing the QR Code.
- Perform OCR on the image or PDF using the
Read
method. - View all QR Code values in the
Barcodes
property.
Here's a basic example in C# demonstrating how to perform OCR on QR Codes:
using IronOcr;
namespace QrCodeOcrExample
{
class Program
{
static void Main(string[] args)
{
// Create an IronTesseract object
var Ocr = new IronTesseract();
// Configure the Ocr object to read barcodes including QR Codes
Ocr.Configuration.ReadBarCodes = true;
// Specify the path to the image or PDF containing the QR Codes
var inputFilePath = "path/to/your/image-or-pdf-file";
// Perform OCR to extract text and barcodes
using (var OcrInput = new OcrInput(inputFilePath))
{
// Read the content from the input file
var results = Ocr.Read(OcrInput);
// Display the QR Code values found in the image or PDF
foreach (var barcode in results.Barcodes)
{
Console.WriteLine("QR Code Value: " + barcode.Value);
}
}
}
}
}
using IronOcr;
namespace QrCodeOcrExample
{
class Program
{
static void Main(string[] args)
{
// Create an IronTesseract object
var Ocr = new IronTesseract();
// Configure the Ocr object to read barcodes including QR Codes
Ocr.Configuration.ReadBarCodes = true;
// Specify the path to the image or PDF containing the QR Codes
var inputFilePath = "path/to/your/image-or-pdf-file";
// Perform OCR to extract text and barcodes
using (var OcrInput = new OcrInput(inputFilePath))
{
// Read the content from the input file
var results = Ocr.Read(OcrInput);
// Display the QR Code values found in the image or PDF
foreach (var barcode in results.Barcodes)
{
Console.WriteLine("QR Code Value: " + barcode.Value);
}
}
}
}
}
Imports IronOcr
Namespace QrCodeOcrExample
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Create an IronTesseract object
Dim Ocr = New IronTesseract()
' Configure the Ocr object to read barcodes including QR Codes
Ocr.Configuration.ReadBarCodes = True
' Specify the path to the image or PDF containing the QR Codes
Dim inputFilePath = "path/to/your/image-or-pdf-file"
' Perform OCR to extract text and barcodes
Using OcrInput As New OcrInput(inputFilePath)
' Read the content from the input file
Dim results = Ocr.Read(OcrInput)
' Display the QR Code values found in the image or PDF
For Each barcode In results.Barcodes
Console.WriteLine("QR Code Value: " & barcode.Value)
Next barcode
End Using
End Sub
End Class
End Namespace
Detailed Steps
- Install IronOcr Library: First, ensure the IronOcr library is installed via NuGet for access to advanced OCR capabilities.
- Instantiating IronTesseract: Create an instance of the
IronTesseract
class to handle OCR processes. - Configuring for Barcode Reading: Set the
ReadBarCodes
configuration totrue
on theOcr
object to enable reading of barcodes and QR codes during OCR operations. - Input Setup: Use
OcrInput
to load your image or PDF that contains QR Codes. - Perform OCR: Call the
Read
method on theOcr
object to perform OCR which will also extract QR Code data. - View QR Code Values: Iterate over the
Barcodes
property of the result to access and display the values of any QR Codes detected.
This process effectively allows you to extract and utilize information encoded in QR Codes using the IronOcr library in a C# application.