public delegate void OcrProgressCallback(IOcrProgressData data)
Public Delegate Sub OcrProgressCallback( _ByVal data As IOcrProgressData _)
typedef void (^LTOcrProgressHandler)(LTOcrProgressData *progressData) void OcrProgressListener.onProgress(OcrProgressData data) public delegate void OcrProgressCallback(IOcrProgressData^ data)
data
An instance of the IOcrProgressData interface containing the progress callback data.
The OCR engine will continuously invoke the callback procedure during the different OCR operations with an instance of IOcrProgressData providing the current processing stage and a percentage indicator value. Use this function to indicate progress of application operations.
The callback can set the IOcrProgressData.Status property at any time to OcrProgressStatus.Abort to abort the OCR process and cancel all pending operations.
This example will display a simple "Processing" Windows Forms dialog that can be used to show OCR operation progress as well as allow the user to abort the current operation. You can plug this dialog into your application and call it in response to user-interface commands that correspond to OCR operations.
using Leadtools;using Leadtools.Codecs;using Leadtools.Ocr;using Leadtools.Document.Writer;using Leadtools.Forms.Common;using Leadtools.WinForms;public void OcrProgressCallbackExample(){string logFileName = Path.Combine(LEAD_VARS.ImagesDir, "log.txt");string multiPageTifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr.tif");string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf");// Create the log text writer_log = File.CreateText(logFileName);// Create an instance of the engineusing (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)){// Start the engine using default parametersocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);// Create an OCR documentusing (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()){// Add this image to the document_log.WriteLine("Adding the pages");_log.WriteLine("********************************");ocrDocument.Pages.AddPages(multiPageTifFileName, 1, -1, new OcrProgressCallback(MyOcrProgressCallback));// Auto-recognize the zones in all the pages_log.WriteLine("Auto-zoning");_log.WriteLine("********************************");ocrDocument.Pages.AutoZone(new OcrProgressCallback(MyOcrProgressCallback));// Recognize it and save it as PDF_log.WriteLine("Recognizing");_log.WriteLine("********************************");ocrDocument.Pages.Recognize(new OcrProgressCallback(MyOcrProgressCallback));_log.WriteLine("Saving to PDF");_log.WriteLine("********************************");ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, new OcrProgressCallback(MyOcrProgressCallback));}// Shutdown the engine// Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown();}_log.WriteLine("********************************");_log.WriteLine("Complete");_log.Flush();_log.Close();}// Text writer to save the log toprivate StreamWriter _log;private void MyOcrProgressCallback(IOcrProgressData data){if (data.Percentage == 0)_log.WriteLine("--------------------------");_log.WriteLine("Page:{0}({1}:{2}) {3}% Operation:{4}",data.CurrentPageIndex.ToString("00"),data.FirstPageIndex.ToString("00"),data.LastPageIndex.ToString("00"),data.Percentage.ToString("000"),data.Operation);}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS21\Bin\Common\OcrLEADRuntime";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.OcrImports Leadtools.Document.WriterImports Leadtools.FormsImports Leadtools.WinForms' Text writer to save the log toPrivate _log As StreamWriterPublic Sub OcrProgressCallbackExample()Dim logFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "log.txt")Dim multiPageTifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr.tif")Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf")' Create the log text writer_log = File.CreateText(logFileName)' Create an instance of the engineUsing ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)' Start the engine using default parametersocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrLEADRuntimeDir)' Create an OCR documentUsing ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()' Add this image to the document_log.WriteLine("Adding the pages")_log.WriteLine("********************************")ocrDocument.Pages.AddPages(multiPageTifFileName, 1, -1, New OcrProgressCallback(AddressOf MyOcrProgressCallback))' Auto-recognize the zones in all the pages_log.WriteLine("Auto-zoning")_log.WriteLine("********************************")ocrDocument.Pages.AutoZone(New OcrProgressCallback(AddressOf MyOcrProgressCallback))' Recognize it and save it as PDF_log.WriteLine("Recognizing")_log.WriteLine("********************************")ocrDocument.Pages.Recognize(New OcrProgressCallback(AddressOf MyOcrProgressCallback))_log.WriteLine("Saving to PDF")_log.WriteLine("********************************")ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, New OcrProgressCallback(AddressOf MyOcrProgressCallback))End Using' Shutdown the engine' Note: calling Dispose will also automatically shutdown the engine if it has been startedocrEngine.Shutdown()End Using_log.WriteLine("********************************")_log.WriteLine("Complete")_log.Flush()_log.Close()End SubPrivate Sub MyOcrProgressCallback(data As IOcrProgressData)If data.Percentage = 0 Then_log.WriteLine("--------------------------")End If_log.WriteLine("Page:{0}({1}:{2}) {3}% Operation:{4}",data.CurrentPageIndex.ToString("00"),data.FirstPageIndex.ToString("00"),data.LastPageIndex.ToString("00"),data.Percentage.ToString("000"),data.Operation)End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"Public Const OcrLEADRuntimeDir As String = "C:\LEADTOOLS21\Bin\Common\OcrLEADRuntime"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
