GdPicture.NET.14
GdPicture14 Namespace / GdPictureOCR Class / GetOrientation Method
Example





In This Topic
GetOrientation Method (GdPictureOCR)
In This Topic
Computes the page orientation of the image previously set by the SetImage method. In order to correct the resulting orientation, you need to rotate the image by the following angle: 360 - returned value.
Syntax
'Declaration
 
Public Function GetOrientation() As Integer
public int GetOrientation()
public function GetOrientation(): Integer; 
public function GetOrientation() : int;
public: int GetOrientation(); 
public:
int GetOrientation(); 

Return Value

The page orientation, in degrees, determining the clockwise rotation applied to the given image. The returned value can only be 0, 90, 180 or 270.

Please always use the GetStat method to determine if this method has been successful.

Remarks
It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Please note that you need to set up the required image before running this method together with setting up the dictionary and the language as well.

Just to remind you, that you need to rotate the image by the angle 360 - returned value to correct the possible page orientation before running the OCR.

Example
How to correct the page orientation for the given image before processing the OCR.
Dim caption As String = "Example: GetOrientation"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR
    'Setting these properties is mandatory for using this method.
    'Specify your path.
    gdpictureOCR.ResourcesFolder = "D:\\GdPicture.NET 14\\Redist\\OCR"
    'Specify your language.
    gdpictureOCR.AddLanguage(OCRLanguage.English)
    'Load the image you want to process.
    Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging
    'The standard open file dialog displays to allow you to select the file.
    Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
    If gdpictureImaging.GetStat = GdPictureStatus.OK AndAlso
       gdpictureOCR.SetImage(image) = GdPictureStatus.OK Then
        'Setting up the image is mandatory.
        'Check the image orientation.
        Dim orientation As Integer = gdpictureOCR.GetOrientation()
        If gdpictureOCR.GetStat = GdPictureStatus.OK Then
            If orientation <> 0 Then
                If gdpictureImaging.RotateAngle(image, 360 - orientation) <> GdPictureStatus.OK Then
                    MessageBox.Show("The image is rotated, but the RotateAngle() method has failed with the status: " + gdpictureImaging.GetStat.ToString, caption)
                Else
                    orientation = 0
                End If
            End If
            'Continue if image is properly oriented.
            If orientation = 0 Then
                'Set up the required OCR parameters and continue with the process.
            End If
        Else
            MessageBox.Show("The GetOrientation() method has failed with the status: " + gdpictureOCR.GetStat.ToString, caption)
        End If
        'Release the used image.
        gdpictureImaging.ReleaseGdPictureImage(image)
    Else
        MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption)
    End If
    gdpictureImaging.Dispose()
End Using
string caption = "Example: GetOrientation";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
    //Setting these properties is mandatory to be able to using this method.
    gdpictureOCR.ResourcesFolder = "D:\\GdPicture.NET 14\\Redist\\OCR"; //Specify your path.
    gdpictureOCR.AddLanguage(OCRLanguage.English); //Specify your language.
    //Load the image you want to process.
    GdPictureImaging gdpictureImaging = new GdPictureImaging();
    //The standard open file dialog displays to allow you to select the file.
    int image = gdpictureImaging.CreateGdPictureImageFromFile("");
    if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
        (gdpictureOCR.SetImage(image) == GdPictureStatus.OK)) //Setting up the image is mandatory.
    {
        //Check the image orientation.
        int orientation = gdpictureOCR.GetOrientation();
        if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
        {
            if (orientation != 0)
            {
                if (gdpictureImaging.RotateAngle(image, 360 - orientation) != GdPictureStatus.OK)
                    MessageBox.Show("The image is rotated, but the RotateAngle() method has failed with the status: " + gdpictureImaging.GetStat().ToString(), caption);
                else
                    orientation = 0;
            }
            //Continue if image is properly oriented.
            if (orientation == 0)
            {
                //Set up the required OCR parameters and continue with the process.
            }
        }
        else
            MessageBox.Show("The GetOrientation() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
        //Release the used image.
        gdpictureImaging.ReleaseGdPictureImage(image);
    }
    else
    {
        MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption);
    }
    gdpictureImaging.Dispose();
}
See Also