ImageGear .NET - Updated
Load and Import Images
User Guide > How to Work with... > OCR > How to... > Load and Import Images

The Recognition engine uses its own internal image storage. To supply recognition engine with input data, you should first load an image to ImageGear storage (ImGearPage). You can load images from any ImageGear supported image location, such as file, URL, or memory, or retrieve images from a scanner. Then you can import the image into Recognition image storage (ImGearRecPage Class). Use the ImGearRecognition.ImportPage Method for this.

If the source ImGearPage contains a grayscale image, the import method can convert the imported image to a bitonal one. If the source ImGearPage contains a color image, the import method can convert the imported image to grayscale or bitonal. The way this method will handle the different image types (such as bitonal, grayscale, or color images) is called the primary color reduction mode. The reduction mode applied during the execution of this method is specified by the ImGearRecPreprocessingSettings.PrimaryReductionMode Property.

Use the ImGearRecImage.Export Method to export the pixel data from ImGearRecPage Class to ImGearPage.

Pixel data is copied into ImGearRecPage Class object rather than shared between ImGearPage and ImGearRecPage Class. If you perform some preprocessing operation on the recognition page, and would like to access the modified image, for example, in order to display it, you'll need to export the image to an ImGearPage.

This code demonstrates loading and recognizing the TEST1.TIF image file. The image contains English, machine-printed text. The result will be saved in the TEST1.TXT text file.

Copy Code
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.Recognition;
public void RecognizeFile(string fileToBeRecognizedPath, string outputfilePath)
    ImGearPage igPage;
    using (FileStream localFile = new FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read))
        igPage = ImGearFileFormats.LoadPage(localFile, 0);
    using (ImGearRecognition igRecognition = new ImGearRecognition())
    using (ImGearRecPage igRecPage = igRecognition.ImportPage(igPage as ImGearRasterPage))
        File.WriteAllText(outputfilePath, igRecPage.Text);
Copy Code
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.Recognition
Public Sub RecognizeFile(fileToBeRecognizedPath As String, outputfilePath As String)
    Dim igPage As ImGearPage
    Using localFile As New FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read)
        igPage = ImGearFileFormats.LoadPage(localFile, 0)
    End Using
    Using igRecognition As New ImGearRecognition(), _
        igRecPage As ImGearRecPage = igRecognition.ImportPage(DirectCast(igPage, ImGearRasterPage))
        File.WriteAllText(outputFile, igRecPage.Text)
    End Using
End Sub