ImageGear .NET
Import Images to OCR

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.

C#
Copy Code
C#
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.Recognition;
public void RecognizingFile(string fileToBeRecognizedPath, string outputfilePath)
{
    ImGearRecognition igRecognition = new ImGearRecognition();
    ImGearPage igPage;
    using (FileStream localFile = new FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read))
        igPage = ImGearFileFormats.LoadPage(localFile, 0);
    ImGearRecPage igRecPage = igRecognition.ImportPage((ImGearRasterPage)igPage);
    igRecognition.OutputManager.CodePage = "Windows ANSI";
    igRecognition.OutputManager.Level = ImGearRecOutputLevel.NOFORMAT;
    igRecognition.OutputManager.Format = "Converters.Text.Text";
    igRecPage.Recognize();
    ImGearRecDocument document = igRecognition.OutputManager.CreateDocument(null);
    document.InsertPage(igRecPage, -1);
    igRecognition.OutputManager.WriteDocument(document, outputfilePath);
    // Dispose document. You must explicitly call this method before calling igRecognition.Dispose()
    // whenever you create document.
    document.Dispose();
    igRecognition.Dispose();
}
VB.NET
Copy Code
VB.NET
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.Recognition
Public Sub RecognizingFile(fileToBeRecognizedPath As String, outputfilePath As String)
    Dim igRecognition As New ImGearRecognition()
    Dim igPage As ImGearPage
    Using localFile As New FileStream(fileToBeRecognizedPath, FileMode.Open, FileAccess.Read)
        igPage = ImGearFileFormats.LoadPage(localFile, 0)
    End Using
    Dim igRecPage As ImGearRecPage = igRecognition.ImportPage(DirectCast(igPage, ImGearRasterPage))
    igRecognition.OutputManager.CodePage = "Windows ANSI"
    igRecognition.OutputManager.Level = ImGearRecOutputLevel.NOFORMAT
    igRecognition.OutputManager.Format = "Converters.Text.Text"
    igRecPage.Recognize()
    Dim document As ImGearRecDocument = igRecognition.OutputManager.CreateDocument(Nothing)
    document.InsertPage(igRecPage, -1)
    igRecognition.OutputManager.WriteDocument(document, outputfilePath)
    ' Dispose document. You must explicitly call this method before calling igRecognition.Dispose()
    ' whenever you create document.
    document.Dispose()
    igRecognition.Dispose()
End Sub

 

 


©2016. Accusoft Corporation. All Rights Reserved.

Send Feedback