public interface IOcrSettingManager Public Interface IOcrSettingManager @interface LTOcrSettingManager : NSObject public class OcrSettingManager public interface class IOcrSettingManager
Access the instance of the IOcrSettingManager used by an IOcrEngine through the IOcrEngine.SettingManager property.
IOcrSettingManager allows you to do the following:
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). Get all of the settings available to the current OCR engine through the GetSettingNames method. The GetSettingDescriptor method returns a description of the setting (its type, friendly name and value range). You can then use the various get and set methods to query and change the values of specific settings. For example, if the setting type is OcrSettingValueType.Integer, you can use the GetIntegerValue to get the current value of the setting and the SetIntegerValue to change its value. Refer to the example below for a complete demo.
This interface also contains methods to load and save the engine state to a .NET stream or an XML file on disk. The following table lists all the states saved:
| Part | Members |
|---|---|
| IOcrSettingManager (accessed through IOcrEngine.SettingManager | All the settings as obtained through IOcrSettingManager.GetSettingNames |
| IOcrLanguageManager (accessed through IOcrEngine.LanguageManager | The value of IOcrLanguageManager.GetEnabledLanguages |
| IOcrSpellCheckManager (accessed through IOcrEngine.SpellCheckManager | The values of IOcrSpellCheckManager.SpellCheckEngine and IOcrSpellCheckManager.SpellLanguage. |
| IOcrDocumentManager (accessed through IOcrEngine.DocumentManager | The values of IOcrDocumentManager.EngineFormat, IOcrDocumentManager.RejectionSymbol and IOcrDocumentManager.MissingSymbol. |
| IOcrZoneManager (accessed through IOcrEngine.ZoneManager | The values of IOcrZoneManager.OmrOptions.FrameDetectionMethod, IOcrZoneManager.OmrOptions.Sensitivity and the state characters of IOcrZoneManager.OmrOptions.GetStateRecognitionCharacter. |
You must call the IOcrEngine.Startup method before you can use the IOcrEngine.SettingManager property.
Note: The IOcrEngine.LanguageManager and IOcrEngine.SpellCheckManager state is also saved when the engine settings are saved. For more information, refer to IOcrSettingManager.Save.
For a list of supported engine-specific settings and their meanings, refer to OCR engine-specific Settings.
This example will start the LEADTOOLS OCR Module - LEAD Engine. Shows the values of all the settings and change a few of them.
using Leadtools;using Leadtools.Codecs;using Leadtools.Ocr;using Leadtools.Document.Writer;public void OcrSettingManagerExample(){// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);IOcrSettingManager settingManager = ocrEngine.SettingManager;// Dump all the settings supported by this engine to a text file on diskDumpAllSettings(settingManager);// Image file to OCRstring tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");// File formats to saveDocumentFormat[] formats = { DocumentFormat.Text, DocumentFormat.Pdf };foreach (DocumentFormat format in formats){// Generate the output file namestring 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 fasterConsole.WriteLine("Turning off font attributes");// Save the old settingsdetectFontStyles = settingManager.GetEnumValue("Recognition.Fonts.DetectFontStyles");recognizeFontAttributes = settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes");// Turn them off nowsettingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", "None");settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", false);}// Show the settings we are usingConsole.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 formatusing (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()){// Add a page to the documentIOcrPage 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 pageocrPage.Recognize(null);// Save the document we have as PDFocrDocument.Save(outFileName, format, null);}// Re-set the original settingsif (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 startedocrEngine.Shutdown();}}private static void DumpAllSettings(IOcrSettingManager settingManager){// Write all the settings into a disk filestring 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:\Users\Public\Documents\LEADTOOLS Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.OcrImports Leadtools.Document.WriterPublic Sub OcrSettingManagerExample()' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager' Dump all the settings supported by this engine to a text file on diskDumpAllSettings(settingManager)' Image file to OCRDim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")' File formats to saveDim formats As DocumentFormat() = {DocumentFormat.Text, DocumentFormat.Pdf}For Each format As DocumentFormat In formats' Generate the output file nameDim outFileName As String = Path.ChangeExtension(tifFileName, DocumentWriter.GetFormatFileExtension(format))Console.WriteLine("Format: {0}" & vbLf & "Output file: {1}", format, outFileName)Dim detectFontStyles As Integer = 0Dim recognizeFontAttributes As Boolean = FalseIf format = DocumentFormat.Text Then' This is 'text' format, we dont need to recognize fonts attributes such as bold and italic' This will make the recognition process fasterConsole.WriteLine("Turning off font attributes")' Save the old settingsdetectFontStyles = settingManager.GetEnumValue("Recognition.Fonts.DetectFontStyles")recognizeFontAttributes = settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes")' Turn them off nowsettingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", "None")settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", False)End If' Show the settings we are usingConsole.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 formatUsing ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()' Add a page to the documentDim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)' Recognize the page' Note, Recognize can be called without calling AutoZone or manually adding zones. The engine will' check and automatically auto-zones the pageocrPage.Recognize(Nothing)' Save the document we have as PDFocrDocument.Save(outFileName, format, Nothing)End Using' Re-set the original settingsIf format = DocumentFormat.Text ThenConsole.WriteLine("Resetting original settings")settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", detectFontStyles)settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", recognizeFontAttributes)End IfNext' Shutdown the engine' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End UsingEnd SubPrivate Shared Sub DumpAllSettings(settingManager As IOcrSettingManager)' Write all the settings into a disk fileDim settingsFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Settings.txt")Using writer As StreamWriter = File.CreateText(settingsFileName)writer.WriteLine("Settings")Dim settingNames As String() = settingManager.GetSettingNames()For Each settingName As String In settingNamesDim sd As IOcrSettingDescriptor = settingManager.GetSettingDescriptor(settingName)writer.WriteLine(" Name: {0}", sd.Name)writer.WriteLine(" ValueType: {0}", sd.ValueType)writer.WriteLine(" FriendlyName: {0}", sd.FriendlyName)Select Case sd.ValueTypeCase OcrSettingValueType.BeginCategorywriter.WriteLine("-------------------------------------")Exit SelectCase OcrSettingValueType.[Integer]writer.WriteLine(" Units: {0}", sd.Units)writer.WriteLine(" IntegerMinimumValue: {0}", sd.IntegerMinimumValue)writer.WriteLine(" IntegerMaximumValue: {0}", sd.IntegerMaximumValue)Exit SelectCase OcrSettingValueType.[Enum]writer.WriteLine(" EnumIsFlags: {0}", sd.EnumIsFlags)writer.WriteLine(" EnumMemberFriendlyNames")If True ThenDim values As Integer() = sd.GetEnumMemberValues()Dim names As String() = sd.GetEnumMemberFriendlyNames()For i As Integer = 0 To values.Length - 1writer.WriteLine(" {0} : {1}", names(i), values(i))NextEnd IfExit SelectCase OcrSettingValueType.[Double]writer.WriteLine(" Units: {0}", sd.Units)writer.WriteLine(" DoubleMinimumValue: {0}", sd.DoubleMinimumValue)writer.WriteLine(" DoubleMaximumValue: {0}", sd.DoubleMaximumValue)Exit SelectCase OcrSettingValueType.[Boolean]Exit SelectCase OcrSettingValueType.CharacterExit SelectCase OcrSettingValueType.[String]writer.WriteLine(" StringMaximumLength: {0}", sd.StringMaximumLength)writer.WriteLine(" StringNullAllowed: {0}", sd.StringNullAllowed)Exit SelectCase OcrSettingValueType.RectangleExit SelectCase OcrSettingValueType.EndCategoryExit SelectCase ElseExit SelectEnd SelectNextEnd UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"End Class
OcrSettingValueType Enumeration
IOcrSpellCheckManager Interface
Programming with the LEADTOOLS .NET OCR
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
