Leadtools.Forms.Ocr Namespace : IOcrSettingManager Interface |
public interface IOcrSettingManager
'Declaration Public Interface IOcrSettingManager
'Usage Dim instance As IOcrSettingManager
public interface IOcrSettingManager
function Leadtools.Forms.Ocr.IOcrSettingManager()
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.
Public Sub OcrSettingManagerExample() ' Create an instance of the engine Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False) ' Start the engine using default parameters ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing) Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager ' Dump all the settings supported by this engine to a text file on disk DumpAllSettings(settingManager) ' Change the format level to drop Dim settingName As String = "SaveDocument.FormatLevel" settingManager.SetEnumValue(settingName, "Drop") ' Now use the new settings, notice that the result PDF file should not contain images Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf") ' Create an OCR document Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() ' Add a page to the document Dim 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 page ocrPage.Recognize(Nothing) ' Save the document we have as PDF ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing) End Using ' Shutdown the engine ' Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown() End Using End Sub Private Sub DumpAllSettings(ByVal settingManager As IOcrSettingManager) ' Write all the settings into a disk file Dim 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 settingNames Dim 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.ValueType) Case OcrSettingValueType.BeginCategory writer.WriteLine("-------------------------------------") Case OcrSettingValueType.Integer writer.WriteLine(" Units: {0}", sd.Units) writer.WriteLine(" IntegerMinimumValue: {0}", sd.IntegerMinimumValue) writer.WriteLine(" IntegerMaximumValue: {0}", sd.IntegerMaximumValue) Case OcrSettingValueType.Enum writer.WriteLine(" EnumIsFlags: {0}", sd.EnumIsFlags) writer.WriteLine(" EnumMemberFriendlyNames") Dim values() As Integer = sd.GetEnumMemberValues() Dim names() As String = sd.GetEnumMemberFriendlyNames() For i As Integer = 0 To values.Length - 1 writer.WriteLine(" {0} : {1}", names(i), values(i)) Next Case OcrSettingValueType.Double writer.WriteLine(" Units: {0}", sd.Units) writer.WriteLine(" DoubleMinimumValue: {0}", sd.DoubleMinimumValue) writer.WriteLine(" DoubleMaximumValue: {0}", sd.DoubleMaximumValue) Case OcrSettingValueType.Boolean Case OcrSettingValueType.Character Case OcrSettingValueType.String writer.WriteLine(" StringMaximumLength: {0}", sd.StringMaximumLength) writer.WriteLine(" StringNullAllowed: {0}", sd.StringNullAllowed) Case OcrSettingValueType.Rectangle Case OcrSettingValueType.EndCategory End Select Next End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void OcrSettingManagerExample() { // 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; // Dump all the settings supported by this engine to a text file on disk DumpAllSettings(settingManager); // Change the format level to drop string settingName = "SaveDocument.FormatLevel"; settingManager.SetEnumValue(settingName, "Drop"); // Now use the new settings, notice that the result PDF file should not contain images string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); // Create an OCR document 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(pdfFileName, DocumentFormat.Pdf, null); } // Shutdown the engine // Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown(); } } private 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:\Users\Public\Documents\LEADTOOLS Images"; }
[TestMethod] public async Task OcrSettingManagerExample() { // Create an instance of the engine IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false); // Start the engine using default parameters ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath); IOcrSettingManager settingManager = ocrEngine.SettingManager; // Dump all the settings supported by this engine to a text file on disk await DumpAllSettings(settingManager); // Change the RecognitionModuleTradeoff to drop string settingName = "Recognition.RecognitionModuleTradeoff"; settingManager.SetEnumValue(settingName, "Fast"); // Now use the new settings, notice that the result PDF file should not contain images string tifFileName = @"Assets\Ocr1.tif"; string pdfFileName = "Ocr1.pdf"; // Create an OCR document IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(); // Add a page to the document IOcrPage ocrPage = null; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName); using (RasterCodecs codecs = new RasterCodecs()) { using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile))) ocrPage = ocrDocument.Pages.AddPage(image, 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 StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting); await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null); // Shutdown the engine ocrEngine.Shutdown(); } private async Task DumpAllSettings(IOcrSettingManager settingManager) { // Write all the settings into a disk file string settingsFileName = "Settings.txt"; StorageFile file = await Tools.AppLocalFolder.CreateFileAsync(settingsFileName); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0)) { using (DataWriter writer = new DataWriter(outputStream)) { writer.WriteString("Settings"); string[] settingNames = settingManager.GetSettingNames(); foreach (string settingName in settingNames) { IOcrSettingDescriptor sd = settingManager.GetSettingDescriptor(settingName); writer.WriteString(string.Format(" Name: {0}", sd.Name)); writer.WriteString(string.Format(" ValueType: {0}", sd.ValueType)); writer.WriteString(string.Format(" FriendlyName: {0}", sd.FriendlyName)); switch (sd.ValueType) { case OcrSettingValueType.BeginCategory: writer.WriteString("-------------------------------------"); break; case OcrSettingValueType.Integer: writer.WriteString(string.Format(" Units: {0}", sd.Units)); writer.WriteString(string.Format(" IntegerMinimumValue: {0}", sd.IntegerMinimumValue)); writer.WriteString(string.Format(" IntegerMaximumValue: {0}", sd.IntegerMaximumValue)); break; case OcrSettingValueType.Enum: writer.WriteString(string.Format(" EnumIsFlags: {0}", sd.EnumIsFlags)); writer.WriteString(" EnumMemberFriendlyNames"); { int[] values = sd.GetEnumMemberValues(); string[] names = sd.GetEnumMemberFriendlyNames(); for (int i = 0; i < values.Length; i++) { writer.WriteString(string.Format(" {0} : {1}", names[i], values[i])); } } break; case OcrSettingValueType.Double: writer.WriteString(string.Format(" Units: {0}", sd.Units)); writer.WriteString(string.Format(" DoubleMinimumValue: {0}", sd.DoubleMinimumValue)); writer.WriteString(string.Format(" DoubleMaximumValue: {0}", sd.DoubleMaximumValue)); break; case OcrSettingValueType.Boolean: break; case OcrSettingValueType.Character: break; case OcrSettingValueType.String: writer.WriteString(string.Format(" StringMaximumLength: {0}", sd.StringMaximumLength)); writer.WriteString(string.Format(" StringNullAllowed: {0}", sd.StringNullAllowed)); break; case OcrSettingValueType.Rectangle: break; case OcrSettingValueType.EndCategory: break; default: break; } } await writer.StoreAsync(); writer.DetachStream(); } await outputStream.FlushAsync(); } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
IOcrSettingManager Members
Leadtools.Forms.Ocr Namespace
GetSettingNames Method
GetSettingDescriptor Method
GetSettingDescriptor Method
OcrSettingValueType Enumeration
IOcrEngine Interface
IOcrEngine.Startup
IOcrEngine.IsStarted
IOcrEngine.Shutdown
OcrEngineManager Class
OcrEngineType Enumeration
IOcrLanguageManager Interface
IOcrSpellCheckManager Interface
Programming with the LEADTOOLS .NET OCR
Files to be Included with Your Application
OCR engine-specific Settings
public interface IOcrSettingManager
'Declaration Public Interface IOcrSettingManager
'Usage Dim instance As IOcrSettingManager
public interface IOcrSettingManager
function Leadtools.Forms.Ocr.IOcrSettingManager()
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.
Public Sub OcrSettingManagerExample() ' Create an instance of the engine Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False) ' Start the engine using default parameters ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing) Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager ' Dump all the settings supported by this engine to a text file on disk DumpAllSettings(settingManager) ' Change the format level to drop Dim settingName As String = "SaveDocument.FormatLevel" settingManager.SetEnumValue(settingName, "Drop") ' Now use the new settings, notice that the result PDF file should not contain images Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf") ' Create an OCR document Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() ' Add a page to the document Dim 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 page ocrPage.Recognize(Nothing) ' Save the document we have as PDF ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing) End Using ' Shutdown the engine ' Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown() End Using End Sub Private Sub DumpAllSettings(ByVal settingManager As IOcrSettingManager) ' Write all the settings into a disk file Dim 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 settingNames Dim 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.ValueType) Case OcrSettingValueType.BeginCategory writer.WriteLine("-------------------------------------") Case OcrSettingValueType.Integer writer.WriteLine(" Units: {0}", sd.Units) writer.WriteLine(" IntegerMinimumValue: {0}", sd.IntegerMinimumValue) writer.WriteLine(" IntegerMaximumValue: {0}", sd.IntegerMaximumValue) Case OcrSettingValueType.Enum writer.WriteLine(" EnumIsFlags: {0}", sd.EnumIsFlags) writer.WriteLine(" EnumMemberFriendlyNames") Dim values() As Integer = sd.GetEnumMemberValues() Dim names() As String = sd.GetEnumMemberFriendlyNames() For i As Integer = 0 To values.Length - 1 writer.WriteLine(" {0} : {1}", names(i), values(i)) Next Case OcrSettingValueType.Double writer.WriteLine(" Units: {0}", sd.Units) writer.WriteLine(" DoubleMinimumValue: {0}", sd.DoubleMinimumValue) writer.WriteLine(" DoubleMaximumValue: {0}", sd.DoubleMaximumValue) Case OcrSettingValueType.Boolean Case OcrSettingValueType.Character Case OcrSettingValueType.String writer.WriteLine(" StringMaximumLength: {0}", sd.StringMaximumLength) writer.WriteLine(" StringNullAllowed: {0}", sd.StringNullAllowed) Case OcrSettingValueType.Rectangle Case OcrSettingValueType.EndCategory End Select Next End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void OcrSettingManagerExample() { // 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; // Dump all the settings supported by this engine to a text file on disk DumpAllSettings(settingManager); // Change the format level to drop string settingName = "SaveDocument.FormatLevel"; settingManager.SetEnumValue(settingName, "Drop"); // Now use the new settings, notice that the result PDF file should not contain images string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf"); // Create an OCR document 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(pdfFileName, DocumentFormat.Pdf, null); } // Shutdown the engine // Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown(); } } private 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:\Users\Public\Documents\LEADTOOLS Images"; }
[TestMethod] public async Task OcrSettingManagerExample() { // Create an instance of the engine IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false); // Start the engine using default parameters ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath); IOcrSettingManager settingManager = ocrEngine.SettingManager; // Dump all the settings supported by this engine to a text file on disk await DumpAllSettings(settingManager); // Change the RecognitionModuleTradeoff to drop string settingName = "Recognition.RecognitionModuleTradeoff"; settingManager.SetEnumValue(settingName, "Fast"); // Now use the new settings, notice that the result PDF file should not contain images string tifFileName = @"Assets\Ocr1.tif"; string pdfFileName = "Ocr1.pdf"; // Create an OCR document IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(); // Add a page to the document IOcrPage ocrPage = null; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName); using (RasterCodecs codecs = new RasterCodecs()) { using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile))) ocrPage = ocrDocument.Pages.AddPage(image, 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 StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting); await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null); // Shutdown the engine ocrEngine.Shutdown(); } private async Task DumpAllSettings(IOcrSettingManager settingManager) { // Write all the settings into a disk file string settingsFileName = "Settings.txt"; StorageFile file = await Tools.AppLocalFolder.CreateFileAsync(settingsFileName); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0)) { using (DataWriter writer = new DataWriter(outputStream)) { writer.WriteString("Settings"); string[] settingNames = settingManager.GetSettingNames(); foreach (string settingName in settingNames) { IOcrSettingDescriptor sd = settingManager.GetSettingDescriptor(settingName); writer.WriteString(string.Format(" Name: {0}", sd.Name)); writer.WriteString(string.Format(" ValueType: {0}", sd.ValueType)); writer.WriteString(string.Format(" FriendlyName: {0}", sd.FriendlyName)); switch (sd.ValueType) { case OcrSettingValueType.BeginCategory: writer.WriteString("-------------------------------------"); break; case OcrSettingValueType.Integer: writer.WriteString(string.Format(" Units: {0}", sd.Units)); writer.WriteString(string.Format(" IntegerMinimumValue: {0}", sd.IntegerMinimumValue)); writer.WriteString(string.Format(" IntegerMaximumValue: {0}", sd.IntegerMaximumValue)); break; case OcrSettingValueType.Enum: writer.WriteString(string.Format(" EnumIsFlags: {0}", sd.EnumIsFlags)); writer.WriteString(" EnumMemberFriendlyNames"); { int[] values = sd.GetEnumMemberValues(); string[] names = sd.GetEnumMemberFriendlyNames(); for (int i = 0; i < values.Length; i++) { writer.WriteString(string.Format(" {0} : {1}", names[i], values[i])); } } break; case OcrSettingValueType.Double: writer.WriteString(string.Format(" Units: {0}", sd.Units)); writer.WriteString(string.Format(" DoubleMinimumValue: {0}", sd.DoubleMinimumValue)); writer.WriteString(string.Format(" DoubleMaximumValue: {0}", sd.DoubleMaximumValue)); break; case OcrSettingValueType.Boolean: break; case OcrSettingValueType.Character: break; case OcrSettingValueType.String: writer.WriteString(string.Format(" StringMaximumLength: {0}", sd.StringMaximumLength)); writer.WriteString(string.Format(" StringNullAllowed: {0}", sd.StringNullAllowed)); break; case OcrSettingValueType.Rectangle: break; case OcrSettingValueType.EndCategory: break; default: break; } } await writer.StoreAsync(); writer.DetachStream(); } await outputStream.FlushAsync(); } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
IOcrSettingManager Members
Leadtools.Forms.Ocr Namespace
GetSettingNames Method
GetSettingDescriptor Method
GetSettingDescriptor Method
OcrSettingValueType Enumeration
IOcrEngine Interface
IOcrEngine.Startup
IOcrEngine.IsStarted
IOcrEngine.Shutdown
OcrEngineManager Class
OcrEngineType Enumeration
IOcrLanguageManager Interface
IOcrSpellCheckManager Interface
Programming with the LEADTOOLS .NET OCR
Files to be Included with Your Application
OCR engine-specific Settings