L_Doc2GetRecognizedCharactersExt

#include "ltdoc2.h"

L_LTDOC2_API L_INT L_Doc2GetRecognizedCharactersExt(hDoc, nDocId, nPageIndex, ppRecogChars, plCharsCount, uStructSize)

Gets all recognized characters for the specified recognized page.

Parameters

L_HDOC2 hDoc

Handle to the OCR document.

L_INT nDocId

Document ID created by calling L_Doc2CreateDocument.

L_INT nPageIndex

Zero-based index of the recognized page for which to get the recognized characters.

pRECOGCHARS2 * ppRecogChars

Address of a 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

Be sure to call L_Doc2Recognize / L_Doc2RecognizeExt successfully before calling L_Doc2GetRecognizedCharactersExt.

L_Doc2GetRecognizedCharactersExt allocates and returns an array containing all recognized characters for the specified recognized page in _ppRecogChars_, and the number of recognized characters in plCharsCount.

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.

Be sure to free the memory associated with the ppRecogChars parameter when it is no longer needed by calling the L_Doc2FreeRecognizedCharacters / L_Doc2FreeRecognizedCharacters function.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT Doc2GetRecognizedCharactersExampleExt(L_HDOC2 hDoc, L_INT nDocId) 
{ 
   L_INT nRet; 
   RECOGNIZEOPTS2 RecogOpts; 
   RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS2); 
   RecogOpts.nPageIndexStart = 0; 
   RecogOpts.nPagesCount = 1; 
   RecogOpts.SpellLangId = DOC2_LANG_ID_ENGLISH; 
 
   nRet = L_Doc2RecognizeExt (hDoc, nDocId, &RecogOpts, NULL, NULL); 
   if (nRet == SUCCESS) 
   { 
      pRECOGCHARS2 pRecogChars = NULL; 
      L_INT32 lCharsCount = 0; 
      nRet = L_Doc2GetRecognizedCharactersExt(hDoc, nDocId, 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_Doc2GetRecognizedCharactersColorsExt(hDoc, nDocId, 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_Doc2GetRecognizedCharactersColorsExt(hDoc, nDocId, 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_Doc2SetRecognizedCharactersExt(hDoc, nDocId, 0, pRecogChars, lCharsCount); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_Doc2FreeRecognizedCharacters(hDoc, &pRecogChars); 
         if(nRet != SUCCESS) 
            return nRet; 
 
         nRet = L_Doc2GetRecognitionResultOptionsExt(hDoc, nDocId, &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_Doc2SetRecognitionResultOptionsExt(hDoc, nDocId, &ResOpts); 
         if(nRet != SUCCESS) 
            return nRet; 
         nRet = L_Doc2SaveResultsToFileExt(hDoc, nDocId, MAKE_IMAGE_PATH(TEXT("test.doc")), DOC2_SAVE_PAGE_RESULTS); 
         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