Provides methods to create OCR engine instances.
public static class OcrEngineManager
Public MustInherit NotInheritable Class OcrEngineManager
public sealed static class OcrEngineManager
@interface LTOcrEngineManager : NSObject // STATIC CLASS
public class OcrEngineManager
function Leadtools.Forms.Ocr.OcrEngineManager()
public ref class OcrEngineManager abstract sealed
The OcrEngineManager class and its methods are your entry point to using the Leadtools.Forms.Ocr class library.
This class provides the methods you need to create an object of the IOcrEngine interface. 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.
All LEADTOOLS OCR engines (Advantage, Professional, and Arabic) are now thread-safe and so the "THUNK" mechanism is no longer required. Consequently, the useThunkServer parameter of the CreateEngine method will be ignored at all times for all engines.
This example shows how to OCR documents using multiple threads.
using Leadtools;
using Leadtools.Forms.Ocr;
using Leadtools.Forms.DocumentWriters;
public void MultiThreadedOcrExample()
{
// The image file names we are going to OCR and convert to PDF
string[] tifFileNames =
{
Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.tif")
};
int threadCount = tifFileNames.Length;
// Create the thread
Thread[] threads = new Thread[threadCount];
AutoResetEvent[] waitHandles = new AutoResetEvent[threadCount];
for (int i = 0; i < threadCount; i++)
{
threads[i] = new Thread(new ParameterizedThreadStart(MyThreadProc));
threads[i].Name = "OCR thread + " + i.ToString();
waitHandles[i] = new AutoResetEvent(false);
}
Console.WriteLine("Starting the threads and waiting...");
// Start the threads
for (int i = 0; i < threadCount; i++)
{
MyThreadData threadData = new MyThreadData();
threadData.ImageFileName = tifFileNames[i];
threadData.WaitHandle = waitHandles[i];
threads[i].Start(threadData);
}
// Wait till all threads are done
WaitHandle.WaitAny(waitHandles);
Console.WriteLine("All threads finished");
}
private struct MyThreadData
{
public string ImageFileName;
public AutoResetEvent WaitHandle;
}
private void MyThreadProc(object data)
{
// Grab the data
MyThreadData threadData = (MyThreadData)data;
string imageFileName = threadData.ImageFileName;
// Show a status message
Console.WriteLine("Begin: {0}", imageFileName);
// Create an instance of the OCR engine using. If you change the engine type from Advantage,
// then the last parameter indicates the use of the LEADTOOLS Thunk Server
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, true))
{
// Start the engine using default parameters
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);
// Get the PDf file name
string pdfFileName = Path.ChangeExtension(imageFileName, "pdf");
// Create an OCR document
using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
{
// Add a page to the document
IOcrPage ocrPage = ocrDocument.Pages.AddPage(imageFileName, 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();
}
Console.WriteLine("End: {0}", imageFileName);
// Singal the main thread
threadData.WaitHandle.Set();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime";
}
Imports Leadtools
Imports Leadtools.Forms.Ocr
Imports Leadtools.Forms.DocumentWriters
Private Structure MyThreadData
Public ImageFileName As String
Public WaitHandle As AutoResetEvent
End Structure
<TestMethod>
Public Sub MultiThreadedOcrExample()
' The image file names we are going to OCR and convert to PDF
Dim tifFileNames As String() = {
Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr2.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr3.tif"),
Path.Combine(LEAD_VARS.ImagesDir, "Ocr4.tif")}
Dim threadCount As Integer = tifFileNames.Length
' Create the thread
Dim threads As Thread() = New Thread(threadCount - 1) {}
Dim waitHandles As AutoResetEvent() = New AutoResetEvent(threadCount - 1) {}
For i As Integer = 0 To threadCount - 1
threads(i) = New Thread(New ParameterizedThreadStart(AddressOf MyThreadProc))
threads(i).Name = "OCR thread + " & i.ToString()
waitHandles(i) = New AutoResetEvent(False)
Next
Console.WriteLine("Starting the threads and waiting...")
' Start the threads
For i As Integer = 0 To threadCount - 1
Dim threadData As New MyThreadData()
threadData.ImageFileName = tifFileNames(i)
threadData.WaitHandle = waitHandles(i)
threads(i).Start(threadData)
Next
' Wait till all threads are done
WaitHandle.WaitAll(waitHandles)
Console.WriteLine("All threads finished")
End Sub
Private Sub MyThreadProc(data As Object)
' Grab the data
Dim threadData As MyThreadData = CType(data, MyThreadData)
Dim imageFileName As String = threadData.ImageFileName
' Show a status message
Console.WriteLine("Begin: {0}", imageFileName)
' Create an instance of the OCR engine using. If you change the engine type from Advantage,
' then the last parameter indicates the use of the LEADTOOLS Thunk Server
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, True)
' Start the engine using default parameters
ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)
' Get the PDf file name
Dim pdfFileName As String = Path.ChangeExtension(imageFileName, "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(imageFileName, 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
Console.WriteLine("End: {0}", imageFileName)
' Singal the main thread
threadData.WaitHandle.Set()
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
Programming with the LEADTOOLS .NET OCR
Creating an OCR Engine Instance
Starting and Shutting Down the OCR Engine
Products |
Support |
Feedback: OcrEngineManager Class - Leadtools.Forms.Ocr |
Introduction |
Help Version 19.0.2017.6.6
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.