L_OcrPage_GetText - OCR Module - LEAD Engine C++ API Help

L_OcrPage_GetText

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetText(page, zoneIndex, text, textLength)

L_OcrPage page; handle to the OCR page
L_INT zoneIndex; zone index
L_WCHAR** text; address for L_WCHAR* variable to be updated with zone/page text
L_UINT* textLength; address for L_UINT variable to be updated with length of the retrieved text

Gets the recognition OCR data for a zone in this L_OcrPage as a string.

Parameter Description
page Handle to the OCR page.
zoneIndex Zero based index of the zone. If you passed -1 for this parameter then all page text will be retrieved.
text 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.
textLength Address for L_UINT variable to be updated with length of the retrieved text.

Returns

SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

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:

  1. Create a new L_OcrPage handle from the form bitmap using L_OcrPage_FromBitmap.
  2. 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); 

  3. Recognize the page (only this one zone will recognized):

  4. Get the value of the name field:

    L_OcrPage_GetText(); 

  5. Remove the name zone from the page:

  6. 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.

Required DLLs and Libraries

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

See Also

Functions: L_OcrPage_Destroy, L_OcrPage_FromBitmap, L_OcrPage_GetBitmap, L_OcrPage_SetBitmap, L_OcrPage_GetOverlayBitmap, L_OcrPage_SetOverlayBitmap, L_OcrPage_SetBitmapChangedCallback, L_OcrPage_IsInverted, L_OcrPage_GetRotateAngle, L_OcrPage_GetDeskewAngle, L_OcrPage_AutoPreprocess, L_OcrPage_AutoZone, L_OcrPage_GetZoneCount, L_OcrPage_InsertZone, L_OcrPage_AddZone, L_OcrPage_IndexOfZone, L_OcrPage_GetZoneAt, L_OcrPage_SetZoneAt, L_OcrPage_RemoveZone, L_OcrPage_RemoveZoneAt, L_OcrPage_ClearZones, L_OcrPage_GetZoneCells, L_OcrPage_SetZoneCells, L_OcrPage_HitTestZone, L_OcrPage_IsRecognized, L_OcrPage_Recognize, L_OcrPage_Unrecognize, L_OcrPage_GetRecognizeStatistics, L_OcrPage_GetRecognizedCharacters, L_OcrPage_SetRecognizedCharacters, L_OcrPage_FreePageCharacters, L_OcrPage_GetZoneWords, L_OcrPage_FreeWords, L_OcrPage_ExtractZoneMICRData, L_OcrPage_DetectLanguages, L_OcrPage_LoadZonesFile, L_OcrPage_SaveZonesFile, L_OcrPage_SaveXml, L_OcrPage_GetAutoPreprocessValues
Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages

Example

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_Advantage, &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_ADVANTAGE_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; 
} 
Help Version 20.0.2018.6.21
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help