VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
Vintasoft.Imaging.ImageProcessing.Ocr.Tesseract Namespace / AutoTesseractOcrTextOrientationCommand Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
AutoTesseractOcrTextOrientationCommand Class
In This Topic
Automatically detects text orientation in a document image using Tesseract OCR and rotates the image if necessary.
Object Model
ProcessingCommandResults AutoTesseractOcrTextOrientationCommand
Syntax
'Declaration

Public Class AutoTesseractOcrTextOrientationCommand
   Inherits Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase

public class AutoTesseractOcrTextOrientationCommand : Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase

Example

This C#/VB.NET code shows how to detect orientation of document image using Tesseract OCR and save image with correct page orientation to a new image file.


''' <summary>
''' Determines orientation of document image using Tesseract OCR and saves image with correct page orientation to a new image file.
''' </summary>
''' <param name="filename">The path to a file with document image.</param>
''' <param name="tesseractOcrDllDirectory">A path to a directory, where Tesseract5.Vintasoft.xXX.dll files are located.</param>
Public Shared Sub DetermineDocumentImageOrientationUsingTesseractOCR(filename As String, tesseractOcrDllDirectory As String)
    ' create an image collection
    Using images As New Vintasoft.Imaging.ImageCollection()
        ' add images from file to the image collection
        images.Add(filename)

        ' create an instance of AutoTesseractOcrTextOrientationCommand class
        Using autoTextOrientationCommand As New Vintasoft.Imaging.ImageProcessing.Ocr.Tesseract.AutoTesseractOcrTextOrientationCommand()
            ' specify path to a directory, where Tesseract5.Vintasoft.xXX.dll files are located
            autoTextOrientationCommand.TesseractOcrDllDirectory = tesseractOcrDllDirectory

            ' for each image in image collection
            For i As Integer = 0 To images.Count - 1
                ' get image
                Dim image As Vintasoft.Imaging.VintasoftImage = images(i)

                ' determine orientation of document image using Tesseract OCR
                autoTextOrientationCommand.ExecuteInPlace(image)

                image.Save(String.Format("image_with_correct_orientation-{0}.png", i))
            Next
        End Using

        ' free images
        images.ClearAndDisposeItems()
    End Using
End Sub


/// <summary>
/// Determines orientation of document image using Tesseract OCR and saves image with correct page orientation to a new image file.
/// </summary>
/// <param name="filename">The path to a file with document image.</param>
/// <param name="tesseractOcrDllDirectory">A path to a directory, where Tesseract5.Vintasoft.xXX.dll files are located.</param>
public static void DetermineDocumentImageOrientationUsingTesseractOCR(string filename, string tesseractOcrDllDirectory)
{
    // create an image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add images from file to the image collection
        images.Add(filename);

        // create an instance of AutoTesseractOcrTextOrientationCommand class
        using (Vintasoft.Imaging.ImageProcessing.Ocr.Tesseract.AutoTesseractOcrTextOrientationCommand autoTextOrientationCommand =
            new Vintasoft.Imaging.ImageProcessing.Ocr.Tesseract.AutoTesseractOcrTextOrientationCommand())
        {
            // specify path to a directory, where Tesseract5.Vintasoft.xXX.dll files are located
            autoTextOrientationCommand.TesseractOcrDllDirectory = tesseractOcrDllDirectory;

            // for each image in image collection
            for (int i = 0; i < images.Count; i++)
            {
                // get image
                Vintasoft.Imaging.VintasoftImage image = images[i];

                // determine orientation of document image using Tesseract OCR
                autoTextOrientationCommand.ExecuteInPlace(image);

                image.Save(string.Format("image_with_correct_orientation-{0}.png", i));
            }
        }

        // free images
        images.ClearAndDisposeItems();
    }
}

Inheritance Hierarchy

System.Object
   Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase
      Vintasoft.Imaging.ImageProcessing.Ocr.Tesseract.AutoTesseractOcrTextOrientationCommand

Requirements

Target Platforms: .NET 11; .NET 10; .NET 9; .NET 8; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also