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

AutoPreprocess Method (IOcrPage)

Example 





The preprocessing command to perform.
Optional callback to show operation progress.
Performs automatic image processing clean up on the image to enhance the quality of the page before beginning recognition. .NET support WinRT support
Syntax
'Declaration
 
Sub AutoPreprocess( _
   ByVal command As OcrAutoPreprocessPageCommand, _
   ByVal callback As OcrProgressCallback _
) 
'Usage
 
Dim instance As IOcrPage
Dim command As OcrAutoPreprocessPageCommand
Dim callback As OcrProgressCallback
 
instance.AutoPreprocess(command, callback)
function Leadtools.Forms.Ocr.IOcrPage.AutoPreprocess( 
   command ,
   callback 
)

Parameters

command
The preprocessing command to perform.
callback
Optional callback to show operation progress.
Remarks

Use this method to deskew, rotate or invert the image according to command. By performing auto pre-processing on a page, you can improve the image quality of draft mode faxes.

Use the OcrProgressCallback to show the operation progress or to abort it. For more information and an example, refer to OcrProgressCallback.

Call this method prior to calling Recognize or RecognizeText.

This method will call GetDeskewAngle, GetRotateAngle and IsInverted to determine whether the page needs processing, if the page does, this method will internally deskews, rotates or inverts the image accordingly.

If the image is skewed, GetDeskewAngle will return the angle needed to deskew the image, if you call AutoPreprocess on the page, all subsequent calls to GetDeskewAngle will return 0 since the image is no longer skewed. Same with GetRotateAngle and IsInverted.

This method works on both the current and processing version of the image. For example, if you add a page that is skewed and call AutoPreprocess width OcrAutoPreprocessPageCommand.Deskew, then obtain either the current or processing images with GetRasterImage(OcrPageType), you will get two raster image objects that are both rotated (deskewed).

Example
Copy CodeCopy Code  
Public Sub AutoPreprocessExample()
      Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif")
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf")
      ' 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)

         ' Create an OCR document
         Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument()
            ' Add this image to the document
            Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing)

            ' Auto-preprocess it
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, Nothing)
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, Nothing)
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, Nothing)

            ' Recognize it and save it as PDF
            ocrPage.Recognize(Nothing)
            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
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void AutoPreprocessExample()
   {
      string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif");
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf");
      // 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);

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

            // Auto-preprocess it
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, null);
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, null);
            ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, null);

            // Recognize it and save it as PDF
            ocrPage.Recognize(null);
            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();
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
[TestMethod]
public async Task AutoPreprocessExample()
{
   string tifFileName = @"Assets\Clean.tif";
   string pdfFileName = "Clean.pdf";
   // 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);

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

   // Add this image 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);
   }

   // Auto-preprocess it
   ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, null);
   ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, null);
   ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, null);

   // Recognize it and save it as PDF
   ocrPage.Recognize(null);
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting);
   await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null);

   // 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

IOcrPage Interface
IOcrPage Members
Recognize Method
OcrAutoPreprocessPageCommand Enumeration
GetDeskewAngle Method
GetRotateAngle Method
IsInverted Method
IOcrPageCollection Interface
IOcrZoneCollection Interface
OcrZone Structure
Programming with the LEADTOOLS .NET OCR

 

 


Products | Support | Contact Us | Copyright Notices

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

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