Loads the OCR engine settings from a .NET stream.
public void Load(Stream stream)
Overloads Sub Load( _ByVal stream As Stream _)
void Load(Stream^ stream)
stream
The stream to read the settings from.
Once you set up the OCR engine, you can re-use these settings by saving the engine state into memory or to an XML file on disk. Later, reload these settings and use them in the same or a different instance of IOcrEngine.
The following table lists all the states loaded from the XML file. After the load operation completes, some or all of the settings below will be changed.
| 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 the IOcrDocumentManager.RejectionSymbol and IOcrDocumentManager.MissingSymbol. |
You can save the settings to a .NET stream using Save, you can load and save the settings to a disk file using Load and Save.
This example will change some of the settings of the OCR engine and saves into a memory stream. It the shuts down the engine, restarts it and reloads the last settings used.
using Leadtools;using Leadtools.Codecs;using Leadtools.Forms.Ocr;using Leadtools.Forms.DocumentWriters;public void LoadSettingsExample2(){string userDictionaryFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyDictionary.ud");// Stream to save the settings toMemoryStream ms = new MemoryStream();// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);IOcrSettingManager settingManager = ocrEngine.SettingManager;// Enable English and German character setsocrEngine.LanguageManager.EnableLanguages(new string[] { "en", "de" });// Set the spell checking optionsocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.None;ocrEngine.SpellCheckManager.SpellLanguage = "en";// Change some settingssettingManager.SetValue("SaveDocument.FormatLevel", "Part");settingManager.SetBooleanValue("SaveDocument.Document.TextInBoxes", false);settingManager.SetIntegerValue("SaveDocument.Document.Margin.Left", 2400);settingManager.SetStringValue("SaveDocument.Character.ProportionalSansSerifFontName", "MyFont");settingManager.SetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator", "MyMark");settingManager.SetValue("SaveDocument.Mark.BeginOfLineSeparator", null);// Change an enum using an integersettingManager.SetEnumValue("SaveDocument.Mark.SuspectedCharacterColor", 7);// Change an enum using stringssettingManager.SetEnumValue("SaveDocument.Mark.RejectionCharacterColor", "Blue, Green, Red");// Save the settingssettingManager.Save(ms);// Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown();}// Reset the stream position to the beginningms.Position = 0;// Now create another instance of the engine, load the settings and make sure they are the sameusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);IOcrSettingManager settingManager = ocrEngine.SettingManager;// Load the settingssettingManager.Load(ms);// Check the character setstring[] languages = ocrEngine.LanguageManager.GetEnabledLanguages();Debug.Assert(languages[0] == "en" && languages[1] == "de");// Check the spell checking optionsDebug.Assert(ocrEngine.SpellCheckManager.SpellCheckEngine == OcrSpellCheckEngine.Native);Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage == "en");// Check the settingsDebug.Assert(settingManager.GetValue("SaveDocument.FormatLevel") == "Part");Debug.Assert(settingManager.GetBooleanValue("SaveDocument.Document.TextInBoxes") == false);Debug.Assert(settingManager.GetIntegerValue("SaveDocument.Document.Margin.Left") == 2400);Debug.Assert(settingManager.GetStringValue("SaveDocument.Character.ProportionalSansSerifFontName") == "MyFont");Debug.Assert(settingManager.GetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator") == "MyMark");Debug.Assert(settingManager.GetValue("SaveDocument.Mark.BeginOfLineSeparator") == null);Debug.Assert(settingManager.GetEnumValue("SaveDocument.Mark.SuspectedCharacterColor") == 7);Debug.Assert(settingManager.GetEnumValueAsString("SaveDocument.Mark.RejectionCharacterColor") == "Blue, Green, Red");// Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown();}}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Forms.OcrImports Leadtools.Forms.DocumentWritersPublic Sub LoadSettingsExample2()Dim userDictionaryFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyDictionary.ud")' Stream to save the settings toDim ms As New MemoryStream()' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager' Enable English and German character setsocrEngine.LanguageManager.EnableLanguages(New String() {"en", "de"})' Set the spell checking optionsocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.NoneocrEngine.SpellCheckManager.SpellLanguage = "en"' Change some settingssettingManager.SetValue("SaveDocument.FormatLevel", "Part")settingManager.SetBooleanValue("SaveDocument.Document.TextInBoxes", False)settingManager.SetIntegerValue("SaveDocument.Document.Margin.Left", 2400)settingManager.SetStringValue("SaveDocument.Character.ProportionalSansSerifFontName", "MyFont")settingManager.SetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator", "MyMark")settingManager.SetValue("SaveDocument.Mark.BeginOfLineSeparator", Nothing)' Change an enum using an integersettingManager.SetEnumValue("SaveDocument.Mark.SuspectedCharacterColor", 7)' Change an enum using stringssettingManager.SetEnumValue("SaveDocument.Mark.RejectionCharacterColor", "Blue, Green, Red")' Save the settingssettingManager.Save(ms)' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End Using' Reset the stream position to the beginningms.Position = 0' Now create another instance of the engine, load the settings and make sure they are the sameUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager' Load the settingssettingManager.Load(ms)' Check the character setDim languages As String() = ocrEngine.LanguageManager.GetEnabledLanguages()Debug.Assert(languages(0) = "en" AndAlso languages(1) = "de")' Check the spell checking optionsDebug.Assert(ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native)Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage = "en")' Check the settingsDebug.Assert(settingManager.GetValue("SaveDocument.FormatLevel") = "Part")Debug.Assert(settingManager.GetBooleanValue("SaveDocument.Document.TextInBoxes") = False)Debug.Assert(settingManager.GetIntegerValue("SaveDocument.Document.Margin.Left") = 2400)Debug.Assert(settingManager.GetStringValue("SaveDocument.Character.ProportionalSansSerifFontName") = "MyFont")Debug.Assert(settingManager.GetStringValue("SaveDocument.Mark.BeforeMissingCharacterSeparator") = "MyMark")Debug.Assert(settingManager.GetValue("SaveDocument.Mark.BeginOfLineSeparator") Is Nothing)Debug.Assert(settingManager.GetEnumValue("SaveDocument.Mark.SuspectedCharacterColor") = 7)Debug.Assert(settingManager.GetEnumValueAsString("SaveDocument.Mark.RejectionCharacterColor") = "Blue, Green, Red")' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"End Class
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
