public void Load(
string fileName
)
Overloads Sub Load( _
ByVal fileName As String _
)
void Load(
String^ fileName
)
fileName
The name of the file containing the settings.
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. You can later reload these settings and use them in the same or different instance of IOcrEngine.
The following table lists all of 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 disk file using Save, you can load and save the settings into any .NET stream using Load and Save.
This example changes some OCR engine settings and saves them to a file. It shuts down the engine, restarts it and reloads the last settings used.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Ocr;
using Leadtools.Document.Writer;
public void LoadSettingsExample1()
{
string settingsFileName = Path.Combine(LEAD_VARS.ImagesDir, "PlusSettings.xml");
string userDictionaryFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyDictionary.ud");
// 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;
// Enable English and German character sets
ocrEngine.LanguageManager.EnableLanguages(new string[] { "en", "de" });
// Set the spell checking options
ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native;
ocrEngine.SpellCheckManager.SpellLanguage = "en";
// 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(settingsFileName);
// Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown();
}
// Now create another instance of the engine, load the settings and make sure they are the same
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;
// Load the settings
settingManager.Load(settingsFileName);
// 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.SpellCheckEngine == OcrSpellCheckEngine.Native);
Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage == "en");
// 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();
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS21\Bin\Common\OcrLEADRuntime";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Ocr
Imports Leadtools.Document.Writer
Public Sub LoadSettingsExample1()
Dim settingsFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "PlusSettings.xml")
Dim userDictionaryFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyDictionary.ud")
' Create an instance of the engine
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)
' Start the engine using default parameters
ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)
Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager
' Enable English and German character sets
ocrEngine.LanguageManager.EnableLanguages(New String() {"en", "de"})
' Set the spell checking options
ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native
ocrEngine.SpellCheckManager.SpellLanguage = "en"
' 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", Nothing)
' 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(settingsFileName)
' Note: calling Dispose will also automatically shutdown the engine if it has been started
ocrEngine.Shutdown()
End Using
' Now create another instance of the engine, load the settings and make sure they are the same
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)
' Start the engine using default parameters
ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)
Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager
' Load the settings
settingManager.Load(settingsFileName)
' Check the character set
Dim languages As String() = ocrEngine.LanguageManager.GetEnabledLanguages()
Debug.Assert(languages(0) = "en" AndAlso languages(1) = "de")
' Check the spell checking options
Debug.Assert(ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native)
Debug.Assert(ocrEngine.SpellCheckManager.SpellLanguage = "en")
' 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") 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 started
ocrEngine.Shutdown()
End Using
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"
Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS21\Bin\Common\OcrLEADRuntime"
End Class
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