Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.10.23
LEADTOOLS OCR C DLL Help

Working with Zones Using OCR Professional

Show in webframe

To add code to an existing project that will let you recognize pages:

1.

Start with the program you created in Working with Pages.

2.

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

#define IDM_FIND_ZONES              201
#define IDM_ZONES_COUNT             202
#define IDM_ADD_VERIFICATION_ZONE   203

 

3.

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

 

MAIN_MENU   MENU
BEGIN
   ... 
   ... 
   MENUITEM "Find Zones"            IDM_FIND_ZONES
   MENUITEM "Zone Count"            IDM_ZONES_COUNT
   MENUITEM "Add Verification Zone" IDM_ADD_VERIFICATION_ZONE
END

 

4.

Define the following global variables in Ezfunc.H in the OCR_Ltdoc2 directory:

L_INT nZoneCount; 

5.

In Ezfunc.cpp in the MainWndProc procedure, add the following code to the switch ("switch(LOWORD(wParam))")statement for WM_COMMAND:

      case IDM_FIND_ZONES:
         {
            AUTOZONEOPTS2 ZoneOpts;
            memset(&ZoneOpts, 0, sizeof(AUTOZONEOPTS2));

            ZoneOpts.uStructSize = sizeof(AUTOZONEOPTS2);
            ZoneOpts.bEnableForceSingleColumn = TRUE;
            ZoneOpts.bDetectNonGridedTables = TRUE;

            L_Doc2SetZoneOptions(hDoc, &ZoneOpts);
            nRet = L_Doc2FindZones(hDoc, 0);
            if (nRet == SUCCESS)
               MessageBox(NULL, TEXT("The automatic zone method found all available zones in the specified pages successfully."), TEXT("Notice!"), MB_OK);
            else
            {
               wsprintf (achBuff, TEXT("Error %d in finding available zones in the specified page."), nRet);
               MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
            }

            // Now the engine will build the OCR zone list, and we need to specify a verification event for each zone
            // but the engine allows adding a verification event only for user zones. So, we need to duplicate these zones in the same coordinates... 
            DuplicateOcrZones(0); 
            InvalidateRect (hWnd, NULL, FALSE);
         }

         break;
      case IDM_ZONES_COUNT:
         {
            nRet = L_Doc2GetZoneCount(hDoc, 0, &nZoneCount);
            if (nRet == SUCCESS)
            {
               wsprintf(achBuff, TEXT("Total Zones count = %d\n"), nZoneCount);
               MessageBox(NULL, achBuff, TEXT("Zones Count"), MB_OK);
            }
         }
         break;
      case IDM_ADD_VERIFICATION_ZONE:
         {
            ZONEDATA2 Zone;
            L_INT i;
            for(i=0; i<nZoneCount; i++)
            {
               memset(&Zone, 0, sizeof(ZONEDATA2));
               nRet = L_Doc2GetZone(hDoc, 0, i, &Zone, sizeof(ZONEDATA2));
               if (nRet == SUCCESS)
               {
                  if ((Zone.uFlags & DOC2_ZONE_CHK_CHECKCBF_PROHIBIT) == DOC2_ZONE_CHK_CHECKCBF_PROHIBIT)
                     Zone.uFlags &= ~ DOC2_ZONE_CHK_CHECKCBF_PROHIBIT;

                  Zone.pfnCallback = VerificationCB;
                  nRet = L_Doc2UpdateZone(hDoc, 0, i, &Zone);
                  if (nRet != SUCCESS)
                  {
                     wsprintf (achBuff, TEXT("Error %d in updating zone # %d"), nRet, i);
                     MessageBox (NULL, achBuff, TEXT("Error"), MB_OK);
                  }
               }
            }
         }
         break; 

6.

Add the following function at the end of the file in EZFUNC.CPP in the OCR_Ltdoc2 directory.

L_INT EXT_CALLBACK VerificationCB(L_INT nZoneIndex, L_TCHAR * pszWord, DOC2_VERIFYCODE * pVerify, L_VOID * pUserData)
{
   UNREFERENCED_PARAMETER(nZoneIndex); 
   UNREFERENCED_PARAMETER(pszWord); 
   UNREFERENCED_PARAMETER(pUserData); 

   *pVerify = DOC2_VERIFY_ACCEPT;
   return SUCCESS;
}

7.

Also, add the following statement before the MainWndProc function.

L_INT EXT_CALLBACK VerificationCB(L_INT nZoneIndex, L_TCHAR * pszWord, DOC2_VERIFYCODE * pVerify, L_VOID * pUserData); 

8.

Add the following at the end of the code in EZFUNC.CPP in the OCR_Ltdoc2 directory:

L_INT DuplicateOcrZones(L_INT nPageIndex) 
{
L_INT nOcrCount=0;
   L_Doc2GetZoneCount(hDoc, nPageIndex, &nOcrZonesCount);
   pZONEDATA2 pZones = (pZONEDATA2)GlobalAllocPtr(GHND, sizeof(ZONEDATA2) * nOcrZonesCount); 
   if (!pZones) 
      return ERROR_NO_MEMORY; 

   L_INT nRet; 

   for (int i=0; i<nOcrZonesCount; i++)
   {
      nRet = L_Doc2GetZone(hDoc, nPageIndex, i, &pZones[i], sizeof(ZONEDATA2)); 
      if (nRet != SUCCESS) 
         return nRet; 
   }

   for (int i=0; i<nOcrZonesCount; i++)
      L_Doc2AddZone(hDoc, nPageIndex, -1, &pZones[i]); 

   return SUCCESS; 
}

9.

Also, add the following statement before the MainWndProc function.

L_INT DuplicateOcrZones(L_INT nPageIndex);

10.

Build SimpleLoad.exe.

11.

Run SimpleLoad.exe.

Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.