L_DocGetRecognizedCharacters

#include "ltdoc.h"

L_LTDOC_API L_INT L_DocGetRecognizedCharacters(hDoc, nPageIndex, ppRecogChars, plCharsCount, uStructSize)

L_HDOC hDoc;

/* handle to the OCR document */

L_INT nPageIndex;

/* page index */

pRECOGCHARS * ppRecogChars;

/* address of a pointer to a RECOGCHARS structure */

L_INT32 * plCharsCount;

/* pointer to the number of characters */

L_UINT uStructSize;

/* size of the structure */

Gets all recognized characters for specific recognized page.

Parameter

Description

hDoc

Handle to the OCR document.

nPageIndex

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

ppRecogChars

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

plCharsCount

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

uStructSize

Specifies the size of the structure pointed to by ppRecogChars, use sizeof(RECOGCHARS) 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 recognized characters count in plCharsCount.

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

This function can be called after a successful recognition process started by calling L_DocRecognize.

This function should not be called before calling L_DocRecognize.

To update the recognized characters, call L_DocSetRecognizedCharacters. To save the updated recognized characters to a file, call L_DocSaveResultsToFile To save the results into memory, call L_DocSaveResultsToMemory.

Required DLLs and Libraries

LTDOC

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_DocGetStatus, L_DocRecognize, L_DocSaveResultsToMemory, L_DocFreeMemoryResults, L_DocSetRecognitionResultOptions, L_DocGetRecognitionResultOptions, L_DocEnumOutputFileFormats, L_DocGetTextFormatInfo, L_DocSaveResultsToFile, L_DocSetSpecialChar, L_DocGetSpecialChar, L_DocSetRecognizedCharacters, L_DocFreeRecognizedCharacters, L_DocGetRecognizedWords, L_DocFreeRecognizedWords

Topics:

OCR Functions: Recognition

 

Recognizing Document Pages

Example

 L_INT DocGetRecognizedCharactersExample(L_HDOC hDoc)
{
   L_INT nRet;
   RECOGNIZEOPTS RecogOpts;
   RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS);
   RecogOpts.nPageIndexStart = 0;
   RecogOpts.nPagesCount = 1;
   RecogOpts.SpellLangId = LANG_ID_ENGLISH;
   RecogOpts.pszFileName = TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\testrdf.rdf");

   nRet = L_DocRecognize (hDoc, &RecogOpts, NULL, NULL);
   if (nRet == SUCCESS)
   {
      pRECOGCHARS pRecogChars = NULL;
      L_INT32 lCharsCount = 0;
      nRet = L_DocGetRecognizedCharacters(hDoc, 0, &pRecogChars, &lCharsCount, sizeof(RECOGCHARS));
      if (nRet == SUCCESS)
      {
         L_TCHAR szBuffer[1024];
         RESULTOPTIONS ResOpts;

         ZeroMemory(&ResOpts, sizeof(RESULTOPTIONS));
         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 |= FONT_BOLD | FONT_UNDERLINE;
               pRecogChars[i].nFontSize = 20;
            }
         }

         nRet = L_DocSetRecognizedCharacters(hDoc, 0, pRecogChars, lCharsCount);
         if(nRet != SUCCESS)
            return nRet;
         nRet = L_DocFreeRecognizedCharacters(hDoc, &pRecogChars);
         if(nRet != SUCCESS)
            return nRet;

         nRet = L_DocGetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS));
         if(nRet != SUCCESS)
            return nRet;

         ResOpts.Format = DOC_RTF_WORD_2000;
         ResOpts.FormatLevel = FORMAT_LEVEL_FULL;
         ResOpts.DocOptions.PaperSize = SEL_PREDEFINED;
         ResOpts.DocOptions.PaperType = PAPER_TYPE_A4;
#if defined(LEADTOOLS_V16_OR_LATER)
         ResOpts.DocFormat = DOCUMENTFORMAT_USER;
#endif // #if defined(LEADTOOLS_V16_OR_LATER)

         nRet = L_DocSetRecognitionResultOptions(hDoc, &ResOpts);
         if(nRet != SUCCESS)
            return nRet;
         nRet = L_DocSaveResultsToFile(hDoc, TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\test.doc"));
         if(nRet != SUCCESS)
            return nRet;
      }
   }
   return SUCCESS;
}