[SerializableAttribute()]
public enum OcrProgressOperation
Value | Member | Description |
---|---|---|
0 | LoadImage | Image load operation. Used when pages are added to an OCR document through one of IOcrPageCollection.AddPage, IOcrPageCollection.AddPages, IOcrPageCollection.InsertPage or IOcrPageCollection.InsertPages methods. |
1 | SaveImage | Image save operation. Used when IOcrPage.Recognize is called. |
2 | ProcessImage | Image preprocessing operation. Used when IOcrPage.AutoPreprocess is called. |
3 | FindZones | Page-layout decomposition operation. Used when IOcrPage.AutoZone is called. |
4 | RecognizeFirstPass | First pass recognition operation that may be used when IOcrPage.Recognize is used with the MOR recognition module |
5 | RecognizeSecondPass | Second pass recognition operation. Used when IOcrPage.Recognize is called. |
6 | RecognizeThirdPass | Third pass recognition operation. Used when IOcrPage.Recognize is called. |
7 | SaveDocumentPrepare | Prepare the document operation. Used when IOcrDocument.Save is called. |
8 | SaveDocument | Save document operation. Used when IOcrDocument.Save is called. |
9 | SaveDocumentConvertImage | Convert the document images operation. Used when IOcrDocument.Save is called. |
10 | Formatting | Format the document before saving. Used when IOcrDocument.Save is called. |
11 | RecognizeOmr | Recognizing OMR zones operation. Used when IOcrPage.Recognize is called on a page with zones containing OcrZoneType.Omr. |
OcrProgressOperation is the value of IOcrProgressData.Operation. Use this value to examine the current operation of the process.
Each operation listed represents one of the fundamental services provided by the OCR engine. Any application program will use at least some of these processes.
Each operation can be initiated by the methods shown. OcrProgressCallback can be used to generate progress monitoring on any of these 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 engine
using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD))
{
// Start the engine using default parameters
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrLEADRuntimeDir);
// Create an OCR document
using (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 started
ocrEngine.Shutdown();
}
_log.WriteLine("********************************");
_log.WriteLine("Complete");
_log.Flush();
_log.Close();
}
// Text writer to save the log to
private 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:\LEADTOOLS23\Resources\Images";
public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime";
}