GdPicture.NET.14
GdPicture14 Namespace / GdPictureSegmenter Class / GetTextLineWordCount Method
The unique result identifier of the executed segmentation process obtained by the RunSegmentation method.
The 0-based index of the text line within the specified segmentation result. It must be a value between 0 and GetTextLineCount(SegmentationResultID)-1.
Example





In This Topic
GetTextLineWordCount Method (GdPictureSegmenter)
In This Topic
Returns the number of words within the specified text line, that is a part of the segmentation result specified by its index.
Syntax
'Declaration
 
Public Function GetTextLineWordCount( _
   ByVal SegmentationResultID As String, _
   ByVal TextLineIdx As Integer _
) As Integer
public int GetTextLineWordCount( 
   string SegmentationResultID,
   int TextLineIdx
)
public function GetTextLineWordCount( 
    SegmentationResultID: String;
    TextLineIdx: Integer
): Integer; 
public function GetTextLineWordCount( 
   SegmentationResultID : String,
   TextLineIdx : int
) : int;
public: int GetTextLineWordCount( 
   string* SegmentationResultID,
   int TextLineIdx
) 
public:
int GetTextLineWordCount( 
   String^ SegmentationResultID,
   int TextLineIdx
) 

Parameters

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

Return Value

The number of words within a text line. 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.
Example
How to find out the number of detected words within the text line.
Dim caption As String = "Example: GetTextLineWordCount"
Using gdpictureSegmenter As GdPictureSegmenter = New GdPictureSegmenter()
    'Set up the image you want to process.
    Using 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
           (gdpictureSegmenter.SetImage(image) = GdPictureStatus.OK) Then
            'Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4
            'Run the segmentation process.
            Dim resultID As String = gdpictureSegmenter.RunSegmentation()
            If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                'Check the results.
                Dim textlineCount As Integer = gdpictureSegmenter.GetTextLineCount(resultID)
                If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                    Dim wordCount As Integer = 0, index As Integer = 0
                    For i As Integer = 0 To textlineCount - 1
                        wordCount = gdpictureSegmenter.GetTextLineWordCount(resultID, i)
                        If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                            index = gdpictureSegmenter.GetTextLineFirstWordIndex(resultID, i)
                            If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                                'Continue ...
                            Else
                                'handle the error
                            End If
                        Else
                            'handle the error
                        End If
                    Next
                Else
                    MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.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() + " or " + gdpictureSegmenter.GetStat().ToString(), caption)
        End If
    End Using
    'Release resources.
    gdpictureSegmenter.ReleaseSegmentationResults()
End Using
string caption = "Example: GetTextLineWordCount";
using (GdPictureSegmenter gdpictureSegmenter = new GdPictureSegmenter())
{
    //Set up the image you want to process.
    using (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) &&
            (gdpictureSegmenter.SetImage(image) == GdPictureStatus.OK))
        {
            //Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4;
            //Run the segmentation process.
            string resultID = gdpictureSegmenter.RunSegmentation();
            if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
            {
                //Check the results.
                int textlineCount = gdpictureSegmenter.GetTextLineCount(resultID);
                if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
                {
                    int wordCount = 0, index = 0;
                    for (int i = 0; i < textlineCount; i++)
                    {
                        wordCount = gdpictureSegmenter.GetTextLineWordCount(resultID, i);
                        if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
                        {
                            index = gdpictureSegmenter.GetTextLineFirstWordIndex(resultID, i);
                            if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
                            {
                                //Continue ...
                            }
                            //else handle the error
                        }
                        //else handle the error
                    }
                }
                else
                    MessageBox.Show("The GetTextLineCount() method has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption);
            }
            else
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption);
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureSegmenter.GetStat().ToString(), caption);
    }
    //Release resources.
    gdpictureSegmenter.ReleaseSegmentationResults();
}
See Also