L_OcrZoneManager_GetOMROptions

Summary

Gets the OMR options currently used by the engine.

Syntax

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrZoneManager_GetOMROptions(zoneManager, value)

Parameters

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.

Returns

Value Meaning
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 Module - LEAD Engine does not 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

See Also

Functions

Topics

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_LEAD, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_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 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 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.