LEADTOOLS OCR(Leadtools.Forms.Ocrアセンブリ)

フレームを表示

IOcrSettingManagerインターフェース








メンバ 
このIOcrEngineの基となるエンジンに特有の設定を管理します。
オブジェクトモデル
構文
public interface IOcrSettingManager 
'Declaration
 
Public Interface IOcrSettingManager 
'Usage
 
Dim instance As IOcrSettingManager
public interface IOcrSettingManager 
@interface LTOcrSettingManager : NSObject
public class OcrSettingManager
function Leadtools.Forms.Ocr.IOcrSettingManager() 
public interface class IOcrSettingManager 
解説

IOcrEngine.SettingManagerプロパティを通してIOcrEngineにより用いられるIOcrSettingManagerのインスタンスにアクセスします。

IOcrSettingManagerは、以下をすることができます:

エンジンに特有の設定を取得して設定するために、IOcrSettingManagerインターフェースの様々なメソッドを使います。各々の設定には、固有の名(文字列値)があります。GetSettingNamesメソッドを通して現在のOCRエンジンが利用できる設定の全てを取得します。GetSettingDescriptorメソッドは、設定(その型、フレンドリー名と値の範囲)の説明を返します。そうすることができます、そして、いろいろなものはメソッドを取得して設定する使用は特定の設定の値を問い合わせて、変更します。たとえば、設定型がOcrSettingValueType.Integerであるならば、その値を変更するために設定とSetIntegerValueの現在の値を取得するためにGetIntegerValueを使うことができます。完了したデモのために下記のサンプルを参照してください

このインターフェースは、ディスク上で.NETストリームまたはXMLファイルにエンジン状態をロードして保存するために、メソッドも格納します。以下の表は、保存されたすべての状態のリストです。

Part メンバ
IOcrSettingManagerIOcrEngine.SettingManagerを通してアクセスされます IOcrSettingManager.GetSettingNamesから得られるすべての設定
IOcrLanguageManagerIOcrEngine.LanguageManagerを通してアクセスされます IOcrLanguageManager.GetEnabledLanguagesの値
IOcrSpellCheckManagerIOcrEngine.SpellCheckManagerを通してアクセスされます IOcrSpellCheckManager.SpellCheckEngineIOcrSpellCheckManager.SpellLanguageの値。
IOcrDocumentManagerIOcrEngine.DocumentManagerを通してアクセスされます IOcrDocumentManager.EngineFormatIOcrDocumentManager.RejectionSymbolIOcrDocumentManager.MissingSymbolの値。
IOcrZoneManagerIOcrEngine.ZoneManagerを通してアクセスされます IOcrZoneManager.OmrOptions.GetStateRecognitionCharacterIOcrZoneManager.OmrOptions.FrameDetectionMethodIOcrZoneManager.OmrOptions.Sensitivityと州の文字の値。

IOcrEngine.SettingManagerプロパティを使うことができる前に、IOcrEngine.Startupメソッドを呼び出さなければなりません。

注意:エンジン設定が保存されるとき、IOcrEngine.LanguageManagerIOcrEngine.SpellCheckManager状態も保存されます。詳細については、「IOcrSettingManager.Save。」を参照してください。

サポートされたエンジンに特有の設定と意味のリストについては、エンジンに特有の設定のOCR処理を行うために、照会します。

サンプル

このサンプルは、LEADTOOLS OCR Advantageエンジンを開始します。すべての設定と変更の値に2、3を示します。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms.DocumentWriters

<TestMethod>
Public Sub OcrSettingManagerExample()
   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
      ' Start the engine using default parameters
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)
      Dim settingManager As IOcrSettingManager = ocrEngine.SettingManager

      ' Dump all the settings supported by this engine to a text file on disk
      DumpAllSettings(settingManager)

      ' Image file to OCR
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")

      ' File formats to save
      Dim formats As DocumentFormat() = {DocumentFormat.Text, DocumentFormat.Pdf}

      For Each format As DocumentFormat In formats
         ' Generate the output file name
         Dim outFileName As String = Path.ChangeExtension(tifFileName, DocumentWriter.GetFormatFileExtension(format))

         Console.WriteLine("Format: {0}" & vbLf & "Output file: {1}", format, outFileName)

         Dim detectFontStyles As Integer = 0
         Dim recognizeFontAttributes As Boolean = False

         If 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 faster

            Console.WriteLine("Turning off font attributes")

            ' Save the old settings
            detectFontStyles = settingManager.GetEnumValue("Recognition.Fonts.DetectFontStyles")
            recognizeFontAttributes = settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes")

            ' Turn them off now
            settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", "None")
            settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", False)
         End If

         ' Show the settings we are using
         Console.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 format
         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(outFileName, format, Nothing)
         End Using

         ' Re-set the original settings
         If format = DocumentFormat.Text Then
            Console.WriteLine("Resetting original settings")
            settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", detectFontStyles)
            settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", recognizeFontAttributes)
         End If
      Next

      ' Shutdown the engine
      ' Note: calling Dispose will also automatically shutdown the engine if it has been started
      ocrEngine.Shutdown()
   End Using
End Sub

Private Shared Sub DumpAllSettings(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("-------------------------------------")
               Exit Select

            Case OcrSettingValueType.[Integer]
               writer.WriteLine("    Units: {0}", sd.Units)
               writer.WriteLine("    IntegerMinimumValue: {0}", sd.IntegerMinimumValue)
               writer.WriteLine("    IntegerMaximumValue: {0}", sd.IntegerMaximumValue)
               Exit Select

            Case OcrSettingValueType.[Enum]
               writer.WriteLine("    EnumIsFlags: {0}", sd.EnumIsFlags)
               writer.WriteLine("    EnumMemberFriendlyNames")
               If True Then
                  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
               End If
               Exit Select

            Case OcrSettingValueType.[Double]
               writer.WriteLine("    Units: {0}", sd.Units)
               writer.WriteLine("    DoubleMinimumValue: {0}", sd.DoubleMinimumValue)
               writer.WriteLine("    DoubleMaximumValue: {0}", sd.DoubleMaximumValue)
               Exit Select

            Case OcrSettingValueType.[Boolean]
               Exit Select

            Case OcrSettingValueType.Character
               Exit Select

            Case OcrSettingValueType.[String]
               writer.WriteLine("    StringMaximumLength:   {0}", sd.StringMaximumLength)
               writer.WriteLine("    StringNullAllowed:     {0}", sd.StringNullAllowed)
               Exit Select

            Case OcrSettingValueType.Rectangle
               Exit Select

            Case OcrSettingValueType.EndCategory
               Exit Select
            Case Else

               Exit Select
         End Select
      Next
   End Using
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

public void OcrSettingManagerExample()
{
   // Create an instance of the engine
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
   {
      // Start the engine using default parameters
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);
      IOcrSettingManager settingManager = ocrEngine.SettingManager;

      // Dump all the settings supported by this engine to a text file on disk
      DumpAllSettings(settingManager);

      // Image file to OCR
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");

      // File formats to save
      DocumentFormat[] formats = { DocumentFormat.Text, DocumentFormat.Pdf };

      foreach (DocumentFormat format in formats)
      {
         // Generate the output file name
         string 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 faster

            Console.WriteLine("Turning off font attributes");

            // Save the old settings
            detectFontStyles = settingManager.GetEnumValue("Recognition.Fonts.DetectFontStyles");
            recognizeFontAttributes = settingManager.GetBooleanValue("Recognition.Fonts.RecognizeFontAttributes");

            // Turn them off now
            settingManager.SetEnumValue("Recognition.Fonts.DetectFontStyles", "None");
            settingManager.SetBooleanValue("Recognition.Fonts.RecognizeFontAttributes", false);
         }

         // Show the settings we are using
         Console.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 format
         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(outFileName, format, null);
         }

         // Re-set the original settings
         if (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 started
      ocrEngine.Shutdown();
   }
}

private static 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";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

      
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();
       }
   }
}
必要条件

ターゲットプラットホーム

参照

参照

IOcrSettingManagerメンバ
Leadtools.Forms.Ocr名前空間
GetSettingNamesメソッド
GetSettingDescriptorメソッド
GetSettingDescriptorメソッド
OcrSettingValueType列挙体
IOcrEngineインターフェース
IOcrEngine.Startup
IOcrEngine.IsStarted
IOcrEngine.Shutdown
OcrEngineManagerクラス
OcrEngineType列挙体
IOcrLanguageManagerインターフェース
IOcrSpellCheckManagerインターフェース
LEADTOOLS .NET OCRによるプログラミング
アプリケーションに含まれるファイル
エンジンに特有の設定のOCR処理を行います

Leadtools.Forms.Ocrは、認識またはDocument Imaging Suiteのライセンスと、解除キーが必要です。詳細は、以下を参照してください。LEADTOOLSツールキット機能