L_Doc2GetRecognizedCharacters

#include "ltdoc2.h"

L_LTDOC2_API L_INT EXT_FUNCTION L_Doc2GetRecognizedCharacters(hDoc, nPageIndex, ppRecogChars, plCharsCount, uStructSize)

Gets all recognized characters for the specified recognized page.

Parameters

L_HDOC2 hDoc

Handle to the OCR document.

L_INT nPageIndex

Index of the recognized page for which to get the recognized characters. This index is zero-based.

pRECOGCHARS2 * ppRecogChars

Address of pointer to a RECOGCHARS2 structure into which an array of RECOGCHARS2 structures will be allocated and updated.

L_INT32 * plCharsCount

Pointer to a variable to be updated with the number of elements in the ppRecogChars array.

L_UINT uStructSize

Size in bytes, of the structure pointed to by ppRecogChars, use sizeof(RECOGCHARS2) to calculate this value.

Returns

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

Comments

This function will allocate and return an array for all recognized characters for the specified recognized page in ppRecogChars.

This function will return the number of recognized characters in plCharsCount.

✅ IMPORTANT

You must free the memory associated with ppRecogChars parameter when it is no longer needed, by calling the L_Doc2FreeRecognizedCharacters / L_Doc2FreeRecognizedCharacters function.

This function can be called after a successful recognition process begun by calling the L_Doc2Recognize / L_Doc2RecognizeExt function.

⛔ CAUTION

This function should not be called before calling the L_Doc2Recognize / L_Doc2RecognizeExt function.

To update the recognized characters, call the L_Doc2SetRecognizedCharacters / L_Doc2SetRecognizedCharactersExt function. To save the updated recognized characters to a file, call the L_Doc2SaveResultsToFile / L_Doc2SaveResultsToFileExt function.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT Doc2GetRecognizedCharactersExample(L_HDOC2 hDoc) 
{ 
   L_INT nRet; 
   RECOGNIZEOPTS2 RecogOpts; 
   RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS2); 
   RecogOpts.nPageIndexStart = 0; 
   RecogOpts.nPagesCount = 1; 
   RecogOpts.SpellLangId = DOC2_LANG_ID_ENGLISH; 
 
   nRet = L_Doc2Recognize (hDoc, &RecogOpts, NULL, NULL); 
   if (nRet == SUCCESS) 
   { 
      pRECOGCHARS2 pRecogChars = NULL; 
      L_INT32 lCharsCount = 0; 
      nRet = L_Doc2GetRecognizedCharacters(hDoc, 0, &pRecogChars, &lCharsCount, sizeof(RECOGCHARS2)); 
      if (nRet == SUCCESS) 
      { 
         L_TCHAR szBuffer[1024]; 
         RESULTOPTIONS2 ResOpts; 
 
         ZeroMemory(&ResOpts, sizeof(RESULTOPTIONS2)); 
         ZeroMemory(szBuffer, sizeof(szBuffer)); 
 
         wsprintf(szBuffer, TEXT("Number of recognized characters in the specified page = %d\n"), lCharsCount); 
         MessageBox(NULL, szBuffer, TEXT("Recognized Characters Count"), MB_OK); 
 
         for (L_INT32 i=0; i<lCharsCount; i++) 
         { 
            if (pRecogChars[i].nConfidence > 900) 
            { 
               pRecogChars[i].uFont |= DOC2_FONT_BOLD | DOC2_FONT_UNDERLINE; 
               pRecogChars[i].nFontSize = 20; 
            } 
         } 
 
         L_INT nClrsCount=0; 
         nRet = L_Doc2GetRecognizedCharactersColors(hDoc, 0, NULL, &nClrsCount); 
         if (nRet == SUCCESS) 
         { 
            wsprintf(szBuffer, TEXT("Number of recognized characters colors in the specified page = %d\n"), nClrsCount); 
            MessageBox(NULL, szBuffer, TEXT("Recognized Characters Colors Count"), MB_OK); 
 
            if (nClrsCount > 0) 
            { 
               COLORREF * pClrChars = (COLORREF *)GlobalAllocPtr(GHND, sizeof(COLORREF) * nClrsCount); 
               nRet = L_Doc2GetRecognizedCharactersColors(hDoc, 0, pClrChars, &nClrsCount); 
               if (nRet == SUCCESS) 
               { 
                  wsprintf(szBuffer, TEXT("Colors for 1st recognized character\nThe foreground color = %d\nThe background color = %d\n"), pClrChars[pRecogChars[0].nFGColorIndex], pClrChars[pRecogChars[0].nBGColorIndex]); 
                  MessageBox(NULL, szBuffer, TEXT("Recognized Character Colors"), MB_OK); 
               } 
 
               GlobalFreePtr(pClrChars); 
            } 
         } 
 
         nRet = L_Doc2SetRecognizedCharacters(hDoc, 0, pRecogChars, lCharsCount); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_Doc2FreeRecognizedCharacters(hDoc, &pRecogChars); 
         if(nRet != SUCCESS) 
            return nRet; 
 
         nRet = L_Doc2GetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS2)); 
         if(nRet != SUCCESS) 
            return nRet; 
 
         ResOpts.Format = DOC2_RTF_WORD_2000; 
         ResOpts.FormatLevel = DOC2_FORMAT_LEVEL_AUTO; 
         ResOpts.DocFormat = DOCUMENTFORMAT_USER; 
 
         nRet = L_Doc2SetRecognitionResultOptions(hDoc, &ResOpts); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_Doc2SaveResultsToFile(hDoc, MAKE_IMAGE_PATH(TEXT("test.doc"))); 
         if(nRet != SUCCESS) 
            return nRet; 
      } 
   } 
   return SUCCESS; 
} 
Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - OmniPage Engine C API Help