Working with Recognition Results Using OCR Plus

To add code to an existing project in order to work with recognition results:

 

1.

Start with the program you created in Recognize Pages.

2.

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

 

#define IDM_GET_OUTPUTFORMAT        207

#define IDM_SAVE_RESULTS            208

 

3.

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

 

MAIN_MENU   MENU

BEGIN

   ...

   ...

   MENUITEM "Get Output Formats"    IDM_GET_OUTPUTFORMAT

   MENUITEM "Save Results"          IDM_SAVE_RESULTS

END

 

4.

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

      case IDM_GET_OUTPUTFORMAT:
         {
            nRet = L_DocEnumOutputFileFormats(hDoc, EnumOutputFileFormatsCB, NULL);
            if (nRet != SUCCESS)
            {
               wsprintf (achBuff, TEXT("Error %d enumerating available file formats"), nRet);
               MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
            }
         }
         break;
      case IDM_SAVE_RESULTS:
         {
            RESULTOPTIONS ResOpts;

            memset(&ResOpts, 0, sizeof(RESULTOPTIONS));
            nRet = L_DocGetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS));
            if (nRet == SUCCESS)
            {
               ResOpts.Format = DOC_WORD_97_2000_XP;
               ResOpts.FormatLevel = FORMAT_LEVEL_FULL;
               ResOpts.DocOptions.PaperSize = SEL_PREDEFINED;
               ResOpts.DocOptions.PaperType = PAPER_TYPE_A4;

               L_DocSetRecognitionResultOptions(hDoc, &ResOpts);
               nRet = L_DocSaveResultsToFile (hDoc, TEXT("c:\\test.doc"));
               if (nRet != SUCCESS)
               {
                  wsprintf (achBuff, TEXT("Error %d in saving recognition results to a file"), nRet);
                  MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
               }
            }
         }
         break;

5.

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

L_INT EXT_CALLBACK EnumOutputFileFormatsCB(FORMAT_TYPE Format, L_VOID * pUserData)
{
   UNREFERENCED_PARAMETER(pUserData);

   TEXTFORMATINFO FormatInfo;
   L_INT nRet;
   L_TCHAR szBuffer[1024];

   memset(&FormatInfo, 0, sizeof(TEXTFORMATINFO));
   nRet = L_DocGetTextFormatInfo(hDoc, Format, &FormatInfo, sizeof(TEXTFORMATINFO));
   if (nRet == SUCCESS)
   {
      wsprintf(szBuffer, TEXT("Format Name = %s\nFormat DLL Name = %s\nFormat Ext Name = %s\n"),
               FormatInfo.pszName,
               FormatInfo.pszDLLName,
               FormatInfo.pszExtName);

      MessageBox(NULL, szBuffer, TEXT("Format Info"), MB_OK);

      switch (FormatInfo.Type)
      {
      case OUT_TYPE_PLAIN:
         wsprintf(szBuffer, TEXT("Format Type = Plain"));
         break;
      case OUT_TYPE_WORD_PROCESSOR:
         wsprintf(szBuffer, TEXT("Format Type = Word Processor"));
         break;
      case OUT_TYPE_TRUE_WORD_PROCESSOR:
         wsprintf(szBuffer, TEXT("Format Type = True Word Processor"));
         break;
      case OUT_TYPE_TABLE:
         wsprintf(szBuffer, TEXT("Format Type = Table"));
         break;
      case OUT_TYPE_UNKNOWN:
         wsprintf(szBuffer, TEXT("Format Type = Unknown"));
         break;
      }

      MessageBox(NULL, szBuffer, TEXT("Format Type"), MB_OK);
   }

   return SUCCESS;
}

 

6.

Also, add the following statement before the MainWndProc function

L_INT EXT_CALLBACK EnumOutputFileFormatsCB(FORMAT_TYPE Format, L_VOID * pUserData);

 

7.

Build SimpleLoad.exe.

8.

Run SimpleLoad.exe.

For more information, refer to:

Punctuation, MICR, and Special Characters

OCR Plus Utility demo

Programming with LEADTOOLS OCR

OCR Frequently Asked Questions

Tutorials

Demo Programs