L_DocRecognize

#include "ltdoc.h"

L_LTDOC_API L_INT L_DocRecognize(hDoc, pRecogOpts, pfnCallback, pUserData)

L_HDOC hDoc;

/* handle to the OCR document */

pRECOGNIZEOPTS pRecogOpts;

/* pointer to RECOGNIZEOPTS */

RECOGNIZESTATUSCALLBACK pfnCallback;

/* callback function */

L_VOID * pUserData;

/* pointer to more parameters for the callback */

Recognizes the specified page(s)

Parameter

Description

hDoc

Handle to the OCR document.

pRecogOpts

Pointer to a RECOGNIZEOPTS structure that contains recognition options.

pfnCallback

Optional callback function for reporting recognition status.

 

If you do not provide a callback function, use NULL as the value of this parameter. Use NULL if no progress reporting is needed.

 

If you do provide a callback function, use the function pointer as the value of this parameter.

 

L_DocRecognize calls this callback function as it reports recognition status for each recognized page.

 

The callback function must adhere to the following function prototype: RECOGNIZESTATUSCALLBACK.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer to the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function will recognize the specified page or pages from the OCR document.

Always set the pszFileName member of the RECOGNIZEOPTS structure to a valid file name.

To save the recognition results to memory, call L_DocSaveResultsToMemory.

To save the recognition result to a file, call L_DocSaveResultsToFile.

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_DocSaveResultsToMemory, L_DocFreeMemoryResults, L_DocSetRecognitionResultOptions, L_DocGetRecognitionResultOptions, L_DocEnumOutputFileFormats, L_DocGetTextFormatInfo, L_DocSaveResultsToFile, L_DocSetSpecialChar, L_DocGetSpecialChar, L_DocGetRecognizedCharacters, L_DocSetRecognizedCharacters, L_DocFreeRecognizedCharacters, RECOGNIZESTATUSCALLBACK, L_DocGetRecognizedWords, L_DocFreeRecognizedWords

Topics:

OCR Functions: User Dictionary

 

Recognizing Document Pages

Example

L_INT EXT_CALLBACK RecognizeStatusCB(L_INT nRecogPage,
                                     L_INT nError,
                                     L_VOID* pUserData)
{
   UNREFERENCED_PARAMETER(pUserData);
   L_TCHAR szBuffer[100];

   ZeroMemory(szBuffer, sizeof(szBuffer));
   wsprintf(szBuffer, TEXT("Recognized page index = %d\nRecognition Return value = %d\n"), nRecogPage, nError);
   MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);

   return SUCCESS;
}

 L_INT DocRecognizeExample(L_HDOC hDoc,L_INT nPageIndex)
{
   L_INT nRet;
   LANGIDS* pLangIds = NULL;
   L_INT nLangCount = 0;
   RECOGNIZEOPTS RecogOpts;
   RECOGMODULE_TRADEOFF TradeOff;

   nRet = L_DocGetDefaultSpellLanguages (hDoc, &pLangIds, &nLangCount);
   if (nRet == SUCCESS)
   {
      nRet = L_DocGetRecognizeModuleTradeOff(hDoc, &TradeOff);
      if(nRet != SUCCESS)
         return nRet;
      if (TradeOff != RECGMD_ACCURATE)
      {
         nRet = L_DocSetRecognizeModuleTradeOff(hDoc, RECGMD_ACCURATE);
         if(nRet != SUCCESS)
            return nRet;
      }

      RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS);
      RecogOpts.nPageIndexStart = nPageIndex;
      RecogOpts.nPagesCount = 1;
      RecogOpts.bEnableSubSystem = TRUE;
      RecogOpts.bEnableCorrection = TRUE;
      RecogOpts.SpellLangId = pLangIds[0];
      RecogOpts.pszFileName = TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\testrdf.rdf");

      nRet = L_DocRecognize(hDoc, &RecogOpts, RecognizeStatusCB, NULL);
      if(nRet != SUCCESS)
         return nRet;
      nRet = L_DocFreeLanguages (hDoc, &pLangIds);
      if(nRet != SUCCESS)
         return nRet;
   }
   else
      return nRet;
   return SUCCESS;
}