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





In This Topic
GetBlockType Method (GdPictureSegmenter)
In This Topic
Returns the type of the specified block, that is a part of the segmentation result specified by its index.
Syntax
'Declaration
 
Public Function GetBlockType( _
   ByVal SegmentationResultID As String, _
   ByVal BlockIdx As Integer _
) As OCRBlockType
public OCRBlockType GetBlockType( 
   string SegmentationResultID,
   int BlockIdx
)
public function GetBlockType( 
    SegmentationResultID: String;
    BlockIdx: Integer
): OCRBlockType; 
public function GetBlockType( 
   SegmentationResultID : String,
   BlockIdx : int
) : OCRBlockType;
public: OCRBlockType GetBlockType( 
   string* SegmentationResultID,
   int BlockIdx
) 
public:
OCRBlockType GetBlockType( 
   String^ SegmentationResultID,
   int BlockIdx
) 

Parameters

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

Return Value

The type of the specified block. A member of the OCRBlockType enumeration.

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

Remarks
It is recommend to use the GdPictureSegmenter.GetStat method to identify the specific reason for the method's failure, if any.
Example
How to find out the number of detected blocks within the segmentation result and types of those blocks.
Dim caption As String = "Example: GetBlockType"
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.PageLayout
            'Run the segmentation process.
            Dim resultID As String = gdpictureSegmenter.RunSegmentation()
            If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                Dim message As String = ""
                'Check the results.
                Dim blockCount As Integer = gdpictureSegmenter.GetBlockCount(resultID)
                If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                    message = message + "The number of detected blocks: " + blockCount.ToString()
                    For i As Integer = 0 To blockCount - 1
                        message = message + vbCrLf + "The block nr." + i.ToString() + " is of the type " + gdpictureSegmenter.GetBlockType(resultID, i).ToString() +
                                                     " and includes " + gdpictureSegmenter.GetBlockParagraphCount(resultID, i).ToString() + " paragraphs."
                    Next
                    MessageBox.Show(message, caption)
                    'Continue ...
                Else
                    MessageBox.Show("The GetBlockCount() 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: GetBlockType";
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.PageLayout;
            //Run the segmentation process.
            string resultID = gdpictureSegmenter.RunSegmentation();
            if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
            {
                string message = "";
                //Check the results.
                int blockCount = gdpictureSegmenter.GetBlockCount(resultID);
                if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
                {
                    message = message + "The number of detected blocks: " + blockCount.ToString();
                    for (int i = 0; i < blockCount; i++)
                    {
                        message = message + "\nThe block nr." + i.ToString() + " is of the type " + gdpictureSegmenter.GetBlockType(resultID, i).ToString() +
                                            " and includes " + gdpictureSegmenter.GetBlockParagraphCount(resultID, i).ToString() + " paragraphs.";
                    }
                    MessageBox.Show(message, caption);
                    //Continue ...
                }
                else
                    MessageBox.Show("The GetBlockCount() 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