LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)

Run(String,String,DocumentFormat,String,OcrProgressCallback) Method

Show in webframe
Example 







The name of the file containing the image.
The name of the result document file.
The output document format. If this parameter is DocumentFormat.User, then the document saved using the native engine format set in IOcrDocumentManager.EngineFormat if the engine used supports native formats, otherwise an exception will be thrown.
Optional name of prepared multi-page zone file. This parameter can be a null (Nothing in Visual Basic) reference.
Optional callback to show operation progress.
Converts an image file on disk to a document file in the specified document format with optional multi-page zone file.
Syntax
'Declaration
 
Overloads Sub Run( _
   ByVal imageFileName As String, _
   ByVal documentFileName As String, _
   ByVal format As DocumentFormat, _
   ByVal zonesFileName As String, _
   ByVal callback As OcrProgressCallback _
) 
'Usage
 
Dim instance As IOcrAutoRecognizeManager
Dim imageFileName As String
Dim documentFileName As String
Dim format As DocumentFormat
Dim zonesFileName As String
Dim callback As OcrProgressCallback
 
instance.Run(imageFileName, documentFileName, format, zonesFileName, callback)

            

            
function Leadtools.Forms.Ocr.IOcrAutoRecognizeManager.Run(String,String,DocumentFormat,String,OcrProgressCallback)( 
   imageFileName ,
   documentFileName ,
   format ,
   zonesFileName ,
   callback 
)

Parameters

imageFileName
The name of the file containing the image.
documentFileName
The name of the result document file.
format
The output document format. If this parameter is DocumentFormat.User, then the document saved using the native engine format set in IOcrDocumentManager.EngineFormat if the engine used supports native formats, otherwise an exception will be thrown.
zonesFileName
Optional name of prepared multi-page zone file. This parameter can be a null (Nothing in Visual Basic) reference.
callback
Optional callback to show operation progress.
Remarks

This method will perform the following operations:

  1. The JobStarted event is triggered.

  2. Creates one ore more IOcrDocument object to store the pages into. The number of OCR documents created is dependant on MaximumThreadsPerJob. If this value is 0 (maximum CPUs/cores) or is greater than 1 and multiple threads is supported by this engine, then more than one document might be created to participate in the recognition process.

  3. Loops through all the pages in imageFileName and for each page:

    The page is added to its document using IOcrPageCollection.AddPage.

    If zonesFileName contains a valid multi-page zone file name and has an entry for the current page, then the zones are loaded with IOcrPage.LoadZones(fileName, pageNumber) and applied to the page. If zonesFileName is a null (Nothing in Visual Basic) reference or it does not contain an equivalant page number, auto-decomposing of the page is performed instead with IOcrPage.AutoZone.

    IOcrPage.Recognize is called to get the OCR data of the page.

    If multiple documents are used or current number of recognized pages is greater than the maximum specified in MaximumPagesBeforeLtd, then current recognition data is saved to a temporary LTD file and the OCR document is cleared.

  4. When all pages are processed their saved to result file name specified in documentFileName using the format specified in format. If LTD was used, the temporary file is converted to the final document using DocumentWriter.Convert and optionally DocumentWriter.AppendLtd.

  5. All OCR documents and temporary files are deleted.

  6. The JobCompleted event is triggered.

  7. You can use the JobProgress event or callback to show the operation progress or to abort it if threading is not used. For more information and an example, refer to OcrProgressCallback.

  8. You can use the JobOperation event to get information regarding the current operation being performed. For more information and an example, refer to JobOperation.

The IOcrAutoRecognizeManager interface also has the following options to use with this method:

Option Description
MaximumPagesBeforeLtd

Add support for converting a document with unlimited number of pages. An OCR recognition operation on a document that contains a large amount of pages (10 and more) might result in an out of memory error.

All of the LEADTOOLS OCR engines supports saving the intermediate recognition results to a temporary LTD file (DocumentFormat.LTD). The result of subsequent pages will be appended to this temporary file. When all the pages of the document have been recognized, the engine will convert the temporary LTD file to the desired output format.

The MaximumPagesBeforeLtd property defines the maximum number of pages processed as a whole. For example, if the original document has 20 pages and the value of this property is 8, the engine will recognize the first 8 pages and saves the result to a temporary file, recognizes the second 8 pages and append the results, and finally, recognize the last 4 pages and convert the temporary document into the final format.

PreprocessPageCommands

Holds an array of OcrAutoPreprocessPageCommand items to control what auto-preprocess operation to perform on each page document prior to recognition.

MaximumThreadsPerJob

Maximum number of threads to use per job. You can instruct IOcrAutoRecognizeManager to use all available machine CPUs/cores when recognizing a document. This will greatly reduce the time required to finish the OCR operation.

JobErrorMode

Ability to resume on none critical errors. For example, if a source document has a page that could not be recognized. The offending page will be added to the final document as a graphics images and recognition will continue to the next page.

JobStarted, JobProgress, JobOperation and JobCompleted events

Events to track when both synchronous and asynchronous jobs has started, being run and completed.

AbortAllJobs

Aborts all running and pending jobs.

EnableTrace

Output debug messages to the standard .NET trace listeners.

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

Private Shared Sub OcrAutoRecognizeManagerRun2Example()
   Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")
   Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf")
   ' Create an instance of the engine
   Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
      ' Start the engine using default parameters
      Console.WriteLine("Starting up the engine...")
      ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)

      Dim ocrAutoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager

      ' Recognize the document
      ocrAutoRecognizeManager.Run(tifFileName, pdfFileName, DocumentFormat.Pdf, Nothing, Nothing)
   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.Codecs;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Forms;
using Leadtools.WinForms;

private static void OcrAutoRecognizeManagerRun2Example()
{
   string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");
   string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf");
   // Create an instance of the engine
   using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
   {
      // Start the engine using default parameters
      Console.WriteLine("Starting up the engine...");
      ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);

      IOcrAutoRecognizeManager ocrAutoRecognizeManager = ocrEngine.AutoRecognizeManager;

      // Recognize the document
      ocrAutoRecognizeManager.Run(tifFileName, pdfFileName, DocumentFormat.Pdf, null, null);
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 18\Bin\Common\OcrAdvantageRuntime";
}
Requirements

Target Platforms

See Also

Reference

IOcrAutoRecognizeManager Interface
IOcrAutoRecognizeManager Members
Overload List
Programming with the LEADTOOLS .NET OCR
Multi-Threading with LEADTOOLS OCR
LEADTOOLS OCR Thunk Server

 

 


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

Run(String,String,DocumentFormat,String,OcrProgressCallback) requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features