SimpleOCR:SDK Functions – OCRSetOutputHandler

OCROutputHandler OCRSetOutputHandler(OCROutputHandler handler)

When the output mode is OM_TEXT or OM_RICHTEXT, a user defined function of type OCROutputHandler will be called by the OCR engine for each “OCR event”.

Return Value

Previously selected output handler.

Parameters

handler

New OCR Output handler function.

Comments

If the output mode is OT_TEXT, OCR events among OT_PROP, OT_ITAL, OT_UNDS, OT_SIZE, OT_HILT and OT_BITM are not sent to the output hander.

An OCROutputHandler has the following form:

void AnOCRHandler(int event, int param);

with event, the code of the “OCR event” and param a value associated with the event.

The OCR events are:

OT_TEXT

A character has been recognized. param contains the ASCII code of the recognized character.

OT_PROP

The font type has changed (proportional or non proportional font). param is nonzero if the font is proportional.

OT_ITAL

Switches italic mode on or off. param is nonzero if the following characters are italic.

OT_UNDS

Switches underscored mode on or off. param is nonzero if the following characters are underscored.

OT_SIZE

Changes the character size. param contains the font size for the following characters.

OT_HILT

Changes the character color.
If param contains 1, the following word is not in the dictionary. If param contains 2, the following word has not been well recognized.

OT_ENDL

An end of line has been reached.

OT_ENDZ

An end of text area has been reached.

OT_BITM

An image […]

2020-11-11T18:59:44-05:00Tags: |

SimpleOCR:SDK Functions – OCROnArea2

int OCROnArea2(const IMG * img, int noisy, int startprogress, int endprogress)

This function is similar to OCROnArea but allows you to give starting and ending values for the progress percentage. It is useful when you want to have to display a progress bar when processing several areas.

Return Value

A non zero error code if the function fails.

Parameters

img

A pointer to the image to process.

noisy

A non zero value if the image is noisy (i.e. contains a lot of speckles)

startprogress

Starting value for the progress percentage.

endprogress

Ending value for the progress percentage.

2020-11-11T18:53:41-05:00Tags: |

SimpleOCR:SDK Functions – OCROnArea

int OCROnArea(const IMG * img, int noisy)

Recognizes the text located in an image that contains a unique text area. This function doesn’t do any layout analysis on the area. The image containing the area is usually extracted from a page with ExtractImgArea.

Return Value

A non zero error code if the function fails.

Parameters

img

A pointer to the image to process.

noisy

A non zero value if the image is noisy (i.e. contains a lot of speckles)

2020-11-11T18:48:35-05:00Tags: |

SimpleOCR:SDK Functions – LoadMultipleImg

SETOFIMG * LoadMultipleImg(const char * filename)

Loads a set of images from a TIFF file.

Return Value

A pointer to the loaded set or NULL if the function fails.

Parameters

filename

TIFF file name.

Comments

When you don’t need the set anymore, you have to free it by calling the FreeMultipleImg function. If your TIFF files contain only one image, you should use LoadImg.

Example

SETOFIMG *set; 
set=LoadMultipleImg("foo.tif"); 

if (set==NULL) 
{
// error processing
}
2020-11-11T18:37:57-05:00Tags: |

SimpleOCR:SDK Functions – LoadImg

IMG * LoadImg(const char * filename)

Loads an image from a TIFF file.

Return Value

A pointer to the loaded image or NULL if the function fails.

Parameters

filename

TIFF file name

Comments

When you don’t need the loaded image anymore, you have to free it by calling the FreeImg function. If you load a multiple image TIFF file, only the first image stored in the file is loaded. You have to use LoadMultipleImg for handling multiple image files.

Example

IMG *img; 
img=LoadImg("foo.tif"); 

if (img==NULL) 
{
// error processing
}
2020-11-11T18:32:42-05:00Tags: |

SimpleOCR:SDK Functions – InvertImg

int InvertImg(IMG * img)

Inverts an image (black pixels becomes white and white pixels becomes black)

Return Value

If the function fails a nonzero error code is returned.

Parameters

img

Pointer to an image of type IMG.

Example

IMG *img; 

// Create an IMG 
... 

if (InvertImg(img)) 
{
//error processing 
...
}
2020-11-11T18:29:16-05:00Tags: |

SimpleOCR:SDK Functions – InsertImage

int InsertImage(SETOFIMG * set, int index, IMG * image)

Inserts an image in a set of image at a given position.

Return Value

If the function fails, a nonzero value is returned.

Parameters

set

A pointer to a set of images of type SETOFIMG.

index

Position of the inserted image, counted from 0.

image

Inserted image.

Example

SETOFIMG *doc; 
IMG *img; 
int nb; 

// Creates an image in img 
... 

// Creates a set 
... 

// Insert the image at the first position 
if (InsertImage(set,0,img)) 
{
// error processing 
...
}
2020-11-11T18:20:55-05:00Tags: , , |

SimpleOCR:SDK Functions – HalfSizeImg

IMG * HalfSizeImg(IMG * img)

Shrinks a bi-level image at 50% of the original size and returns the result in a grayscale image.

Return Value

A pointer to a new IMG object. If the function fails, the return value is NULL.

Parameters

img

Pointer to an image of type IMG.

Comments

The original image is left unchanged. If you don’t need it anymore, you have to free it by calling the FREEIMG function. This function is mainly useful when you want to display a reduced bi-level image with a good display quality.

Example

IMG *img,img2; 

// Create an IMG 
... 
img2=HalfSizeImg(img); 

if (img2==NULL) 
{
// Error processing 
...
}
2020-11-11T18:15:17-05:00Tags: |

SimpleOCR:SDK Functions – GetNbImages

int GetNbImages(const SETOFIMG * set)

Returns the number of images that a set of images contains.

Return Value

The number of images in the set

Parameters

set

A pointer to a set of images of type SETOFIMG.

Example

SETOFIMG *doc; 
int nb; 

// Creates a set of images 
... 
nb=GetNbImages(set);
2020-11-11T17:56:02-05:00Tags: |

SimpleOCR:SDK Functions – GetImgSize

void GetImgSize(const IMG * img, int * pw, int * ph)

This function allows you to get the size of an image, given in pixels.

Return Value

None

Parameters

img

Pointer to an image of type IMG.

pw

Pointer to an integer that will contain the image width in pixels

ph

Pointer to an integer that will contain the image height in pixels

Example

The following example retrieves an image size

IMG *img; 
int width,height; 

// Create an IMG 
... 
GetImgSize(img,&width,&height);
2020-11-11T17:07:51-05:00Tags: |

SimpleOCR:SDK Functions – GetImgRes

void GetImgRes(const IMG * img, int * pw, int * ph)

This function allows you to get the horizontal and vertical resolution of an image

Return Value

None

Parameters

img

Pointer to an image of type IMG.

pw

Pointer to an integer that will contain the image horizontal resolution, given in Dots Per Inch (DPI).

ph

Pointer to an integer that will contain the image vertical resolution, given in DPI.

Example

IMG *img; 
int HorzRes,VertRes; 

// Create an IMG 
... 
GetImgRes(img,&HorzRes,&VertRes);
2020-11-11T17:00:32-05:00Tags: |

SimpleOCR:SDK Functions – GetImgBitmapInfo

LPBITMAPINFO GetImgBitmapInfo(const IMG * img)

This function gets a pointer to the BITMAPINFO structure corresponding to the image.

Return Value

A pointer to a BITMAPINFO structure.

Parameters

img

Pointer to an image of type IMG.

Comments

See your Windows SDK documentation for obtaining information about the BITMAPINFO structure and how to use it.

Example

IMG *img; 
LPBITMAPINFO lpbi; 

// Create an IMG 
... 
lpbi=GetImgBitmapInfo(img);
2020-11-11T12:20:09-05:00Tags: |

SimpleOCR:SDK Functions – GetImgBitmap

unsigned char * GetImgBitmap(const IMG * img)

This function gets a pointer to the bitmap corresponding to the image. The bitmap is organized like a Device Independent Bitmap (DIB)

Return Value

A pointer to the bitmap that encodes the image.

Parameters

img

Pointer to an image of type IMG.

Comments

See your Windows SDK documentation for obtaining information about Device Independent Bitmaps and how to use it.

Example

IMG *img; 
unsigned char *bitmap; 

// create an IMG 
... 
bitmap=GetImgBitmap (img);
2020-11-11T11:43:12-05:00Tags: |

SimpleOCR:SDK Functions – GetImage

IMG * GetImage(const SETOFIMG * set, int index)

Gets a pointer to a given image in a set of images.

Return Value

A pointer to the image of order index in the set.

Parameters

set

A pointer to a set of images of type SETOFIMG

index

Order of the image you want to access. The first image is at index 0.

Example

SETOFIMG *doc; 
IMG *img; 
int nb; 

// Creates a set of images 
... 

// Let's get the last image 
img=GetImage(set,(set)-1);
2020-11-11T11:27:52-05:00Tags: |

SimpleOCR:SDK Functions – FreeMultipleImg

void FreeMultipleImg(SETOFIMG * set)

Frees a set of images. All the images in the set are also freed.

Return Value

An empty set of images or NULL if the function fails.

Parameters

set

A set of images of type SETOFIMG

Example

SETOFIMG *doc; 
doc=CreateMultipleImg(); 

if (doc==NULL) 
{
// error processing 
...
} 

// use the set 
... 

// Free it 
FreeMultipleImg(doc);
2020-11-11T11:19:20-05:00Tags: |

SimpleOCR:SDK Functions -FixOrientationImg

int FixOrientationImg(IMG * img)

When a document has not been properly scanned, the resulting image can be of the wrong orientation. This function analyses an image in the wrong orientation, and rotates it the necessary 90, 180, or 270 degrees.

Return Value

If the function fails a nonzero error code is returned

Parameters

img

Pointer to an image of type IMG.

Example

IMG *img; 

// Create an IMG 
... 

if (FixOrientationImg(img)) 
{
// error processing 
...
}
2020-11-11T11:06:54-05:00Tags: |

SimpleOCR:SDK Functions – ExtractImgArea

IMG * ExtractImgArea(IMG * img, int x, int y, int w, int h)

Extracts a rectangular area from an image.

Return Value

A pointer to a new IMG object. If the function fails, the return value is NULL.

Parameters

img

Pointer to an image of type IMG.

x

x coordinate of the upper left corner of the area.

y

y coordinate of the upper left corner of the area.

w

area width in pixels.

h

area height in pixels.

Comments

The original image is left unchanged. The extract image should be freed with the function FreeImg

Example

IMG *img,img2; 

// Create an IMG 
... 
img2=WIMGExtract(img,10,20,300,100); 

if (img2==NULL) 
{
// Error processing 
...
} 

// Use the extracted Image 
... 

// Free it 
FreeImg(img2);
2020-11-11T11:01:14-05:00Tags: |

SimpleOCR:SDK Functions – EraseBlackBordersImg

int EraseBlackBordersImg(IMG * img)

Sometimes a scanned image has black borders. It happens frequently when the scanned document is smaller than the scanning area. This function detects and removes these black borders.

Return Value

On success, the function returns 0. If the function fails, the return value is different of 0.

Parameters

img

Pointer to an image of type IMG.

Example

IMG *img; 

// Create an IMG 
... 

if(WIMGEraseBlackBorders(img)) 
{
// Error processing 
...
}
2020-11-09T17:48:35-05:00Tags: |

SimpleOCR:SDK Functions – DIBToIMG

IMG * DIBToIMG(HGLOBAL hDib)

Converts a memory block containing a Device Independent Bitmap (DIB) to an IMG object.

Return Value

A pointer to an IMG object. If the function fails, the return value is NULL.

Parameters

hDib

A HGLOBAL handler referencing a Global Memory object containing a BITMAPINFO structure followed by the bitmap bits.

Comments

See your Windows SDK documentation for obtaining information about Device Independent Bitmaps and how to use it.

Example

Retrieve a DIB from the clipboard and convert it to an IMG object

HGLOBAL hDib; 
IMG *img; 

// Retrieve an IMG from the clipboard 
if (IsClipboardFormatAvailable(CF_DIB) &&
OpenClipboard(hWnd)) { 
hDib=GetClipboardData(CF_DIB); 
img=DIBToIMG(hDib); 
CloseClipboard();
}
2020-11-09T17:43:05-05:00Tags: |

SimpleOCR:SDK Functions – DeskewImg

int DeskewImg(IMG * img)

When a document has not been properly scanned, the resulting image can be skewed. This function analyses a skewed image and rotates it in order to fix the problem.

Return Value

If the function fails a nonzero error code is returned.

Parameters

img

Pointer to an image of type IMG.

Example

IMG *img; 

// Create an IMG 
... 

if (DeskewImg(img,180)) 
{
// error processing 
...
}
2020-11-09T17:13:06-05:00Tags: |

SimpleOCR:SDK Functions – CountPixelsImg

int CountPixelsImg(IMG * img)

Count the number of black pixels in an image.

Return Value

Number of black pixels in the image

Parameters

img

Pointer to an image of type IMG.

Example

IMG *img; 
IMG *img2; 
int count; 

// Create an IMG 
... 

IMG2 = ExtractImgArea(img,x,y,w,h); 
count = CountPixelsImg(img);
2020-11-09T16:45:33-05:00Tags: |

SimpleOCR:SDK Functions – DelImage

void DelImage(SETOFIMG * set, int index)

Deletes and frees an image in a set.

Return Value

None

Parameters

set

A pointer to a set of images of type SETOFIMG.

index

Position of the deleted image, counted from 0.

Example

SETOFIMG *doc; 
IMG *img; 
int nb; 

// Creates a set 
... 

// Delete the third image 
DelImage(set,2,img);
2020-11-09T16:38:05-05:00Tags: |
Go to Top