#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_SetAreaOptions(page, options)
Sets the options for the area of interest on the page.
Handle to the OCR page.
Pointer to the L_OcrPageAreaOptions structure that represents the options for the area of interest to be used for the page.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
To obtain the options currently being used for the area of interest used by the page, call L_OcrPage_GetAreaOptions.
Required DLLs and Libraries
L_INT L_OcrPage_SetAreaOptionsExample()
{
L_INT retCode = SUCCESS;
BITMAPHANDLE bitmap = { 0 };
L_OcrEngine ocrEngine = NULL;
L_OcrPage ocrPage = NULL;
L_OcrDocumentManager ocrDocumentManager = NULL;
L_OcrPageAreaOptions areaOptions = { 0 };
areaOptions.StructSize = sizeof(L_OcrPageAreaOptions);
// Create an instance of the engine
retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &ocrEngine);
if (retCode != SUCCESS)
goto CLEANUP;
// Start the engine using default parameters
retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR);
if (retCode != SUCCESS)
goto CLEANUP;
// Load an image to process
retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL);
if (retCode != SUCCESS)
goto CLEANUP;
// Add the image to an OCR page
retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL);
if (retCode != SUCCESS)
goto CLEANUP;
// Transfer ownership to the OCR page
memset(&bitmap, 0, sizeof(bitmap));
// Get the area options for this page
retCode = L_OcrPage_GetAreaOptions(ocrPage, &areaOptions);
if (retCode != SUCCESS)
goto CLEANUP;
// Set the area of interest to be the first word of the first zone
areaOptions.Area.left = 284;
areaOptions.Area.top = 292;
areaOptions.Area.right = 538;
areaOptions.Area.bottom = 391;
// Set the area options with this new area of interest
retCode = L_OcrPage_SetAreaOptions(ocrPage, &areaOptions);
if (retCode != SUCCESS)
goto CLEANUP;
// Recognize it
retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL);
if (retCode != SUCCESS)
goto CLEANUP;
// Retrieve the text from the first zone, this should be "LEAD"
L_TCHAR* text = NULL;
L_UINT textLength = 0;
L_OcrPage_GetText(ocrPage, 0, &text, &textLength);
tprintf(TEXT("Recognized text: %s\n"), text);
L_OcrMemory_Free(text);
// Get the area options for this page
retCode = L_OcrPage_GetAreaOptions(ocrPage, &areaOptions);
if (retCode != SUCCESS)
goto CLEANUP;
// Set the area of interest to be the second word of the first zone
areaOptions.Area.left = 538;
areaOptions.Area.top = 292;
areaOptions.Area.right = 1096;
areaOptions.Area.bottom = 391;
// Set the area options with this new area of interest
retCode = L_OcrPage_SetAreaOptions(ocrPage, &areaOptions);
if (retCode != SUCCESS)
goto CLEANUP;
// Recognize it
retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL);
if (retCode != SUCCESS)
goto CLEANUP;
// Retrieve the text from the new first zone, this should be " Technologies"
L_TCHAR* text2 = NULL;
L_UINT textLength2 = 0;
L_OcrPage_GetText(ocrPage, 0, &text2, &textLength2);
tprintf(TEXT("Recognized text: %s\n"), text2);
L_OcrMemory_Free(text2);
CLEANUP:
if (bitmap.Flags.Allocated)
L_FreeBitmap(&bitmap);
if (ocrPage != NULL)
L_OcrPage_Destroy(ocrPage);
if (ocrEngine != NULL)
L_OcrEngine_Destroy(ocrEngine);
return retCode;
}