L_OcrZoneManager_GetOMROptions

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrZoneManager_GetOMROptions(zoneManager, value)

L_OcrZoneManager zoneManager; handle to the OCR engine zone manager
L_OcrOMROptions* value; address to variable of type L_OcrOMROptions structure to be updated with the OMR options

Gets the OMR options currently used by the engine.

Parameter Description
zoneManager Handle to the OCR engine zone manager.
value Address to variable of type L_OcrOMROptions structure to be updated with the OMR options.

Returns

SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Gets the OMR options currently used by the engine.

OMR stands for Optical Mark Recognition. For more information refer to Using Using OMR in LEADTOOLS C API OCR.

With the L_OcrOMROptions, you can change the following OMR settings:

The OMR zones of a page have the L_OcrZone.ZoneType property set to L_OcrZoneType_OMR.

Currently LEADTOOLS OCR Advantage engines doesn't supports auto detection of OMR zones. Instead, you need to: add the OMR zones manually to the page by setting their boundary (through L_OcrZone.Bounds, the zone type through L_OcrZone.ZoneType and adding the zone to the page using the L_OcrPage_AddZone or L_OcrPage_InsertZone before calling L_OcrPage_Recognize.

To use OMR in LEADTOOLS, you need a special key to unlock the OMR capabilities. For more information, refer to Setting a Runtime License.

Required DLLs and Libraries

LTOCR
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrZoneManager_SetOMROptions
Topics: Programming with LEADTOOLS OCR Advantage
LEADTOOLS OCR Advantage Engine Settings
Recognizing OCR Pages
Using OMR in LEADTOOLS C API OCR

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
#define OCR_ADVANTAGE_RUNTIME_DIR TEXT("C:\\LEADTOOLS 19\\Bin\\Common\\OcrAdvantageRuntime") 
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 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Advantage OCR C API Help