LEADTOOLS OCR (Leadtools.Forms.Ocr assembly)
LEAD Technologies, Inc

OcrStatistic Structure

Example 





Members 
Represents processing statistic data. .NET support
Object Model
OcrStatistic Structure
Syntax
[SerializableAttribute()]
public struct OcrStatistic : System.ValueType 
'Declaration
 
<SerializableAttribute()>
Public Structure OcrStatistic 
   Inherits System.ValueType
'Usage
 
Dim instance As OcrStatistic
[SerializableAttribute()]
public class OcrStatistic
JAVASCRIPT_NOSTRUCTS
[SerializableAttribute()]
public value class OcrStatistic : public System.ValueType 
Remarks

This structure contains the accuracy and timing data of the latest successful recognition process.

To obtain the statistic, use GetLastStatistic.

Note that the time spent for the text post-processing can be calculated as follows: PostProcessingTime = statistic.ReadingTime - statistic.RecognitionTime.

Note: Only the following members are available for the LEADTOOLS OCR Advantage Engine

Example
Copy CodeCopy Code  
Public Sub OcrStatisticExample()
      ' Create an instance of the engine
      Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, False)
         ' Start the engine using default parameters
         ocrEngine.Startup(Nothing, Nothing, Nothing, Nothing)
         Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")
         Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.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(tifFileName, Nothing)

            ' Process the page
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, 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)

            ' Show the statistic about the last recognize operation
            Dim statistic As OcrStatistic = ocrEngine.GetLastStatistic()
            Console.WriteLine("Recognized characters: {0}", statistic.RecognizedCharacters)
            Console.WriteLine("Recognized words: {0}", statistic.RecognizedWords)
            Console.WriteLine("Rejected characters: {0}", statistic.RejectedCharacters)
            Console.WriteLine("Corrected words: {0}", statistic.CorrectedWords)
            Console.WriteLine("Recognition time: {0} ms", statistic.RecognitionTime)
            Console.WriteLine("Reading time: {0} ms", statistic.ReadingTime)
            Console.WriteLine("Image Preprocessing time: {0} ms", statistic.ImagePreprocessingTime)
            Console.WriteLine("Decomposition time: {0} ms", statistic.DecompositionTime)
            Console.WriteLine("Post processing time: {0} ms", statistic.ReadingTime - statistic.RecognitionTime)
         End Using

         ' Shutdown the engine
         ' Note: calling Dispose will also automatically shutdown the engine if it has been started
         ocrEngine.Shutdown()
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void OcrStatisticExample()
   {
      // Create an instance of the engine
      using(IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false))
      {
         // Start the engine using default parameters
         ocrEngine.Startup(null, null, null, null);
         string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");
         string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.pdf");

         // Create an OCR document
         using(IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument())
         {
            // Add a page to the document
            IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null);

            // Process the page
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, 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);

            // Show the statistic about the last recognize operation
            OcrStatistic statistic = ocrEngine.GetLastStatistic();
            Console.WriteLine("Recognized characters: {0}", statistic.RecognizedCharacters);
            Console.WriteLine("Recognized words: {0}", statistic.RecognizedWords);
            Console.WriteLine("Rejected characters: {0}", statistic.RejectedCharacters);
            Console.WriteLine("Corrected words: {0}", statistic.CorrectedWords);
            Console.WriteLine("Recognition time: {0} ms", statistic.RecognitionTime);
            Console.WriteLine("Reading time: {0} ms", statistic.ReadingTime);
            Console.WriteLine("Image Preprocessing time: {0} ms", statistic.ImagePreprocessingTime);
            Console.WriteLine("Decomposition time: {0} ms", statistic.DecompositionTime);
            Console.WriteLine("Post processing time: {0} ms", statistic.ReadingTime - statistic.RecognitionTime);
         }

         // Shutdown the engine
         // Note: calling Dispose will also automatically shutdown the engine if it has been started
         ocrEngine.Shutdown();
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task OcrStatisticExample()
{
   // Create an instance of the engine
   IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
   // Start the engine using default parameters
   ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath);

   string tifFileName = @"Assets\Ocr1.tif";
   string pdfFileName = "Ocr1.pdf";

   // Create an OCR document
   IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument();

   // Add a page to the document
   IOcrPage ocrPage = null;
   using (RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName);
      using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
      {
         ocrPage = ocrDocument.Pages.AddPage(image, null);
      }
   }

   // Process the page
   ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, 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
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // Show the statistic about the last recognize operation
   OcrStatistic statistic = ocrEngine.GetLastStatistic();
   Debug.WriteLine("Recognized characters: {0}", statistic.RecognizedCharacters);
   Debug.WriteLine("Recognized words: {0}", statistic.RecognizedWords);
   Debug.WriteLine("Rejected characters: {0}", statistic.RejectedCharacters);
   Debug.WriteLine("Corrected words: {0}", statistic.CorrectedWords);
   Debug.WriteLine("Recognition time: {0} ms", statistic.RecognitionTime);
   Debug.WriteLine("Reading time: {0} ms", statistic.ReadingTime);
   Debug.WriteLine("Image Preprocessing time: {0} ms", statistic.ImagePreprocessingTime);
   Debug.WriteLine("Decomposition time: {0} ms", statistic.DecompositionTime);
   Debug.WriteLine("Post processing time: {0} ms", statistic.ReadingTime - statistic.RecognitionTime);

   // Shutdown the engine
   ocrEngine.Shutdown();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

OcrStatistic Members
Leadtools.Forms.Ocr Namespace
IOcrEngine.GetLastStatistic
IOcrEngine.Startup
IOcrEngine.IsStarted
IOcrEngine.Shutdown
IOcrPage Interface
IOcrPage.AutoPreprocess
AutoZone Method
IOcrPage.Recognize
IOcrDocument.Save
IOcrDocument.SaveXml
OcrEngineManager Class
OcrEngineType Enumeration
Programming with Leadtools .NET OCR

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

OcrStatistic requires an OCR module license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features