#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetBitmap(page, bitmapType, bitmapHandle, bitmapHandleSize)
Gets the original or processing btimap data of this page as a bitmap handle.
Handle to the OCR page.
The page type to get.
Address to BITMAPHANDLE variable to be updated with the page bitmap.
Size of the BITMAPHANDLE structure, use sizeof(BITMAPHANDLE).
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Each L_OcrPage contains two versions of the image used to create it: an original and an optional processing version. The processing version usually black/white and has uniform resolution (if the original image is FAX for example) and it gets passed to the internal OCR engine during the zoning and recognition process. The L_OcrPage_AutoPreprocess method also uses the B/W image to determine if the page is inverted, skewed, or has an orientation. However, it applies the correction to both the current and processing images.
You can use L_OcrPage_GetBitmap to get a copy of the processing image, but as for the original image this function returns a reference to the original bitmap handle (not a copy) so you should not call L_FreeBitmap on this bitmap type.
You cannot set the processing image of a page; it is created automatically by the engine.
If the original image is black and white and has uniform vertical and horizontal resolution, then the engine will not create a processing image, in other words, L_OcrPage_GetBitmap will return identical BTIMAPHANDLE for both original and processing bitmap types.
If the original image has different horizontal and vertical resolution, such as a FAX image, the processing page will be have be resized to have uniform resolution.
Required DLLs and Libraries
L_INT L_OcrPage_GetBitmapExample()
{
int bitsPerPixel = 0;
int qualityFactor = 2;
L_OcrEngine ocrEngine = NULL;
L_OcrPage ocrPage = NULL;
BITMAPHANDLE bitmap = {0}, exportPage = {0};
pLOADFILEOPTION loadOpts = NULL;
pSAVEFILEOPTION saveOpts = NULL;
pFILEINFO fileInfo = NULL;
L_OcrProgressCallback callback = NULL;
L_VOID* userData = NULL;
// Create an instance of the engine
L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine);
if(retCode != SUCCESS)
return retCode;
// Start the engine using default parameters
retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR);
if(retCode != SUCCESS)
goto CLEANUP;
// Load an image file
retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), bitsPerPixel, ORDER_RGB, loadOpts, fileInfo);
if(retCode != SUCCESS)
goto CLEANUP;
// Add the raster image into the OCR page
retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, callback, userData);
if(retCode != SUCCESS)
{
L_FreeBitmap(&bitmap);
goto CLEANUP;
}
// At this point, we have a valid page and bitmap ownership has transfered, so, we do not need to free the bitmap anymore
bitmap.Flags.Allocated = 0;
retCode = L_OcrPage_GetBitmap(ocrPage, L_OcrPageBitmapType_Original, &exportPage, sizeof(BITMAPHANDLE));
if(retCode != SUCCESS)
goto CLEANUP;
// Save this image to disk
bitsPerPixel = 24;
L_SaveBitmap(MAKE_IMAGE_PATH(L_TEXT("OcrExported.jpg")), &exportPage, FILE_JPEG, bitsPerPixel, qualityFactor, saveOpts);
CLEANUP:
if(ocrPage != NULL)
L_OcrPage_Destroy(ocrPage);
if(L_OcrEngine_IsStarted(ocrEngine))
L_OcrEngine_Shutdown(ocrEngine);
L_OcrEngine_Destroy(ocrEngine);
return retCode;
}