L_OcrPage_GetText

#include "ltocr.h"

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

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

Parameters

L_OcrPage page

Handle to the OCR page.

L_INT zoneIndex

Zero based index of the zone. If you passed -1 for this parameter then all page text will be retrieved.

L_WCHAR** 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.

L_UINT* textLength

Address for L_UINT variable to be updated with length of the retrieved text.

Returns

Value Meaning
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

See Also

Functions

Topics

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 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.