To add code to an existing project in order to recognize pages:
Start with the program you created in Working with Zones.
Define the following global IDs in Ezfunc.h in the OCR_Ltdoc2 directory:
#define IDM_RECOGNIZE 205#define IDM_GET_STATUS 206
Edit EZFUNC.RC file in the OCR_Ltdoc2 directory and add the following lines:
MAIN_MENU MENUBEGIN......MENUITEM "Recognize Page" IDM_RECOGNIZEMENUITEM "Engine Status" IDM_GET_STATUSEND
In Ezfunc.cpp in the MainWndProc procedure, add the following code to the switch statement (switch(LOWORD(wParam))) for WM_COMMAND:
case IDM_RECOGNIZE:{RECOGNIZEOPTS2 RecogOpts;memset(&RecogOpts, 0, sizeof(RECOGNIZEOPTS2));RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS2);RecogOpts.nPageIndexStart = 0;RecogOpts.nPagesCount = 1;RecogOpts.SpellLangId = DOC2_LANG_ID_ENGLISH;RecogOpts.bEnableSubSystem = TRUE;RecogOpts.bEnableCorrection = TRUE;nRet = L_Doc2Recognize(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:{STATUS2 Status;memset(&Status, 0, sizeof(STATUS2));nRet = L_Doc2GetStatus(hDoc, &Status, sizeof(STATUS2));if (nRet == SUCCESS){wsprintf(achBuff, TEXT("Recognition Time = %d\nTotal Recognized Characters = %d\nTotal Recognized Words = %d\nTotal Rejected Characters = %d\n "),Status.lRecogTime,Status.nRecogChrCount,Status.nRecogWordCount,Status.nRejectChrCount);MessageBox(NULL, achBuff, TEXT("Status..."), MB_OK);}}break;
Add at the end of the code the following function in EZFUNC.CPP in OCR_Ltdoc2 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}
Also, add the following statement before the MainWndProc function
L_INT EXT_CALLBACK RecognizeStatusCB(L_INT nRecogPage, L_INT nError, L_VOID * pUserData); Build SimpleLoad.exe.
Run SimpleLoad.exe.