Provides support for the one shot "fire and forget" approach to OCR.
Syntax
Visual Basic (Declaration) | |
---|
Public Interface IOcrAutoRecognizeManager |
C# | |
---|
public interface IOcrAutoRecognizeManager |
C++/CLI | |
---|
public interface class IOcrAutoRecognizeManager |
Example
This example will convert TIF files in a source folder to PDF in a destination folder
Visual Basic | Copy Code |
---|
Public Sub AutoRecognizeExample()
RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here")
RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here")
Console.WriteLine("Preparing the source and destination directories...")
Dim sourceDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path
Dim destinationDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path + "Destination"
If (Directory.Exists(sourceDirectory)) Then
Directory.Delete(sourceDirectory, True)
End If
Directory.CreateDirectory(sourceDirectory)
If (Directory.Exists(destinationDirectory)) Then
Directory.Delete(destinationDirectory, True)
End If
Directory.CreateDirectory(destinationDirectory)
Dim imagesDirectory As String = LeadtoolsExamples.Common.ImagesPath.Path
For i As Integer = 0 To 3
Dim fileName As String = String.Format("Ocr{0}.tif", i + 1)
Dim sourceFileName As String = Path.Combine(imagesDirectory, fileName)
Dim destinationFileName As String = Path.Combine(sourceDirectory, fileName)
File.Copy(sourceFileName, destinationFileName, True)
Next
Console.WriteLine("Creating an instance of the engine...")
Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
Console.WriteLine("Starting up the engine...")
ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
Dim ocrAutoRecognizeManager As IOcrAutoRecognizeManager = ocrEngine.AutoRecognizeManager
Dim tifFileNames() As String = Directory.GetFiles(sourceDirectory, "*.tif")
For Each tifFileName As String In tifFileNames
Dim documentFileName As String = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(tifFileName))
documentFileName = Path.ChangeExtension(documentFileName, "pdf")
Console.WriteLine("Processing {0}", tifFileName)
ocrAutoRecognizeManager.Run(tifFileName, documentFileName, Nothing, DocumentFormat.Pdf, Nothing)
Console.WriteLine("Saved: {0}", documentFileName)
Next
Console.WriteLine("Shutting down...")
ocrEngine.Shutdown()
End Using
End Sub |
C# | Copy Code |
---|
public void AutoRecognizeExample() { // Unlock the support needed for LEADTOOLS Plus OCR engine RasterSupport.Unlock(RasterSupportType.Document, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlus, "Replace with your own key here"); RasterSupport.Unlock(RasterSupportType.OcrPlusPdfLeadOutput, "Replace with your own key here"); Console.WriteLine("Preparing the source and destination directories..."); string sourceDirectory = LeadtoolsExamples.Common.ImagesPath.Path; string destinationDirectory = LeadtoolsExamples.Common.ImagesPath.Path + "Destination"; // Prepare the directories if(Directory.Exists(sourceDirectory)) Directory.Delete(sourceDirectory, true); Directory.CreateDirectory(sourceDirectory); if(Directory.Exists(destinationDirectory)) Directory.Delete(destinationDirectory, true); Directory.CreateDirectory(destinationDirectory); // Copy some files to the source directory string imagesDirectory = LeadtoolsExamples.Common.ImagesPath.Path; for(int i = 0; i < 4; i++) { string fileName = string.Format("Ocr{0}.tif", i + 1); string sourceFileName = Path.Combine(imagesDirectory, fileName); string destinationFileName = Path.Combine(sourceDirectory, fileName); File.Copy(sourceFileName, destinationFileName, true); } Console.WriteLine("Creating an instance of the engine..."); // Create an instance of the engine using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false)) { // Start the engine using default parameters Console.WriteLine("Starting up the engine..."); ocrEngine.Startup(null, null, null, null); IOcrAutoRecognizeManager ocrAutoRecognizeManager = ocrEngine.AutoRecognizeManager; // Loop through all the TIF files in the source directory, convert to PDF in the destination directory string[] tifFileNames = Directory.GetFiles(sourceDirectory, "*.tif"); foreach(string tifFileName in tifFileNames) { // Construct the name of the document file string documentFileName = Path.Combine(destinationDirectory, Path.GetFileNameWithoutExtension(tifFileName)); documentFileName = Path.ChangeExtension(documentFileName, "pdf"); // OCR the file Console.WriteLine("Processing {0}", tifFileName); ocrAutoRecognizeManager.Run(tifFileName, documentFileName, null, DocumentFormat.Pdf, null); Console.WriteLine("Saved: {0}", documentFileName); } // Note: calling Dispose will also automatically shutdown the engine if it has been started Console.WriteLine("Shutting down..."); ocrEngine.Shutdown(); } } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also