Reference Guide
GdPicture14 Namespace / GdPictureOCR Class / GetWordTop Method
The unique result identifier of the executed OCR process obtained by the RunOCR method.
The 0-based index of the word within the specified OCR result. It must be a value between 0 and GetWordCount(OCRResultID)-1.
Example





In This Topic
    GetWordTop Method (GdPictureOCR)
    In This Topic
    Returns the top y-coordinate of the bounding box of the specified word, that is a part of the OCR result specified by its index.

    This method uses a coordinate system, where the origin is in the top-left corner of the processed image and the units are pixels.

    Syntax
    'Declaration
     
    
    Public Function GetWordTop( _
       ByVal OCRResultID As String, _
       ByVal WordIdx As Integer _
    ) As Integer
    public int GetWordTop( 
       string OCRResultID,
       int WordIdx
    )
    public function GetWordTop( 
        OCRResultID: String;
        WordIdx: Integer
    ): Integer; 
    public function GetWordTop( 
       OCRResultID : String,
       WordIdx : int
    ) : int;
    public: int GetWordTop( 
       string* OCRResultID,
       int WordIdx
    ) 
    public:
    int GetWordTop( 
       String^ OCRResultID,
       int WordIdx
    ) 

    Parameters

    OCRResultID
    The unique result identifier of the executed OCR process obtained by the RunOCR method.
    WordIdx
    The 0-based index of the word within the specified OCR result. It must be a value between 0 and GetWordCount(OCRResultID)-1.

    Return Value

    The top y-coordinate of the word's bounding box, in pixels.

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

    Remarks
    We strongly recommend using the GetStat method to identify the specific reason for the method's failure.

    Please note, that the origin of the used coordinate system is in the top-left corner of the processed image and the used units are pixels.

    Example
    How to get the position of recognized words within the OCR result.
    Dim caption As String = "Example: GetWordTop"
    Dim oGdPictureOCR As GdPictureOCR = New GdPictureOCR
    Dim oGdPicturePDF As GdPicturePDF = New GdPicturePDF
    'Load the PDF document.
    If oGdPicturePDF.LoadFromFile("input.pdf", False) = GdPictureStatus.OK Then
        'Select the first page.
        oGdPicturePDF.SelectPage(1)
        'Render this page to a 200 DPI image.
        Dim image As Integer = oGdPicturePDF.RenderPageToGdPictureImage(200, True)
        If oGdPicturePDF.GetStat = GdPictureStatus.OK AndAlso
           oGdPictureOCR.SetImage(image) = GdPictureStatus.OK Then
            'Setting up the image is mandatory.
            'Set up the OCR parameters.
            oGdPictureOCR.ResourceFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"
            oGdPictureOCR.AddLanguage(OCRLanguage.English)
            oGdPictureOCR.OCRMode = OCRMode.FavorAccuracy
            'Set up the OCR context and the character list.
            oGdPictureOCR.Context = OCRContext.OCRContextSingleLine
            oGdPictureOCR.CharacterSet = "0123456789"
            'Set up the area to be processed by the OCR.
            oGdPictureOCR.SetROI(100, 100, 200, 50)
            'Run the OCR process to recognize the phone number.
            Dim resID As String = oGdPictureOCR.RunOCR()
            If oGdPictureOCR.GetStat = GdPictureStatus.OK Then
                Dim wordCount As Integer = oGdPictureOCR.GetWordCount(resID)
                If oGdPictureOCR.GetStat = GdPictureStatus.OK Then
                    Dim left As Integer = oGdPictureOCR.GetWordLeft(resID, 0)
                    Dim top As Integer = oGdPictureOCR.GetWordTop(resID, 0)
                    If oGdPicturePDF.DrawRectangle(left, top,
                                                   oGdPictureOCR.GetWordRight(resID, wordCount - 1) - left,
                                                   oGdPictureOCR.GetWordBottom(resID, wordCount - 1) - top,
                                                   False, True) = GdPictureStatus.OK Then
                        MessageBox.Show("The recognized phone number area has been successfully drawn.", caption)
                    End If
                    'Save the page with drawn recognized phone number to the New PDF document.
                    If oGdPicturePDF.SaveToFile("output.pdf") = GdPictureStatus.OK Then
                        MessageBox.Show("Done!", caption)
                    Else
                        MessageBox.Show("The file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("The GetWordCount() method has failed with the status: " + oGdPictureOCR.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The error occurred when running the OCR. Status: " + oGdPictureOCR.GetStat().ToString(), caption)
            End If
            'Release the image.
            GdPictureDocumentUtilities.DisposeImage(image)
        Else
            MessageBox.Show("The error occurred when creating or setting up the image. Status: " + oGdPicturePDF.GetStat().ToString() + "/" + oGdPictureOCR.GetStat().ToString(), caption)
        End If
        'Close the document.
        oGdPicturePDF.CloseDocument()
    Else
        MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
    End If
    'Release resources.
    oGdPictureOCR.ReleaseOCRResults()
    oGdPictureOCR.Dispose()
    oGdPicturePDF.Dispose()
    string caption = "Example: GetWordTop";
    GdPictureOCR oGdPictureOCR = new GdPictureOCR();
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    //Load the PDF document.
    if (oGdPicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)
    {
        //Select the first page.
        oGdPicturePDF.SelectPage(1);
        //Render this page to a 200 DPI image.
        int image = oGdPicturePDF.RenderPageToGdPictureImage(200, true);
        if ((oGdPicturePDF.GetStat() == GdPictureStatus.OK) &&
            (oGdPictureOCR.SetImage(image) == GdPictureStatus.OK)) //Setting up the image is mandatory.
        {
            //Set up the OCR parameters.
            oGdPictureOCR.ResourceFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";
            oGdPictureOCR.AddLanguage(OCRLanguage.English);
            oGdPictureOCR.OCRMode = OCRMode.FavorAccuracy;
            //Set up the OCR context and the character list.
            oGdPictureOCR.Context = OCRContext.OCRContextSingleLine;
            oGdPictureOCR.CharacterSet = "0123456789";
            //Set up the area to be processed by the OCR.
            oGdPictureOCR.SetROI(100, 100, 200, 50);
            //Run the OCR process to recognize the phone number.
            string resID = oGdPictureOCR.RunOCR();
            if (oGdPictureOCR.GetStat() == GdPictureStatus.OK)
            {
                int wordCount = oGdPictureOCR.GetWordCount(resID);
                if (oGdPictureOCR.GetStat() == GdPictureStatus.OK)
                {
                    int left = oGdPictureOCR.GetWordLeft(resID, 0);
                    int top = oGdPictureOCR.GetWordTop(resID, 0);
                    if (oGdPicturePDF.DrawRectangle(left, top,
                                                    oGdPictureOCR.GetWordRight(resID, wordCount - 1) - left,
                                                    oGdPictureOCR.GetWordBottom(resID, wordCount - 1) - top,
                                                    false, true) == GdPictureStatus.OK)
                        MessageBox.Show("The recognized phone number area has been successfully drawn.", caption);
                    //Save the page with drawn recognized phone number to the new PDF document.
                    if (oGdPicturePDF.SaveToFile("output.pdf") == GdPictureStatus.OK)
                        MessageBox.Show("Done!", caption);
                    else
                        MessageBox.Show("The file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
                }
                else
                    MessageBox.Show("The GetWordCount() method has failed with the status: " + oGdPictureOCR.GetStat().ToString());
            }
            else
                MessageBox.Show("The error occurred when running the OCR. Status: " + oGdPictureOCR.GetStat().ToString(), caption);
            //Release the image.
            GdPictureDocumentUtilities.DisposeImage(image);
        }
        else
            MessageBox.Show("The error occurred when creating or setting up the image. Status: " + oGdPicturePDF.GetStat().ToString() + "/" + oGdPictureOCR.GetStat().ToString(), caption);
        //Close the document.
        oGdPicturePDF.CloseDocument();
    }
    else
        MessageBox.Show("The file can't be loaded. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
    //Release resources.
    oGdPictureOCR.ReleaseOCRResults();
    oGdPictureOCR.Dispose();
    oGdPicturePDF.Dispose();
    See Also