Recognize Pages Using LEADTOOLS OCR Module - LEAD Engine

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

  1. Start with the program you created in Working with Pages Using LEADTOOLS OCR Module - LEAD Engine.
  2. Define the following global IDs in Ezfunc.h in the OCR_Ltocr directory:

    #define IDM_RECOGNIZE               205   
    #define IDM_GET_STATUS              206 

  3. Edit EZFUNC.RC file in the OCR_Ltocr 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_OcrLanguageManager languageManager = NULL; 
       L_OcrEngine_GetLanguageManager(hEngine, languageManager); 
       L_OcrLanguage langs[] = { L_OcrLanguage_EN }; 
       nRet = L_OcrLanguageManager_EnableLanguages(languageManager, langs, _countof(langs)); 
       if(nRet != SUCCESS) 
       { 
          wsprintf (achBuff, TEXT("Error %d enabling recognition language(s)"), nRet); 
          MessageBox(NULL, achBuff, TEXT("Error!"), MB_OK); 
          return 0; 
       } 
       nRet = L_OcrPage_Recognize(hPage, MyCallback, NULL); 
       if (nRet == SUCCESS) 
          MessageBox(NULL, TEXT("The engine finished recognizing OCR page successfully."), TEXT("Notice"), MB_OK); 
       else 
       { 
          wsprintf (achBuff, TEXT("Error %d while recognizing OCR page"), nRet); 
          MessageBox (NULL, achBuff, TEXT("Error"), MB_OK); 
       } 
    } 
    break; 
    case IDM_GET_STATUS: 
    { 
       L_OcrRecognizeStatistic statistics; 
       memset(&statistics, 0, sizeof(L_OcrRecognizeStatistic)); 
       statistics.StructSize = sizeof(L_OcrRecognizeStatistic); 
       nRet = L_OcrPage_GetRecognizeStatistics(hPage, &statistics); 
       if (nRet == SUCCESS) 
       { 
          wsprintf(achBuff, TEXT("Total Recognized Characters = %d\nTotal Recognized Words = %d\nTotal Rejected Characters = %d\n "), 
          statistics.RecognizedCharacters, 
          statistics.RecognizedWords, 
          statistics.RejectedCharacters); 
          MessageBox(NULL, achBuff, TEXT("Status..."), MB_OK); 
       } 
    } 
    break; 

  5. Add below callback code above the function MainWndProc:

    L_INT EXT_CALLBACK MyCallback(L_OcrProgressData* data, L_VOID* userData) 
    { 
       UNREFERENCED_PARAMETER(userData); 
       L_TCHAR szBuffer[1024] = {0}; 
       L_TCHAR szOperation[100] = {0}; 
       switch(data->Operation) 
       { 
          case L_OcrProgressOperation_AutoZone: 
          lstrcpy(szOperation, TEXT("Auto Zone")); 
          break; 
          case L_OcrProgressOperation_PreprocessImage: 
          lstrcpy(szOperation, TEXT("Pre-process Image")); 
          break; 
          case L_OcrProgressOperation_Recognize: 
          lstrcpy(szOperation, TEXT("Recognize")); 
          break; 
          case L_OcrProgressOperation_SaveDocumentPrepare: 
          lstrcpy(szOperation, TEXT("Save Document Prepare")); 
          break; 
          case L_OcrProgressOperation_SaveDocument: 
          lstrcpy(szOperation, TEXT("Save Document")); 
          break; 
       } 
       wsprintf(szBuffer, TEXT("Recognizing page # %d, Operation: %s, Percentage: %d\n"), data->CurrentPageIndex, szOperation, data->Percentage); 
       OutputDebugString(szBuffer); 
       return SUCCESS; // continue to recognize next page 
    } 

  6. Build SimpleLoad.exe.

  7. Run SimpleLoad.exe.
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.