L_OcrZoneManager

LEADTOOLS has defined the following data types for referencing an OCR zone manager handle:

Data Type Definition and Usage
L_OcrZoneManager Defined as Handle, used as a handle of the OCR zone manager.

Example

static void LogMessage(const wchar_t* message, ...) 
{ 
   const unsigned int bufferSize = 1024 * 4; 
   wchar_t buffer[bufferSize]; 
 
   if(message != NULL) 
   { 
      va_list ap; 
      va_start(ap, message); 
      vswprintf_s(buffer, message, ap); 
      va_end(ap); 
   } 
   else 
   { 
      wcscpy_s(buffer, L""); 
   } 
 
   _tprintf(buffer); 
} 
 
L_INT L_OcrZoneManager_GetOMROptionsExample() 
{ 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   L_OcrZoneManager zoneManager = NULL; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
   L_OcrDocument ocrDocument = NULL; 
   L_OcrOMROptions omrOptions = {0}; 
 
   omrOptions.StructSize = sizeof(L_OcrOMROptions); 
 
   // Create an instance of the engine 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
 
   L_OcrEngine_GetZoneManager(ocrEngine, &zoneManager); 
 
   // Load an image to process 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Mixed.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
 
   // Add the image to an OCR page 
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
 
   // Transfer ownership to the OCR page 
   bitmap.Flags.Allocated = 0; 
 
   // Add the OMR zones. We calculated the 3 OMR zone boundaries for this image previously 
   L_RECT omrBounds[3] =  
   { 
      { 484, 98, 84, 78 }, 
      { 494, 184, 70, 54 }, 
      { 498, 244, 76, 76 } 
   }; 
 
   for(L_UINT i = 0; i < _countof(omrBounds); i++) 
   { 
      // Create a new OMR zone and add it to the page 
      L_OcrZone zone = {0}; 
      L_OcrZone_Default(&zone); 
      zone.ZoneType = L_OcrZoneType_OMR; 
      zone.Bounds = omrBounds[i]; 
      L_OcrPage_AddZone(ocrPage, &zone); 
   } 
 
   // Change the OMR options (Auto detection of frames with highest sensitivity) 
   L_OcrZoneManager_GetOMROptions(zoneManager, &omrOptions); 
   omrOptions.FrameDetectionMethod = L_OcrOMRFrameDetectionMethod_Auto; 
   omrOptions.Sensitivity = L_OcrOMRSensitivity_Highest; 
   L_OcrZoneManager_SetOMROptions(zoneManager, &omrOptions); 
 
   // Recognize the page 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
 
   // Now show the OMR zone properties 
   L_UINT count = 0; 
   L_OcrPage_GetZoneCount(ocrPage, &count); 
   for (L_UINT i = 0; i < count; i++) 
   { 
      L_OcrPageCharacters pageCharacters = {0}; 
      pageCharacters.StructSize = sizeof(L_OcrPageCharacters); 
      L_INT nRet = L_OcrPage_GetRecognizedCharacters(ocrPage, &pageCharacters); 
      if(nRet == SUCCESS) 
      { 
         if(pageCharacters.ZoneCharacterCount > 0) 
         { 
            L_OcrCharacter omrCharacter = pageCharacters.ZoneCharacters[i].Characters[0]; 
 
            LogMessage(L"%u: State: %s, Confidence: %u", i + 1, omrCharacter.Code == omrOptions.StateRecognitionCharacters[1] ? L"Filled" : L"Unfilled", omrCharacter.Confidence); 
         } 
 
         // We should free the page characters 
         L_OcrPage_FreePageCharacters(&pageCharacters); 
      } 
   } 
 
   // Now save the result as PDF using the default characters representation for OMR states (0 for unfilled, 1 for filled) 
   L_TCHAR* pdfFileName1 = MAKE_IMAGE_PATH(L_TEXT("Omr_Results1.pdf")); 
   LogMessage(L"Saving to %s", pdfFileName1); 
 
   //Create an OCR document 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
 
   //Add OCR Page to OCR document 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
 
   L_OcrDocument_Save(ocrDocument, pdfFileName1, DOCUMENTFORMAT_PDF, NULL, NULL); 
 
   // Change the character representation for the OMR states to Y for unfilled, and X for filled 
   omrOptions.StateRecognitionCharacters[0] = 'Y'; 
   omrOptions.StateRecognitionCharacters[1] = 'X'; 
   L_OcrZoneManager_SetOMROptions(zoneManager, &omrOptions); 
 
   L_TCHAR* pdfFileName2 = MAKE_IMAGE_PATH(L_TEXT("Omr_Results2.pdf")); 
   LogMessage(L"Saving to %s", pdfFileName2); 
 
   L_OcrDocument_Save(ocrDocument, pdfFileName2, DOCUMENTFORMAT_PDF, NULL, NULL); 
 
   //CLEANUP 
   if(bitmap.Flags.Allocated) 
      L_FreeBitmap(&bitmap); 
 
   if(ocrPage != NULL) 
      L_OcrPage_Destroy(ocrPage); 
 
   if(ocrDocument != NULL) 
      L_OcrDocument_Destroy(ocrDocument); 
 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
 
   return SUCCESS; 
} 

Help Version 20.0.2018.2.22
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS OCR Module - LEAD Engine C API Help