←Select platform

IOcrSettingDescriptor Interface

Summary
Defines a setting name, friendly name, type and range.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public interface IOcrSettingDescriptor 
@interface LTOcrSettingDescriptor : NSObject 
public class OcrSettingDescriptor 
public interface class IOcrSettingDescriptor  
class IOcrSettingDescriptor: 
Remarks

IOcrSettingDescriptor contains the properties of a setting. You can get the settings supported by the OCR engine by calling IOcrSettingManager.GetSettingNames and you can get the descriptor (an instance of IOcrSettingDescriptor) of a setting by calling IOcrSettingManager.GetSettingDescriptor.

The following table lists the members of IOcrSettingDescriptor and their meaning:

Member Description Valid For
IOcrSettingDescriptor.Name The unique name of setting. This is the same name you pass to IOcrSettingManager.GetSettingDescriptor All types
IOcrSettingDescriptor.ValueType One of the OcrSettingValueType enumeration member specifying the setting type All types
IOcrSettingDescriptor.FriendlyName Friendly name of the setting. You can use this name in your user application All types
IOcrSettingDescriptor.Units Name of the unit of the value OcrSettingValueType.Integer and OcrSettingValueType.Double
IOcrSettingDescriptor.IntegerMinimumValue Minimum allowed value of the setting OcrSettingValueType.Integer
IOcrSettingDescriptor.IntegerMaximumValue Maximum allowed value of the setting OcrSettingValueType.Integer
IOcrSettingDescriptor.EnumIsFlags If true, the enum setting members can be combined together (OR'ed), otherwise; only one enum member can be set at a time OcrSettingValueType.Enum
IOcrSettingDescriptor.GetEnumMemberFriendlyNames Returns an array of strings containing the enumeration members friendly names. You can use these name in your user application OcrSettingValueType.Enum
IOcrSettingDescriptor.GetEnumMemberValues Returns an array of integers containing the enumeration members values OcrSettingValueType.Enum
IOcrSettingDescriptor.DoubleMinimumValue Minimum allowed value of the setting OcrSettingValueType.Double
IOcrSettingDescriptor.DoubleMaximumValue Maximum allowed value of the setting OcrSettingValueType.Double
IOcrSettingDescriptor.StringMaximumLength Maximum number of characters in the value of the setting OcrSettingValueType.String
IOcrSettingDescriptor.StringNullAllowed A null (Nothing in Visual Basic) is a valid value for this setting OcrSettingValueType.String

IOcrEngine is a wrapper for different OCR engines, these engines contain specific additional features and functionalities that can be queried and updated using the IOcrSettingManager interface.

You can use the different methods of the IOcrSettingManager interface 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 IOcrSettingManager.GetSettingNames method. The IOcrSettingManager.GetSettingDescriptor method 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 OcrSettingValueType.Integer, you can use the IOcrSettingManager.GetIntegerValue to get the current value of the setting and the IOcrSettingManager.SetIntegerValue to change its value. Refer to IOcrSettingManager for a complete example.

For a list of supported engine-specific settings and their meanings, refer to OCR engine-specific Settings.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Document.Writer; 
 
public void OcrSettingManagerExample() 
{ 
   // Create an instance of the engine 
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
   { 
      // Start the engine using default parameters 
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
      IOcrSettingManager settingManager = ocrEngine.SettingManager; 
 
      // Dump all the settings supported by this engine to a text file on disk 
      DumpAllSettings(settingManager); 
 
      // Image file to OCR 
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
 
      // File formats to save 
      DocumentFormat[] formats = { DocumentFormat.Text, DocumentFormat.Pdf }; 
 
      foreach (DocumentFormat format in formats) 
      { 
         // Generate the output file name 
         string outFileName = Path.ChangeExtension(tifFileName, DocumentWriter.GetFormatFileExtension(format)); 
 
         Console.WriteLine("Format: {0}\nOutput file: {1}", format, outFileName); 
 
         int detectFontStyles = 0; 
         bool recognizeFontAttributes = false; 
 
         if (format == DocumentFormat.Text) 
         { 
            // This is 'text' format, we dont need to recognize fonts attributes such as bold and italic 
            // This will make the recognition process faster 
 
            Console.WriteLine("Turning off font attributes"); 
 
            // Save the old settings 
            detectFontStyles = settingManager.GetEnumValue("Recognition.Fonts.DetectFontStyles"); 
            recognizeFontAttributes = settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes"); 
 
            // Turn them off now 
            settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", "None"); 
            settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", false); 
         } 
 
         // Show the settings we are using 
         Console.WriteLine("Recognizing using these font attributes settings:"); 
         Console.WriteLine("Recognition.Fonts.DetectFontStyles: {0}", settingManager.GetEnumValueAsString("Recognition.Fonts.DetectFontStyles")); 
         Console.WriteLine("Recognition.Fonts.RecognizeFontAttributes: {0}", settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes")); 
 
 
         // Recognize and save the file to the output format 
         using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
         { 
            // Add a page to the document 
            IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); 
 
            // Recognize the page 
            // Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will 
            // check and automatically auto-zones the page 
            ocrPage.Recognize(null); 
 
            // Save the document we have as PDF 
            ocrDocument.Save(outFileName, format, null); 
         } 
 
         // Re-set the original settings 
         if (format == DocumentFormat.Text) 
         { 
            Console.WriteLine("Resetting original settings"); 
            settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", detectFontStyles); 
            settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", recognizeFontAttributes); 
         } 
      } 
 
      // Shutdown the engine 
      // Note: calling Dispose will also automatically shutdown the engine if it has been started 
      ocrEngine.Shutdown(); 
   } 
} 
 
private static void DumpAllSettings(IOcrSettingManager settingManager) 
{ 
   // Write all the settings into a disk file 
   string settingsFileName = Path.Combine(LEAD_VARS.ImagesDir, "Settings.txt"); 
   using (StreamWriter writer = File.CreateText(settingsFileName)) 
   { 
      writer.WriteLine("Settings"); 
      string[] settingNames = settingManager.GetSettingNames(); 
 
      foreach (string settingName in settingNames) 
      { 
         IOcrSettingDescriptor sd = settingManager.GetSettingDescriptor(settingName); 
 
         writer.WriteLine("  Name:           {0}", sd.Name); 
         writer.WriteLine("  ValueType:      {0}", sd.ValueType); 
         writer.WriteLine("  FriendlyName:   {0}", sd.FriendlyName); 
 
         switch (sd.ValueType) 
         { 
            case OcrSettingValueType.BeginCategory: 
               writer.WriteLine("-------------------------------------"); 
               break; 
 
            case OcrSettingValueType.Integer: 
               writer.WriteLine("    Units: {0}", sd.Units); 
               writer.WriteLine("    IntegerMinimumValue: {0}", sd.IntegerMinimumValue); 
               writer.WriteLine("    IntegerMaximumValue: {0}", sd.IntegerMaximumValue); 
               break; 
 
            case OcrSettingValueType.Enum: 
               writer.WriteLine("    EnumIsFlags: {0}", sd.EnumIsFlags); 
               writer.WriteLine("    EnumMemberFriendlyNames"); 
               { 
                  int[] values = sd.GetEnumMemberValues(); 
                  string[] names = sd.GetEnumMemberFriendlyNames(); 
                  for (int i = 0; i < values.Length; i++) 
                  { 
                     writer.WriteLine("      {0} : {1}", names[i], values[i]); 
                  } 
               } 
               break; 
 
            case OcrSettingValueType.Double: 
               writer.WriteLine("    Units: {0}", sd.Units); 
               writer.WriteLine("    DoubleMinimumValue: {0}", sd.DoubleMinimumValue); 
               writer.WriteLine("    DoubleMaximumValue: {0}", sd.DoubleMaximumValue); 
               break; 
 
            case OcrSettingValueType.Boolean: 
               break; 
 
            case OcrSettingValueType.Character: 
               break; 
 
            case OcrSettingValueType.String: 
               writer.WriteLine("    StringMaximumLength:   {0}", sd.StringMaximumLength); 
               writer.WriteLine("    StringNullAllowed:     {0}", sd.StringNullAllowed); 
               break; 
 
            case OcrSettingValueType.Rectangle: 
               break; 
 
            case OcrSettingValueType.EndCategory: 
               break; 
 
            default: 
               break; 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.4.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ocr Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.