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.

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
$vbLabelText   $csharpLabel

Detailed Steps

  1. Install IronOcr Library: First, ensure the IronOcr library is installed via NuGet for access to advanced OCR capabilities.
  2. Instantiating IronTesseract: Create an instance of the IronTesseract class to handle OCR processes.
  3. Configuring for Barcode Reading: Set the ReadBarCodes configuration to true on the Ocr object to enable reading of barcodes and QR codes during OCR operations.
  4. Input Setup: Use OcrInput to load your image or PDF that contains QR Codes.
  5. Perform OCR: Call the Read method on the Ocr object to perform OCR which will also extract QR Code data.
  6. 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.