LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)

CreateEngine Method

Show in webframe
Example 







An OcrEngineType enumeration member that specifies the LEADTOOLS OCR engine type to use.
true to use the LEADTOOLS OCR Thunk Server when loading the engine, otherwise, false. Refer to Multi-Threading with LEADTOOLS OCR for more information.
Creates an instance of IOcrEngine.
Syntax
public static IOcrEngine CreateEngine( 
   OcrEngineType engineType,
   bool useThunkServer
)
'Declaration
 
Public Shared Function CreateEngine( _
   ByVal engineType As OcrEngineType, _
   ByVal useThunkServer As Boolean _
) As IOcrEngine
'Usage
 
Dim engineType As OcrEngineType
Dim useThunkServer As Boolean
Dim value As IOcrEngine
 
value = OcrEngineManager.CreateEngine(engineType, useThunkServer)
public static IOcrEngine CreateEngine( 
   OcrEngineType engineType,
   bool useThunkServer
)
+ (LTOcrEngine*)createEngine:(LTOcrEngineType)engineType;
public static OcrEngine createEngine(OcrEngineType engineType)
 function Leadtools.Forms.Ocr.OcrEngineManager.CreateEngine( 
   engineType ,
   useThunkServer 
)
public:
static IOcrEngine^ CreateEngine( 
   OcrEngineType engineType,
   bool useThunkServer
) 

Parameters

engineType
An OcrEngineType enumeration member that specifies the LEADTOOLS OCR engine type to use.
useThunkServer
true to use the LEADTOOLS OCR Thunk Server when loading the engine, otherwise, false. Refer to Multi-Threading with LEADTOOLS OCR for more information.

Return Value

The instance of IOcrEngine that this method creates.
Remarks

CreateEngine should be the first method your application calls into the Leadtools.Forms.Ocr assembly. Afterwards, you can use the properties and methods of this interface to perform your OCR tasks.

Based on the engine type passed to the CreateEngine methods, OcrEngineManager will load the OCR engine defined in one of the supporting assemblies and return an interface to IOcrEngine. Use this interface and its included types to start using the Leadtools.Forms.Ocr class library. For more information about the engine types, refer to OcrEngineType.

The CreateEngine method lets you create an instance of IOcrEngine, loading the corresponding Leadtools.Forms.Ocr.[EngineName].dll assembly using the .NET System.Reflection.Assembly.Load(string assemblyString) method. You cannot unload this assembly once it has been successfully loaded.

Depending on your application requirement, platform and OCR engine type; a "thunk" mechanism might be required. Refer to Multi-Threading with LEADTOOLS OCR for more information and on how to use the useThunkServer parameter.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.WinForms
Imports Leadtools.ImageProcessing.Core

Public Sub CreateEngineExample()
   ' 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 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

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

public void CreateEngineExample()
{
   // 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);
      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();
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime";
}
using Leadtools;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Codecs;

[TestMethod]
public async Task CreateEngineExample()
{
   // 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);

   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;
   using (RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName);
      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();
}
Requirements

Target Platforms

See Also

Reference

OcrEngineManager Class
OcrEngineManager Members
OcrEngineType Enumeration
Programming with the LEADTOOLS .NET OCR
Creating an OCR Engine Instance
Starting and Shutting Down the OCR Engine
Multi-Threading with LEADTOOLS OCR
LEADTOOLS OCR Thunk Server
Files to be Included with Your Application

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

CreateEngine requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features