Reference Guide
GdPicture14 Namespace / GdPictureSegmenter Class / GetCharacterLeft Method
The unique result identifier of the executed segmentation process obtained by the RunSegmentation method.
The 0-based index of the character within the specified segmentation result. It must be a value between 0 and GetCharacterCount(SegmentationResultID)-1.
Example





In This Topic
    GetCharacterLeft Method (GdPictureSegmenter)
    In This Topic
    Returns the left x-coordinate of the bounding box of the specified character, that is a part of the segmentation 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 GetCharacterLeft( _
       ByVal SegmentationResultID As String, _
       ByVal CharacterIdx As Integer _
    ) As Integer
    public int GetCharacterLeft( 
       string SegmentationResultID,
       int CharacterIdx
    )
    public function GetCharacterLeft( 
        SegmentationResultID: String;
        CharacterIdx: Integer
    ): Integer; 
    public function GetCharacterLeft( 
       SegmentationResultID : String,
       CharacterIdx : int
    ) : int;
    public: int GetCharacterLeft( 
       string* SegmentationResultID,
       int CharacterIdx
    ) 
    public:
    int GetCharacterLeft( 
       String^ SegmentationResultID,
       int CharacterIdx
    ) 

    Parameters

    SegmentationResultID
    The unique result identifier of the executed segmentation process obtained by the RunSegmentation method.
    CharacterIdx
    The 0-based index of the character within the specified segmentation result. It must be a value between 0 and GetCharacterCount(SegmentationResultID)-1.

    Return Value

    The left x-coordinate of the character's bounding box, in pixels.

    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 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 find out detected characters within the segmentation result. All characters are subsequently color-coded and saved into the output file.
    Dim caption As String = "Example: GetCharacterLeft"
    Using oGdPictureSegmenter As GdPictureSegmenter = New GdPictureSegmenter()
        Using oGdPictureImage As GdPictureImaging = New GdPictureImaging()
            'Set up the image you want to process.
            Dim image As Integer = oGdPictureImage.CreateGdPictureImageFromFile("input.tif")
            If (oGdPictureImage.GetStat() = GdPictureStatus.OK) AndAlso
               (oGdPictureSegmenter.SetImage(image) = GdPictureStatus.OK) Then
                'Set the segmentation mode.
                oGdPictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4
                'Run the segmentation process.
                Dim resultID As String = oGdPictureSegmenter.RunSegmentation()
                If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then
                    'Check the results.
                    Dim characterCount As Integer = oGdPictureSegmenter.GetCharacterCount(resultID)
                    If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then
                        Dim message As String = "The number of detected characters: "
                        message = message + characterCount.ToString() + vbCrLf
                        Dim top As Integer = 0, left As Integer = 0, bottom As Integer = 0, right As Integer = 0, save As Integer = 0
                        For i As Integer = 0 To characterCount - 1
                            top = oGdPictureSegmenter.GetCharacterTop(resultID, i)
                            If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then left = oGdPictureSegmenter.GetCharacterLeft(resultID, i)
                            If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then bottom = oGdPictureSegmenter.GetCharacterBottom(resultID, i)
                            If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then right = oGdPictureSegmenter.GetCharacterRight(resultID, i)
                            If oGdPictureSegmenter.GetStat() = GdPictureStatus.OK Then
                                If oGdPictureImage.DrawRectangle(image, left, top, right - left, bottom - top, 5, Color.Brown, True) = GdPictureStatus.OK Then
                                    message = message + (i + 1).ToString() + ".rectangle has been drawn." + vbCrLf
                                    save += 1
                                Else
                                    message = message + (i + 1).ToString() + ".rectangle HAS NOT been drawn. Status: " + oGdPictureSegmenter.GetStat().ToString() + vbCrLf
                                End If
                            Else
                                message = message + i.ToString() + ".word has failed to get its position. Status: " + oGdPictureSegmenter.GetStat().ToString() + vbCrLf
                            End If
                        Next
                        If characterCount = 0 Then
                            message = message + "The resulting image HAS NOT been created."
                        Else
                            If save = characterCount Then
                                If oGdPictureImage.SaveAsTIFF(image, "output.tif", TiffCompression.TiffCompressionAUTO) = GdPictureStatus.OK Then
                                    message = message + "The resulting image HAS been saved successfully."
                                Else
                                    message = message + "The resulting image HAS NOT been saved. Status: " + oGdPictureImage.GetStat().ToString()
                                End If
                            End If
                        End If
                        MessageBox.Show(message, caption)
                    Else
                        MessageBox.Show("The GetCharacterCount() method has failed with the status: " + oGdPictureSegmenter.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("The segmentation process has failed with the status: " + oGdPictureSegmenter.GetStat().ToString(), caption)
                End If
                'Release the used image.
                oGdPictureImage.ReleaseGdPictureImage(image)
            Else
                MessageBox.Show("The error occurred when setting up the image: " + oGdPictureImage.GetStat().ToString() + " or " + oGdPictureSegmenter.GetStat().ToString(), caption)
            End If
        End Using
        'Release resources.
        oGdPictureSegmenter.ReleaseSegmentationResults()
    End Using
    string caption = "Example: GetCharacterLeft";
    using (GdPictureSegmenter oGdPictureSegmenter = new GdPictureSegmenter())
    {
        //Set up the image you want to process.
        using (GdPictureImaging oGdPictureImage = new GdPictureImaging())
        {
            //The standard open file dialog displays to allow you to select the file.
            int image = oGdPictureImage.CreateGdPictureImageFromFile("input.tif");
            if ((oGdPictureImage.GetStat() == GdPictureStatus.OK) &&
                (oGdPictureSegmenter.SetImage(image) == GdPictureStatus.OK))
            {
                //Set the segmentation mode.
                oGdPictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4;
                //Run the segmentation process.
                string resultID = oGdPictureSegmenter.RunSegmentation();
                if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                {
                    //Check the results.
                    int characterCount = oGdPictureSegmenter.GetCharacterCount(resultID);
                    if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                    {
                        string message = "The number of detected characters: ";
                        message = message + characterCount.ToString() + "\n";
                        int top = 0, left = 0, bottom = 0, right = 0, save = 0;
                        for (int i = 0; i < characterCount; i++)
                        {
                            top = oGdPictureSegmenter.GetCharacterTop(resultID, i);
                            if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                                left = oGdPictureSegmenter.GetCharacterLeft(resultID, i);
                            if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                                bottom = oGdPictureSegmenter.GetCharacterBottom(resultID, i);
                            if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                                right = oGdPictureSegmenter.GetCharacterRight(resultID, i);
                            if (oGdPictureSegmenter.GetStat() == GdPictureStatus.OK)
                            {
                                if (oGdPictureImage.DrawRectangle(image, left, top, right - left, bottom - top, 5, Color.Brown, true) == GdPictureStatus.OK)
                                {
                                    message = message + (i + 1).ToString() + ".rectangle has been drawn.\n";
                                    save++;
                                }
                                else
                                    message = message + (i + 1).ToString() + ".rectangle HAS NOT been drawn. Status: " + oGdPictureSegmenter.GetStat().ToString() + "\n";
                            }
                            else
                                message = message + i.ToString() + ".word has failed to get its position. Status: " + oGdPictureSegmenter.GetStat().ToString() + "\n";
                        }
                        if (characterCount == 0)
                        {
                            message = message + "The resulting image HAS NOT been created.";
                        }
                        else
                        {
                            if (save == characterCount)
                            {
                                if (oGdPictureImage.SaveAsTIFF(image, "output.tiff", TiffCompression.TiffCompressionAUTO) == GdPictureStatus.OK)
                                    message = message + "The resulting image HAS been saved successfully.";
                                else
                                    message = message + "The resulting image HAS NOT been saved. Status: " + oGdPictureImage.GetStat().ToString();
                            }
                        }
                        MessageBox.Show(message, caption);
                    }
                    else
                        MessageBox.Show("The GetCharacterCount() method has failed with the status: " + oGdPictureSegmenter.GetStat().ToString(), caption);
                }
                else
                    MessageBox.Show("The segmentation process has failed with the status: " + oGdPictureSegmenter.GetStat().ToString(), caption);
                //Release the used image.
                oGdPictureImage.ReleaseGdPictureImage(image);
            }
            else
                MessageBox.Show("The error occurred when setting up the image: " + oGdPictureImage.GetStat().ToString() + " or " + oGdPictureSegmenter.GetStat().ToString(), caption);
        }
        //Release resources.
        oGdPictureSegmenter.ReleaseSegmentationResults();
    }
    See Also