L_Doc2GetRecognizedCharacters

#include "ltdoc2.h"

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

L_HDOC2 hDoc;

handle to the OCR document

L_INT nPageIndex;

page index

pRECOGCHARS2 * ppRecogChars;

address of a pointer to a RECOGCHARS2 structure

L_INT32 * plCharsCount;

pointer to the number of characters

L_UINT uStructSize;

size of the structure

Gets all recognized characters for the specified recognized page.

Parameter

Description

hDoc

Handle to the OCR document.

nPageIndex

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

ppRecogChars

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

plCharsCount

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

uStructSize

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

Returns

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.

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

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

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

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

Required DLLs and Libraries

LTDOC2

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_Doc2GetStatus, L_Doc2Recognize, L_Doc2SetRecognitionResultOptions, L_Doc2GetRecognitionResultOptions, L_Doc2EnumOutputFileFormats, L_Doc2GetTextFormatInfo, L_Doc2SaveResultsToFile, L_Doc2SetSpecialChar, L_Doc2GetSpecialChar, L_Doc2SetRecognizedCharacters, L_Doc2FreeRecognizedCharacters, L_Doc2GetRecognizedWords, L_Doc2FreeRecognizedWords, L_Doc2GetRecognizedCharactersColors

Topics:

OCR Functions: Recognition

 

Recognizing Document Pages

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
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 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Professional OCR C API Help