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 OCR_Ltdoc directory: |
#define IDM_RECOGNIZE 205
#define IDM_GET_STATUS 206
3. |
Edit EZFUNC.RC file in the OCR_Ltdoc directory and add the following lines: |
MAIN_MENU MENU
BEGIN
...
...
MENUITEM "Recognize Page" IDM_RECOGNIZE
MENUITEM "Engine Status" IDM_GET_STATUS
END
4. |
In Ezfunc.cpp in the MainWndProc procedure, add the following code to the switch statement (switch(LOWORD(wParam)))for WM_COMMAND: |
case IDM_RECOGNIZE:
{
L_TCHAR st [256] = {0};
RECOGNIZEOPTS RecogOpts;
memset(&RecogOpts, 0, sizeof(RECOGNIZEOPTS));
wsprintf(st,TEXT("c:\\test.rdf"));
RecogOpts.uStructSize = sizeof(RECOGNIZEOPTS);
RecogOpts.pszFileName = st;
RecogOpts.nPageIndexStart = 0;
RecogOpts.nPagesCount = 1;
RecogOpts.SpellLangId = LANG_ID_ENGLISH;
RecogOpts.bEnableSubSystem = TRUE;
RecogOpts.bEnableCorrection = TRUE;
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\n "),
Status.lRecogTime,
Status.nRecogChrCount,
Status.nRecogWordCount,
Status.nRejectChrCount);
MessageBox(NULL, achBuff, TEXT("Status..."), MB_OK);
}
}
break;
5. |
Add at the end of the code the following function in EZFUNC.CPP in OCR_Ltdoc 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. |