Gets the recognition OCR data for a zone in this L_OcrPage as a string.
#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetText(page, zoneIndex, text, textLength)
Handle to the OCR page.
Zero based index of the zone. If you passed -1 for this parameter then all page text will be retrieved.
Address for L_WCHAR* variable to be updated with zone/page text. You must call L_OcrMemory_Free method to free this string buffer when no longer needed.
Address for L_UINT variable to be updated with length of the retrieved text.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Gets the recognition OCR data for a zone in this L_OcrPage as a string.
If the passed 'zoneIndex' parameter contains -1 then all page text will be retrieved.
Use this method to get the page result in a simple string. Getting the result as text is helpful in situations when adding zones manually for form processing. For example, suppose the form you are processing has two areas of interests, a name field at coordinates 100, 100, 400, 120 and a social security number at coordinates 100, 200, 400, 220. You can structure your application as follows:
Add the name zone manually:
L_OcrZone nameZone = { 0 };
nameZone.StructSize = sizeof(L_OcrZone);
L_OcrZone_Default(&nameZone);
nameZone.ZoneType = L_OcrZoneType_Text;
L_RECT rect = {100, 100, 400, 120};
nameZone.Bounds = rect;
L_OcrPage_AddZone(ocrPage, nameZone);
Recognize the page (only this one zone will recognized):
Get the value of the name field:
L_OcrPage_GetText();
Remove the name zone from the page:
Repeat the steps from (2) above to get the social security field.
Note: You must call L_OcrMemory_Free method to free this string buffer when no longer needed.
L_INT L_OcrPage_GetTextExample()
{
BITMAPHANDLE bitmap = { 0 };
L_OcrEngine ocrEngine = NULL;
L_OcrPage ocrPage = NULL;
// Create an instance of the engine
std::wcout << L"Creating OCR engine instance...\n";
L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &ocrEngine);
if(retCode != SUCCESS)
return retCode;
// Start the engine using default parameters
std::wcout << L"Starting up OCR engine...\n";
L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR);
// Load an image to process
std::wcout << L"Loading page to process...\n";
L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL);
// Create an OCR page to handle processing
L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL);
// Transfer ownership
bitmap.Flags.Allocated = 0;
// Find text in the image
std::wcout << L"Finding text within page...\n";
L_OcrPage_AutoZone(ocrPage, NULL, NULL);
// Recognize the text
std::wcout << L"Recognizing the text...\n";
L_OcrPage_Recognize(ocrPage, NULL, NULL);
// Loop through zones and output the text
L_UINT zoneCount = 0;
L_OcrPage_GetZoneCount(ocrPage, &zoneCount);
std::wcout << L"Zone count: " << zoneCount << std::endl;
std::wcout << L"Show recognized text:\n"
<< L"**********************************************\n";
for(L_UINT zoneIndex = 0; zoneIndex < zoneCount; zoneIndex++)
{
L_WCHAR* text = NULL;
L_UINT textLength = 0;
L_OcrPage_GetText(ocrPage, zoneIndex, &text, &textLength);
std::wcout << text << std::endl;
L_OcrMemory_Free(text);
}
std::wcout << L"**********************************************\n";
//CLEANUP
std::wcout << L"Disposing of resources used...";
L_OcrPage_Destroy(ocrPage);
L_OcrEngine_Destroy(ocrEngine);
return SUCCESS;
}