LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)

Startup Method

Show in webframe
Example 







Optional instance of a Leadtools.Codecs.RasterCodecs object to be used when loading image files from disk inside the engine. You can pass your own initialized instance of Leadtools.Codecs.RasterCodecs to be used. The same object will then be used internally by the OCR engine when loading raster image files. Otherwise, pass null (Nothing in Visual Basic) and the IOcrEngine will create and use its own version of Leadtools.Codecs.RasterCodecs when needed. Refer to RasterCodecsInstance for more information on how this parameter is used by the OCR engine during its lifetime, refer to OCR Engine and RasterCodecs/DocumentWriter Usage.
Optional instance of a Leadtools.Forms.DocumentWriters.DocumentWriter object to be used when saving OCR documents to disk inside the engine. You can pass your own initialized instance of Leadtools.Forms.DocumentWriters.DocumentWriter to be used. The same object will then be used internally by the OCR engine when saving OCR documents to disk. Otherwise, pass null (Nothing in Visual Basic) and the IOcrEngine will create and use its own version of Leadtools.Forms.DocumentWriters.DocumentWriter when needed. Refer to DocumentWriterInstance for more information on how this parameter is used by the OCR engine during its lifetime, refer to OCR Engine and RasterCodecs/DocumentWriter Usage.

Optional path to a directory to be used when the engine saves temporary files. The IOcrEngine object will create various temporary files during recognition and document saving processes. It will use the path passed in workDirectory as the location where these temporary files will be created. You can pass null (Nothing in Visual Basic) to let the engine select the temporary directory of the current logged in user (TEMP).

In either case, the value of working directory of the current started IOcrEngine can be obtained through the WorkDirectory property.

The engine automatically deletes any temporary files created. However, if an unexpected error occurs (for example, an unhandled exception), some temporary files may still reside in the work directory after the application exits. A typical application may use a custom directory inside the application path and manually deletes any files that may reside there before calling Startup in case the previous instance of the application exited abnormally.

If the value of the workDirectory parameter is not null (Nothing in Visual Basic), then it must refer to a valid directory that exists in the system and the process that created the engine must have enough access rights to read, write and delete files from this directory.

Optional startup parameter. The value of this parameter depends on the type of this IOcrEngine as follows:
Engine startupParameters
OcrEngineType.Advantage

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrAdvantageRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Arabic

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrArabicRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Plus

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrPlusRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Professional

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrProfessionalRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

Starts the OCR engine.
Syntax
'Declaration
 
Sub Startup( _
   ByVal rasterCodecs As RasterCodecs, _
   ByVal documentWriter As DocumentWriter, _
   ByVal workDirectory As String, _
   ByVal startupParameters As String _
) 
'Usage
 
Dim instance As IOcrEngine
Dim rasterCodecs As RasterCodecs
Dim documentWriter As DocumentWriter
Dim workDirectory As String
Dim startupParameters As String
 
instance.Startup(rasterCodecs, documentWriter, workDirectory, startupParameters)
- (void)startup:(LTRasterCodecs*)rasterCodecs
  workDirectory:(NSString*)workDirectory
artupParameters:(NSString*)startupParameters;
            
public void startup(RasterCodecs rasterCodecs,
                    String workDirectory,
                    String startupParameters,
                    String sharedLibsFolder)
            
function Leadtools.Forms.Ocr.IOcrEngine.Startup( 
   rasterCodecs ,
   documentWriter ,
   workDirectory ,
   startupParameters 
)

Parameters

rasterCodecs
Optional instance of a Leadtools.Codecs.RasterCodecs object to be used when loading image files from disk inside the engine. You can pass your own initialized instance of Leadtools.Codecs.RasterCodecs to be used. The same object will then be used internally by the OCR engine when loading raster image files. Otherwise, pass null (Nothing in Visual Basic) and the IOcrEngine will create and use its own version of Leadtools.Codecs.RasterCodecs when needed. Refer to RasterCodecsInstance for more information on how this parameter is used by the OCR engine during its lifetime, refer to OCR Engine and RasterCodecs/DocumentWriter Usage.
documentWriter
Optional instance of a Leadtools.Forms.DocumentWriters.DocumentWriter object to be used when saving OCR documents to disk inside the engine. You can pass your own initialized instance of Leadtools.Forms.DocumentWriters.DocumentWriter to be used. The same object will then be used internally by the OCR engine when saving OCR documents to disk. Otherwise, pass null (Nothing in Visual Basic) and the IOcrEngine will create and use its own version of Leadtools.Forms.DocumentWriters.DocumentWriter when needed. Refer to DocumentWriterInstance for more information on how this parameter is used by the OCR engine during its lifetime, refer to OCR Engine and RasterCodecs/DocumentWriter Usage.
workDirectory

Optional path to a directory to be used when the engine saves temporary files. The IOcrEngine object will create various temporary files during recognition and document saving processes. It will use the path passed in workDirectory as the location where these temporary files will be created. You can pass null (Nothing in Visual Basic) to let the engine select the temporary directory of the current logged in user (TEMP).

In either case, the value of working directory of the current started IOcrEngine can be obtained through the WorkDirectory property.

The engine automatically deletes any temporary files created. However, if an unexpected error occurs (for example, an unhandled exception), some temporary files may still reside in the work directory after the application exits. A typical application may use a custom directory inside the application path and manually deletes any files that may reside there before calling Startup in case the previous instance of the application exited abnormally.

If the value of the workDirectory parameter is not null (Nothing in Visual Basic), then it must refer to a valid directory that exists in the system and the process that created the engine must have enough access rights to read, write and delete files from this directory.

startupParameters
Optional startup parameter. The value of this parameter depends on the type of this IOcrEngine as follows:
Engine startupParameters
OcrEngineType.Advantage

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrAdvantageRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Arabic

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrArabicRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Plus

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrPlusRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

OcrEngineType.Professional

The path to the folder containing the OCR engine files.

By default, during setup the LEADTOOLS OCR Module setup installs the OCR engine files to "Installation Path\Bin\Common\OcrProfessionalRuntime" where Installation Path is the root folder where the LEADTOOLS for .NET Class Library is installed (for example, C:\LEADTOOLS 18).

If you pass null (Nothing in Visual Basic) to startupParameters, then the LEADTOOLS OCR engine will look for these extra files in the default installation folder specified above.

When you are ready to package your application, you might want to change the location where the LEADTOOLS OCR engine looks for these extra files. You can use this property to do that. Set the path you want before calling the Startup method.

Remarks

The Startup method must be called before invoking any other methods or properties in this IOcrEngine.

To check if the engine is started, use the IsStarted property.

You must call Shutdown to shut down the engine and free the memory and resources used.

You can call the Startup method multiple times, only the first call will start the engine while subsequent calls will only increment an internal counter. You must call Shutdown for each Startup called.

The IOcrEngine interface implements System.IDisposable. It is highly recommended that you call System.IDisposable.Dispose (or use the using statement in C# or Using statement in Visual Basic) when creating the IOcrEngine instance. The System.IDisposable.Dispose method will automatically shuts down the engine if it has been started.

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

Public Sub StartupEngineExample()
   ' Use RasterCodecs to load an image file
   ' Note: You can let the engine load the image file directly as shown in the other examples
   Dim codecs As New RasterCodecs()
   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"))
   ' Assume you coped the engine runtime files to C:\MyApp\Ocr
   Dim engineDir As String = "C:\MyApp\Ocr"

   ' Store the engine work directory into a path inside our application
   Dim workDir As String = "C:\MyApp\OcrTemp"

   ' Delete all files in the work directory in case the previous version of our application exited abnormally and
   ' the engine did not get the chance to clean all of its temporary files (if any)
   Directory.Delete(workDir, True)

   ' Re-create the work directory
   Directory.CreateDirectory(workDir)

   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
      ' Show that the engine has not been started yet
      Console.WriteLine("Before calling Startup, IsStarted = " + ocrEngine.IsStarted.ToString())

      ' Start the engine using our parameters
      ' Since we already have a RasterCodecs object, we can re-use it to save memory and resources
      ocrEngine.Startup(codecs, Nothing, workDir, engineDir)

      ' Make sure the engine is using our working directory
      Console.WriteLine("workDir passed is {0}, the value of WorkDirectory after Startup is {1}", workDir, ocrEngine.WorkDirectory)

      ' Show that the engine has started fine
      Console.WriteLine("After calling Startup, EngineType is {0}, IsStarted = {1}", ocrEngine.EngineType, ocrEngine.IsStarted)

      ' Maks sure the engine is using our own version of RasterCodecs
      Debug.Assert(codecs Is ocrEngine.RasterCodecsInstance)

      ' Create an OCR document
      Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
         ' Add the raster image as page to the document
         Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(image, 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
         Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

public void StartupEngineExample()
{
   // Use RasterCodecs to load an image file
   // Note: You can let the engine load the image file directly as shown in the other examples
   RasterCodecs codecs = new RasterCodecs();
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"));
   // Assume you coped the engine runtime files to C:\MyApp\Ocr
   string engineDir = @"C:\MyApp\Ocr";

   // Store the engine work directory into a path inside our application
   string workDir = @"C:\MyApp\OcrTemp";

   // Delete all files in the work directory in case the previous version of our application exited abnormally and
   // the engine did not get the chance to clean all of its temporary files (if any)
   Directory.Delete(workDir, true);

   // Re-create the work directory
   Directory.CreateDirectory(workDir);

   // Create an instance of the engine
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
   {
      // Show that the engine has not been started yet
      Console.WriteLine("Before calling Startup, IsStarted = " + ocrEngine.IsStarted);

      // Start the engine using our parameters
      // Since we already have a RasterCodecs object, we can re-use it to save memory and resources
      ocrEngine.Startup(codecs, null, workDir, engineDir);

      // Make sure the engine is using our working directory
      Console.WriteLine("workDir passed is {0}, the value of WorkDirectory after Startup is {1}", workDir, ocrEngine.WorkDirectory);

      // Show that the engine has started fine
      Console.WriteLine("After calling Startup, EngineType is {0}, IsStarted = {1}", ocrEngine.EngineType, ocrEngine.IsStarted);

      // Maks sure the engine is using our own version of RasterCodecs
      Debug.Assert(codecs == ocrEngine.RasterCodecsInstance);

      // Create an OCR document
      using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
      {
         // Add the raster image as page to the document
         IOcrPage 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
         string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.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();
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;

[TestMethod]
public async Task StartupEngineExample()
{
   // Use RasterCodecs to load an image file
   // Note: You can let the engine load the image file directly as shown in the other examples
   RasterCodecs codecs = new RasterCodecs();
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(@"Assets\Ocr1.tif");
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   // Assume you coped the engine runtime files to a folder named "OcrRuntime" inside your project

   // Store the engine work directory into a path inside our application
   string tempFolderName = "OcrTemp";
   string workDir = Path.Combine(Tools.AppLocalFolder.Path, tempFolderName);

   // Create the work directory
   await Tools.AppLocalFolder.CreateFolderAsync(tempFolderName);

   // Create an instance of the engine
   IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);

   // Show that the engine has not been started yet
   Debug.WriteLine("Before calling Startup, IsStarted = " + ocrEngine.IsStarted);

   // Start the engine using our parameters
   // Since we already have a RasterCodecs object, we can re-use it to save memory and resources
   ocrEngine.Startup(codecs, null, workDir, Tools.OcrEnginePath);

   // Make sure the engine is using our working directory
   Debug.WriteLine("workDir passed is {0}, the value of WorkDirectory after Startup is {1}", workDir, ocrEngine.WorkDirectory);

   // Show that the engine has started fine
   Debug.WriteLine("After calling Startup, EngineType is {0}, IsStarted = {1}", ocrEngine.EngineType, ocrEngine.IsStarted);

   // Maks sure the engine is using our own version of RasterCodecs
   Debug.Assert(codecs == ocrEngine.RasterCodecsInstance);

   // Create an OCR document
   IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

   // Add the raster image as page to the document
   IOcrPage 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
   string pdfFileName = "Ocr1.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

IOcrEngine Interface
IOcrEngine Members
WorkDirectory Property
IsStarted Property
Shutdown Method
OcrEngineManager Class
OcrEngineType Enumeration
Leadtools.Forms.DocumentWriters.DocumentWriter
Programming with the LEADTOOLS .NET OCR
Creating an OCR Engine Instance
Starting and Shutting Down the OCR Engine

 

 


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

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