LBitmap::AutoZone

#include "ltwrappr.h"

L_INT LBitmap::AutoZone(phZones, puCount, uFlags = 0)

HGLOBAL * phZones;

/* pointer of a handle to be updated with the detected zones */

L_UINT32 * puCount;

/* the count of detected zones */

L_UINT32 uFlags;

/* flags */

Detects different zone types (Text, Graphic and Table) in an image automatically. This is an important feature for OCR pre-processing to improve the recognition results. This function is useful for any application that needs to automatically separate images, tables and text within mixed raster content (MRC) images.

Parameter

Description

phZones

Pointer to a handle to be updated with the detected zones. To retrieve data of the detected zones cast the phZones to pLEADZONE and call GlobalLock function.

puCount

Pointer to a variable to be updated with the number of detected zones.

uFlags

Flags that indicate the detection behavior of the function. The following flags indicate the type of zones to be detected. You can combine values when appropriate by using a bitwise OR ( | ). Possible values are:

 

Value

Meaning

 

AUTOZONE_DETECT_TEXT

[0x0001] Detects text zones.

 

AUTOZONE_DETECT_GRAPHIC

0x0002] Detects graphic zones.

 

AUTOZONE_DETECT_TABLE

[0x0004] Detects table zones.

 

AUTOZONE_DETECT_ALL

[0x0007] Detects all zone types (Text, Graphics and tables).

 

Flags indicate whether to allow overlapping among zones:

 

Value

Meaning

 

AUTOZONE_DONT_ALLOW_OVERLAP

[0x0000] Don't allow zones to overlap.

 

AUTOZONE_ALLOW_OVERLAP

[0x0010] Allow zones to overlap.

 

Flags indicate the merging type among text zones:

 

Value

Meaning

 

AUTOZONE_ACCURATE_ZONES

[0x0000] Don't merge text zones and keep them separated (paragraphs).

 

AUTOZONE_GENERAL_ZONES

[0x0100] Merge text zones to the maximum.

 

Flags indicate the table zones detection options:

 

Value

Meaning

 

AUTOZONE_DONT_RECOGNIZE_ONE_CELL_TABLE

[0x0000] Ignore one-cell tables (borders), and detect what inside.

 

AUTOZONE_RECOGNIZE_ONE_CELL_TABLE

[0x1000] Consider borders as one-cell tables.

 

Flags indicate whether to use multi-threading:

 

Value

Meaning

 

AUTOZONE_USE_MULTITHREADING

[0x00000000] Use multi-threading (that will be faster with a multi-core CPUs).

 

AUTOZONE_DONTUSE_MULTITHREADING

[0x80000000] Don't Use multi-threading (that will be used with a single-core CPUs).

 

Flags indicate the table detection method:

 

Value

Meaning

 

AUTOZONE_NORMAL_TABLE

[0x0000] Use normal table detection.

 

AUTOZONE_ADVANCED_TABLE

[0x2000] Use advanced table detection to obtain more accurate results and detect complex tables.

 

AUTOZONE_LINES_RECONSTRUCTION

[0x4000] Use lines reconstruction to connect broken lines and for patterned tables.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

After using this function the phZones should be freed using the LBitmap::FreeZoneData function.

This function does not support 12 and 16-bit grayscale and 48 and 64-bit color images. If the image is 12 and 16-bit grayscale and 48 and 64-bit color, the function will not return an error.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

The behavior of this function can be modified by overriding LBitmap::AutoZoneCallback.

Required DLLs and Libraries

LTIMGCOR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

LBitmap::AutoZoneCallback, LBitmap::FreeZoneData, Class Members

Topics:

Raster Image Functions: Document Imaging

Raster Image Functions: Processing an Image

Example

Detects the image zones and return the results.

//#if defined (LEADTOOLS_V17_OR_LATER)


L_INT LBitmap__AutoZoneBitmapExample(LBitmap & LeadBitmap) {
   L_INT nRet;
   HGLOBAL pointer = NULL;
   L_UINT32 count;
   L_INT TextZonesCount = 0;
   L_INT GraphicZonesCount = 0;
   L_INT TableZonesCount = 0;
   L_INT CellsCount = 0;
   L_UINT i;
   nRet = LeadBitmap.Load(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 17\\Images\\Clean.tif"));
   if(nRet !=SUCCESS)
      return nRet;
   nRet = LeadBitmap.AutoZone(&pointer, &count, 0);
   if(nRet !=SUCCESS)
      return nRet;
   LEADZONE * pZone = (LEADZONE *)GlobalLock(pointer);
   for(i=0; i<count; i++)
   {
      if (pZone[i].uZoneType == LEAD_ZONE_TYPE_TEXT)
      {
         TextZonesCount++;
      }
      if (pZone[i].uZoneType == LEAD_ZONE_TYPE_GRAPHIC)
      {
         GraphicZonesCount++;
      }
      if (pZone[i].uZoneType == LEAD_ZONE_TYPE_TABLE)
      {
         TableZonesCount++;
         TABLEZONE * pTable = (TABLEZONE *)GlobalLock(pZone[i].pZoneData);
         CellsCount = pTable->Rows * pTable->Columns;
         GlobalUnlock(pTable);
      }
   }       
   nRet = LeadBitmap.FreeZoneData(pointer, count);
   if(nRet !=SUCCESS)
      return nRet;
   GlobalUnlock(pointer);
   return SUCCESS;
}
//#endif // LEADTOOLS_V17_OR_LATER