ImageGear PDF v25.2 - Updated
Work with Zones
Developer Guide > How to Work with... > OCR > How to... > Work with Zones

A zone is a rectangular area in the image, up to full size, containing a feature of interest to the user. The image data covered by each zone is handled and processed (and typically recognized) separately, according to zone-specific parameters. The zones of an ImGearOCR Class image form a list, the zone list, which is attached to the image. The zone list can be examined at any time with the Zones Property of ImGearOCRPage Class.

Zones can be added to a given image (to the zone list of the image, to be precise) in three different ways:

Manually

In addition to, or instead of the automatic zone search, you can program your own zones by specifying the zone coordinates. For adding zones to the zone list manually, the application calls the Add Method of ImGearOCRZoneCollection Class. Related methods are: Insert Method, Remove Method, RemoveAt Method, and Clear Method.

C#
Copy Code
public static string RecognizeZone(ImGearRasterPage rasterPage, int left, int right, int top, int bottom)
{
    string resultString = null;

    ImGearOCRZone zone = new ImGearOCRZone();
    zone.Rect.Left = left;
    zone.Rect.Top = top;
    zone.Rect.Right = right;
    zone.Rect.Bottom = bottom;

    // Initialization of ImGearOCR by default.
    using (ImGearOCR igOcr = ImGearOCR.Create())
    {
        // Import ImageGear page to recognition repository.
        using (ImGearOCRPage igOcrPage = igOcr.ImportPage(rasterPage))
        {
            // Add a zone of interest.
            igOcrPage.Zones.Add(zone);

            // Recognize image.
            igOcrPage.Recognize();

            // Get result text.
            resultString = igOcrPage.Text;
        }
    }

    return resultString;
}
VB.NET
Copy Code
Public Shared Function RecognizeZone(ByVal rasterPage As ImGearRasterPage, ByVal left As Integer, ByVal right As Integer, ByVal top As Integer, ByVal bottom As Integer) As String
    Dim resultString As String = Nothing
    Dim zone As ImGearOCRZone = New ImGearOCRZone()
    zone.Rect.Left = left
    zone.Rect.Top = top
    zone.Rect.Right = right
    zone.Rect.Bottom = bottom

    ' Initialization of ImGearOCR by default.
    Using igOcr As ImGearOCR = ImGearOCR.Create()

        ' Import ImageGear page to recognition repository.
        Using igOcrPage As ImGearOCRPage = igOcr.ImportPage(rasterPage)

            ' Add a zone of interest.
            igOcrPage.Zones.Add(zone)

            ' Recognize image.
            igOcrPage.Recognize()

            ' Get result text.
            resultString = igOcrPage.Text
        End Using
    End Using

    Return resultString
End Function

From a File

The second way of creating zones is by reading zones from a file (called a zone file) that contains the attributes of previously saved zones. An application can save the current zone definitions to a zone file any time with the ImGearOCRZoneCollection.SaveToFile Method. The application can load them from a zone file with the LoadFromFile Method.

When a zone file is loaded, any previous zones on the image are removed.

If the application calls the ImGearOCRPage.Recognize Method on an image with an empty zone list, then full page recognition is performed. 

Automatically

The automatic page-layout decomposition process (auto-zoning) can be activated directly by calling the ImGearOCRPage.LocateZones Method for finding text blocks on the image. It creates an entire zone list for the given image.

The LocateZones Method has an overload that takes an ImGearRectangle as a parameter. This rectangle serves to limit the area of the image inside which zones will be searched and defined.

When automatic zone location is performed, any previous zones on the image are removed.
C#
Copy Code
using (ImGearOCRPage igOcrPage = igOcr.ImportPage((ImGearRasterPage)igPage))
  {
  // Finds blocks of text on the image and creates a zone for each block.
  recognitionPage.LocateZones();
  // Perform recognition.
  recognitionPage.Recognize();                  
}
VB.NET
Copy Code
Using igOcrPage As ImGearOCRPage = igOcr.ImportPage(DirectCast(igPage, ImGearRasterPage))
' Finds blocks of text on the image and creates a zone for each block.
recognitionPage.LocateZones()                 
' Perform recognition.
recognitionPage.Recognize()
End Using
Is this page helpful?
Yes No
Thanks for your feedback.