Recognize Pages

To add code to an existing project in order to recognize pages:

1.

Start with the program you created in Working with Zones.

2.

Define the following global IDs in Ezfunc.h in the DocumentTutor directory:

#define IDM_RECOGNIZE               205

#define IDM_GET_STATUS              206

 

3.

Edit EZFUNC.RC file in the DocumentTutor directory and add the following lines:

 

MAIN_MENU   MENU

BEGIN

   ...

   ...

   MENUITEM "Recognize Page"        IDM_RECOGNIZE

   MENUITEM "Engine Status"         IDM_GET_STATUS

END

 

4.

In the MainWndProc procedure, add the following code to the switch statement for WM_COMMAND:

      case IDM_RECOGNIZE:
         {
            RECOGNIZEOPTS RecogOpts;
            memset(&RecogOpts, 0, sizeof(RECOGNIZEOPTS));

            RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS);
            RecogOpts.nPageIndexStart = 0;
            RecogOpts.nPagesCount = 1;
            RecogOpts.SpellLangId = LANG_ID_ENGLISH;
            RecogOpts.bEnableSubSystem = TRUE;
            RecogOpts.bEnableCorrection = TRUE;
            RecogOpts.pszFileName = TEXT("c:\\testrdf.rdf");
            nRet = L_DocRecognize(hDoc, &RecogOpts, RecognizeStatusCB, NULL);
            if (nRet == SUCCESS)
               MessageBox(NULL, TEXT("The engine finished recognizing the specified pages successfully."), TEXT("Notice"), MB_OK);
            else
            {
               wsprintf (achBuff, TEXT("Error %d in recognized pages"), nRet);
               MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
            }
         }
         break;
      case IDM_GET_STATUS:
         {
            STATUS Status;
            memset(&Status, 0, sizeof(STATUS));

            nRet = L_DocGetStatus(hDoc, &Status, sizeof(STATUS));
            if (nRet == SUCCESS)
            {
               wsprintf(achBuff, TEXT("Recognition Time = %d\nTotal Recognized Characters = %d\nTotal Recognized Words = %d\nTotal Rejected Characters = %d\nTotal Rejected Words = %d\n"),
                        Status.lRecogTime,
                        Status.nRecogChrCount,
                        Status.nRecogWordCount,
                        Status.nRejectChrCount,
                        Status.nRejectWordCount);
               MessageBox(NULL, achBuff, TEXT("Status..."), MB_OK);
            }
         }
         break;

 

5.

Add the following function in EZFUNC.CPP in DocumentTutor directory.

L_INT EXT_CALLBACK RecognizeStatusCB(L_INT nRecogPage, L_INT nError, L_VOID * pUserData)
{
   UNREFERENCED_PARAMETER(pUserData);

   L_TCHAR szBuffer[1024];

   wsprintf(szBuffer, TEXT("Page # %d has finished recognition.\nThe recognition return code = %d\n"), nRecogPage, nError);
   MessageBox(NULL, szBuffer, TEXT("Recognition Status"), MB_OK);
   return SUCCESS; // continue to recognize next page
}

 

6.

Also, add the following statement before the MainWndProc function

L_INT EXT_CALLBACK RecognizeStatusCB(L_INT nRecogPage, L_INT nError, L_VOID * pUserData);

7.

Build SimpleLoad.exe.

8.

Run SimpleLoad.exe.