Read Scanned Document

This code example demonstrates how to use the IronTesseract OCR (Optical Character Recognition) engine to extract text from an image.

// Import the necessary namespaces
using IronOcr;

class Program
{
    static void Main()
    {
        // Create an instance of the IronTesseract OCR engine
        var Ocr = new IronTesseract();

        // Initialize an OcrInput object and load the image that contains the text to be recognized
        using (var Input = new OcrInput("potter.tiff"))
        {
            // Perform the OCR recognition process on the loaded image
            var Result = Ocr.Read(Input);

            // Print the recognized text to the console
            Console.WriteLine(Result.Text);
        }
    }
}
// Import the necessary namespaces
using IronOcr;

class Program
{
    static void Main()
    {
        // Create an instance of the IronTesseract OCR engine
        var Ocr = new IronTesseract();

        // Initialize an OcrInput object and load the image that contains the text to be recognized
        using (var Input = new OcrInput("potter.tiff"))
        {
            // Perform the OCR recognition process on the loaded image
            var Result = Ocr.Read(Input);

            // Print the recognized text to the console
            Console.WriteLine(Result.Text);
        }
    }
}
' Import the necessary namespaces
Imports IronOcr

Friend Class Program
	Shared Sub Main()
		' Create an instance of the IronTesseract OCR engine
		Dim Ocr = New IronTesseract()

		' Initialize an OcrInput object and load the image that contains the text to be recognized
		Using Input = New OcrInput("potter.tiff")
			' Perform the OCR recognition process on the loaded image
			Dim Result = Ocr.Read(Input)

			' Print the recognized text to the console
			Console.WriteLine(Result.Text)
		End Using
	End Sub
End Class
$vbLabelText   $csharpLabel

Explanation:

  1. Namespace Import: The using IronOcr; directive includes the IronOcr library which provides the necessary OCR classes.
  2. Create OCR Engine Instance: var Ocr = new IronTesseract(); initializes an IRON Tesseract OCR engine that will be used to process images.
  3. Load Image: using (var Input = new OcrInput("potter.tiff")) loads the image file "potter.tiff" into an OcrInput object which is required for OCR processing. The using statement ensures that resources are managed properly.
  4. OCR Processing: var Result = Ocr.Read(Input); calls the Read method to process the loaded image, leveraging OCR technology to recognize and convert text within the image.
  5. Output Recognized Text: Console.WriteLine(Result.Text); outputs the recognized text to the console, making the text accessible for further processing or display.

This process allows for the extraction of readable text from image files programmatically using the advanced capabilities of the IronTesseract OCR engine.