Loads the OCR engine settings from a .NET stream.
Syntax
Visual Basic (Declaration) | |
---|
Overloads Overridable Sub Load( _
ByVal stream As Stream _
) |
Parameters
- stream
- The stream to read the settings from.
Example
This example will change some of the settings of the OCR engine and saves into a memory stream. Shutsdown the engine, restarts it and reload the last settings used.
Visual Basic | Copy Code |
---|
Public Sub LoadSettingsExample2()
RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
Dim userDictionaryFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "MyDictionary.ud"
Dim ms As New MemoryStream()
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager
ocrEngine.LanguageManager.EnableLanguages(New String() {"en", "de"})
ocrEngine.SpellCheckManager.Enabled = False
ocrEngine.SpellCheckManager.SpellLanguage = "en"
ocrEngine.SpellCheckManager.UserDictionary.Use(userDictionaryFileName, Nothing)
settingManager.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)
settingManager.SetEnumValue("SaveDocument.Mark.SuspectedCharacterColor", 7)
settingManager.SetEnumValue("SaveDocument.Mark.RejectionCharacterColor", "Blue, Green, Red")
settingManager.Save(ms)
ocrEngine.Shutdown()
End Using
ms.Position = 0
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager
settingManager.Load(ms)
Dim languages() As String = ocrEngine.LanguageManager.GetEnabledLanguages()
Debug.Assert(languages(0) = "en" AndAlso languages(1) = "de")
Debug.Assert(ocrEngine.SpellCheckManager.Enabled)
Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage = "en")
Debug.Assert(ocrEngine.SpellCheckManager.UserDictionary.FileName = userDictionaryFileName)
Debug.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") = Nothing)
Debug.Assert(settingManager.GetEnumValue("SaveDocument.Mark.SuspectedCharacterColor") = 7)
Debug.Assert(settingManager.GetEnumValueAsString("SaveDocument.Mark.RejectionCharacterColor") = "Blue, Green, Red")
ocrEngine.Shutdown()
End Using
End Sub |
C# | Copy Code |
---|
public void LoadSettingsExample2() { // Unlock the support needed for LEADTOOLS Plus OCR engine RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); string userDictionaryFileName = LeadtoolsExamples.Common.ImagesPath.Path + "MyDictionary.ud"; // Stream to save the settings to MemoryStream ms = new MemoryStream(); // Create an instance of the engine using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Start the engine using default parameters ocrEngine.Startup(null, null, null, null); IOcrSettingManager settingManager = ocrEngine.SettingManager; // Enable English and German character sets ocrEngine.LanguageManager.EnableLanguages(new string[] { "en", "de" }); // Set the spell checking options ocrEngine.SpellCheckManager.Enabled = false; ocrEngine.SpellCheckManager.SpellLanguage = "en"; ocrEngine.SpellCheckManager.UserDictionary.Use(userDictionaryFileName, null); // Change some settings settingManager.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 integer settingManager.SetEnumValue("SaveDocument.Mark.SuspectedCharacterColor", 7); // Change an enum using strings settingManager.SetEnumValue("SaveDocument.Mark.RejectionCharacterColor", "Blue, Green, Red"); // Save the settings settingManager.Save(ms); // Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown(); } // Reset the stream position to the beginning ms.Position = 0; // Now create another instance of the engine, load the settings and make sure they are the same using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Start the engine using default parameters ocrEngine.Startup(null, null, null, null); IOcrSettingManager settingManager = ocrEngine.SettingManager; // Load the settings settingManager.Load(ms); // Check the character set string[] languages = ocrEngine.LanguageManager.GetEnabledLanguages(); Debug.Assert(languages[0] == "en" && languages[1] == "de"); // Check the spell checking options Debug.Assert(ocrEngine.SpellCheckManager.Enabled); Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage == "en"); Debug.Assert(ocrEngine.SpellCheckManager.UserDictionary.FileName == userDictionaryFileName); // Check the settings Debug.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 started ocrEngine.Shutdown(); } } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also