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





In This Topic
GdPicture14 Namespace / GdPictureOCR Class / GetWordCharacterCount Method

GetWordCharacterCount Method (GdPictureOCR)

In This Topic
Returns the number of characters within the specified word, that is a part of a specified OCR result.
Syntax
'Declaration

 

Public Function GetWordCharacterCount( _

   ByVal OCRResultID As String, _

   ByVal WordIdx As Integer _

) As Integer
public int GetWordCharacterCount( 

   string OCRResultID,

   int WordIdx

)
public function GetWordCharacterCount( 

    OCRResultID: String;

    WordIdx: Integer

): Integer; 
public function GetWordCharacterCount( 

   OCRResultID : String,

   WordIdx : int

) : int;
public: int GetWordCharacterCount( 

   string* OCRResultID,

   int WordIdx

) 
public:

int GetWordCharacterCount( 

   String^ OCRResultID,

   int WordIdx

) 

Parameters

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

Return Value

The number of characters. Please always use the GdPictureOCR.GetStat method to determine if this method has been successful.
Remarks
It is recommend to use the GdPictureOCR.GetStat method to identify the specific reason for the method's failure, if any.
Example
How to find out the number of characters in the recognized word within the OCR result.
Dim caption As String = "Example: GetWordCharacterCount"

Dim gdpictureOCR As GdPictureOCR = New GdPictureOCR

Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF

'Load the PDF document.

If gdpicturePDF.LoadFromFile("input.pdf", False) = GdPictureStatus.OK Then

    'Select the first page.

    gdpicturePDF.SelectPage(1)

    'Render this page to a 200 DPI image.

    Dim image As Integer = gdpicturePDF.RenderPageToGdPictureImage(200, True)

    If gdpicturePDF.GetStat = GdPictureStatus.OK AndAlso

       gdpictureOCR.SetImage(image) = GdPictureStatus.OK Then

        'Setting up the image is mandatory.

        'Set up the OCR parameters.

        gdpictureOCR.ResourcesFolder = "C:\Path\To\GdPicture.NET 14\Redist\OCR"

        gdpictureOCR.AddLanguage(OCRLanguage.English)

        gdpictureOCR.OCRMode = OCRMode.FavorAccuracy

        'Set up the OCR context and the character list.

        gdpictureOCR.Context = OCRContext.OCRContextSingleLine

        gdpictureOCR.CharacterSet = "0123456789"

        'Set up the area to be processed by the OCR.

        gdpictureOCR.SetROI(100, 100, 200, 50)

        'Run the OCR process to recognize the phone number.

        Dim resID As String = gdpictureOCR.RunOCR()

        If gdpictureOCR.GetStat = GdPictureStatus.OK Then

            Dim wordCount As Integer = gdpictureOCR.GetWordCount(resID)

            If gdpictureOCR.GetStat = GdPictureStatus.OK Then

                Dim content As String = "", word As String = ""

                Dim charAll As Integer = 0, charCount As Integer = 0

                For i As Integer = 0 To wordCount - 1

                    word = gdpictureOCR.GetWordValue(resID, i)

                    If gdpictureOCR.GetStat() = GdPictureStatus.OK Then

                        content = content + " " + word

                    End If

                    charCount = gdpictureOCR.GetWordCharacterCount(resID, i)

                    If gdpictureOCR.GetStat() = GdPictureStatus.OK Then

                        charAll = charAll + charCount

                    End If

                    Dim index As Integer = gdpictureOCR.GetWordFirstCharacterIndex(resID, i)

                    'Continue with analyzing the result ...

                Next

                MessageBox.Show("The number of recognized words: " + wordCount.ToString() + vbCrLf +

                                "The number of recognized characters in all words: " + charAll.ToString() + vbCrLf +

                                "Content: " + content, caption)

            Else

                MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)

            End If

        Else

            MessageBox.Show("The error occurred when running the OCR. Status: " + gdpictureOCR.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: " + gdpicturePDF.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption)

    End If

    'Close the document.

    gdpicturePDF.CloseDocument()

Else

    MessageBox.Show("The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString(), caption)

End If

'Release resources.

gdpictureOCR.ReleaseOCRResults()

gdpictureOCR.Dispose()

gdpicturePDF.Dispose()
string caption = "Example: GetWordCharacterCount";

GdPictureOCR gdpictureOCR = new GdPictureOCR();

GdPicturePDF gdpicturePDF = new GdPicturePDF();

//Load the PDF document.

if (gdpicturePDF.LoadFromFile("input.pdf", false) == GdPictureStatus.OK)

{

    //Select the first page.

    gdpicturePDF.SelectPage(1);

    //Render this page to a 200 DPI image.

    int image = gdpicturePDF.RenderPageToGdPictureImage(200, true);

    if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&

        (gdpictureOCR.SetImage(image) == GdPictureStatus.OK)) //Setting up the image is mandatory.

    {

        //Set up the OCR parameters.

        gdpictureOCR.ResourcesFolder = "C:\\Path\\To\\GdPicture.NET 14\\Redist\\OCR";

        gdpictureOCR.AddLanguage(OCRLanguage.English);

        gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;

        //Set up the OCR context and the character list.

        gdpictureOCR.Context = OCRContext.OCRContextSingleLine;

        gdpictureOCR.CharacterSet = "0123456789";

        //Set up the area to be processed by the OCR.

        gdpictureOCR.SetROI(100, 100, 200, 50);

        //Run the OCR process to recognize the phone number.

        string resID = gdpictureOCR.RunOCR();

        if (gdpictureOCR.GetStat() == GdPictureStatus.OK)

        {

            int wordCount = gdpictureOCR.GetWordCount(resID);

            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)

            {

                string content = "", word = "";

                int charAll = 0, charCount = 0;

                for (int i = 0; i < wordCount; i++)

                {

                    word = gdpictureOCR.GetWordValue(resID, i);

                    if (gdpictureOCR.GetStat() == GdPictureStatus.OK)

                        content = content + " " + word;

                    charCount = gdpictureOCR.GetWordCharacterCount(resID, i);

                    if (gdpictureOCR.GetStat() == GdPictureStatus.OK)

                        charAll = charAll + charCount;

                    int index = gdpictureOCR.GetWordFirstCharacterIndex(resID, i);

                    //Continue with analyzing the result ...

                }

                MessageBox.Show("The number of recognized words: " + wordCount.ToString() +

                                "\nThe number of recognized characters in all words: " + charAll.ToString() +

                                "\nContent: " + content, caption);

            }

            else

                MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString());

        }

        else

            MessageBox.Show("The error occurred when running the OCR. Status: " + gdpictureOCR.GetStat().ToString(), caption);

        //Release the image.

        GdPictureDocumentUtilities.DisposeImage(image);

    }

    else

        MessageBox.Show("The error occurred when creating or setting up the image. Status: " + gdpicturePDF.GetStat().ToString() + "/" + gdpictureOCR.GetStat().ToString(), caption);

    //Close the document.

    gdpicturePDF.CloseDocument();

}

else

    MessageBox.Show("The file can't be loaded. Status: " + gdpicturePDF.GetStat().ToString(), caption);

//Release resources.

gdpictureOCR.ReleaseOCRResults();

gdpictureOCR.Dispose();

gdpicturePDF.Dispose();
See Also