L_OcrSettingManager_SetValue - OCR Module - LEAD Engine C++ API Help

L_OcrSettingManager_SetValue

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrSettingManager_SetValue(settingManager, settingName, value)

L_OcrSettingManager settingManager; handle to the OCR engine setting manager
const L_TCHAR* settingName; unique setting name
const L_TCHAR* value; new setting value as string

Sets the value of a setting from a string.

Parameter Description
settingManager Handle to the OCR engine setting manager.
settingName Name of the setting you wish to get its boolean value. This is the value you retrieved with a call to L_OcrSettingManager_GetSettingName method.
value New setting value as string.

Returns

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

Comments

Sets the value of a setting from a string.

To get the type of a setting along with other information such as its friendly name and range use the L_OcrSettingManager_GetSettingDescriptor method.

To get the value of a setting as a string, use L_OcrSettingManager_GetValue.

Note that settings of type L_OcrSettingValueType_BeginCategory and L_OcrSettingValueType_EndCategory have no values and will return an error if you try to get or set their values.

"value" must be convertible to the correct setting type. For example, if the setting is a L_OcrSettingValueType_Integer value, value can be "1" or "193". If the value cannot be converted, an error will return.

LEADTOOLS OCR Module - LEAD Engine contain specific additional features and functionality that can be queried and updated using different L_OcrSettingManager handle functions.

You can use the different methods of the L_OcrSettingManager handle to get and set the engine-specific settings. Each setting has a unique name (a string value). You can get all the settings available to the current OCR engine through the L_OcrSettingManager_GetSettingName method. The L_OcrSettingManager_GetSettingDescriptor and L_OcrSettingManager_GetSettingDescriptors methods returns a description of the setting (its type, friendly name and value range), you can then use the various setting get and set methods to query and change the value of a certain setting. For example, if the setting type is L_OcrSettingValueType_Integer, you can use the L_OcrSettingManager_GetIntegerValue to get the current value of the setting and the L_OcrSettingManager_SetIntegerValue to change its value. Refer to L_OcrEngine_GetSettingManager for a complete example.

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

Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
LEADTOOLS OCR Module - LEAD Engine Settings

Example

// In this example the user should pass the setting name and value as string 
L_INT L_OcrSettingManager_SetValueExample(const L_WCHAR* settingName, const L_TCHAR* settingValue) 
{ 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrSettingManager ocrSettingManager = NULL; 
   L_OcrPage ocrPage = NULL; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
   L_OcrDocument ocrDocument = NULL; 
 
   // 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); 
 
   // Get the manager to modify global OCR Engine settings 
   L_OcrEngine_GetSettingManager(ocrEngine, &ocrSettingManager); 
 
   // Load an image 
   retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Add image to OCR page 
   retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   if(retCode != SUCCESS) 
   { 
      L_FreeBitmap(&bitmap); 
      goto CLEANUP; 
   } 
 
   // Transfer ownership to OCR page 
   bitmap.Flags.Allocated = 0; 
 
   // check if the user passed setting name is supported first 
   retCode = L_OcrSettingManager_IsSettingNameSupported(ocrSettingManager, settingName); 
   if(!retCode) // setting name is not supported so return 
      goto CLEANUP; 
 
   L_OcrSettingValueType settingValueType; 
   L_OcrSettingManager_GetSettingValueType(ocrSettingManager, settingName, &settingValueType); 
 
   L_INT integerValue = 0; 
   L_DOUBLE doubleValue = 0; 
   L_TCHAR* stringValue = NULL; 
   switch(settingValueType) 
   { 
      case L_OcrSettingValueType_Integer: 
         L_OcrSettingManager_GetIntegerValue(ocrSettingManager, settingName, &integerValue); 
         if(integerValue != _ttoi(settingValue)) // Not the same value 
            L_OcrSettingManager_SetIntegerValue(ocrSettingManager, settingName, _ttoi(settingValue)); 
         break; 
 
      case L_OcrSettingValueType_Double: 
         L_OcrSettingManager_GetDoubleValue(ocrSettingManager, settingName, &doubleValue); 
         if(doubleValue != _ttof(settingValue)) // Not the same value 
            L_OcrSettingManager_SetDoubleValue(ocrSettingManager, settingName, _ttof(settingValue)); 
         break; 
 
      case L_OcrSettingValueType_String: 
         L_OcrSettingManager_GetStringValue(ocrSettingManager, settingName, &stringValue); 
         if(lstrcmp(stringValue, settingValue) != 0) // Not the same value 
            L_OcrSettingManager_SetStringValue(ocrSettingManager, settingName, settingValue); 
 
         // Free the retrieved string setting value  
         if(stringValue != NULL) 
            L_OcrMemory_Free(stringValue); 
         break; 
 
      default: 
         L_OcrSettingManager_GetValue(ocrSettingManager, settingName, &stringValue); 
         if(lstrcmp(stringValue, settingValue) != 0) // Not the same value 
            L_OcrSettingManager_SetValue(ocrSettingManager, settingName, settingValue); 
 
         // Free the retrieved string setting value  
         if(stringValue != NULL) 
            L_OcrMemory_Free(stringValue); 
         break; 
   } 
 
   // Recognize the page (automatically zoned) 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
 
   // Recognize and save the file to the output format 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
 
   // Create file-based OCR document 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
 
   // In Document File Mode, add OcrPage to OcrDocument after recognition 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
   L_OcrPage_Destroy(ocrPage); 
 
   // Save the document we have 
   L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Ocr.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL); 
 
CLEANUP: 
   if(ocrDocument != NULL) 
      L_OcrDocument_Destroy(ocrDocument); 
 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
   return SUCCESS; 
} 
Help Version 20.0.2018.6.21
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help