GetWordIsFromDictionary Method (GdPictureOCR)
In This Topic
Returns, if the specified word within a specified OCR result, has been found in the added dictionaries.
Syntax
'Declaration
Public Function GetWordIsFromDictionary( _
ByVal As String, _
ByVal As Integer _
) As Boolean
public bool GetWordIsFromDictionary(
string ,
int
)
public function GetWordIsFromDictionary(
: String;
: Integer
): Boolean;
public function GetWordIsFromDictionary(
: String,
: int
) : boolean;
public: bool GetWordIsFromDictionary(
string* ,
int
)
public:
bool GetWordIsFromDictionary(
String^ ,
int
)
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
true, if the specified word has been found in the added dictionaries, otherwise false.
Please always use the GdPictureOCR.GetStat method to determine if this method has been successful.
Example
How to find out the number of recognized words within the OCR result and some of the word's properties.
Dim caption As String = "Example: GetWordIsFromDictionary"
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"
'Release default languages.
gdpictureOCR.ResetSelectedDictionaries()
'Add required languages.
gdpictureOCR.AddLanguage(OCRLanguage.Slovak)
gdpictureOCR.AddLanguage(OCRLanguage.Czech)
'Set up the OCR mode.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy
'Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
gdpictureOCR.CharacterSet = ""
'Set up the area to be processed by the OCR.
gdpictureOCR.SetROI(100, 100, 200, 200)
'Run the OCR process.
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 message As String = "The number of recognized words: " + wordCount.ToString()
'Analyze the results.
For i As Integer = 0 To wordCount - 1
message = message + vbCrLf + i.ToString() + ".word: " + gdpictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + gdpictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + gdpictureOCR.GetWordRecognitionLanguage(resID, i) + vbCrLf +
message = " Font: " + gdpictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + gdpictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + gdpictureOCR.GetWordFontStyle(resID, i).ToString() + vbCrLf +
" monospaced" + gdpictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + gdpictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + gdpictureOCR.GetWordFontIsSmallcaps(resID, i).ToString()
Next
MessageBox.Show(message, 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: GetWordIsFromDictionary";
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";
//Release default languages.
gdpictureOCR.ResetSelectedDictionaries();
//Add required languages.
gdpictureOCR.AddLanguage(OCRLanguage.Slovak);
gdpictureOCR.AddLanguage(OCRLanguage.Czech);
//Set up the OCR mode.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;
//Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
gdpictureOCR.CharacterSet = "";
//Set up the area to be processed by the OCR.
gdpictureOCR.SetROI(100, 100, 200, 200);
//Run the OCR process.
string resID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
int wordCount = gdpictureOCR.GetWordCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
string message = "The number of recognized words: " + wordCount.ToString();
//Analyze the results.
for (int i = 0; i < wordCount; i++)
{
message = message + "\n" + i.ToString() + ".word: " + gdpictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + gdpictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + gdpictureOCR.GetWordRecognitionLanguage(resID, i) +
message = "\n Font: " + gdpictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + gdpictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + gdpictureOCR.GetWordFontStyle(resID, i).ToString() +
"\n: monospaced" + gdpictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + gdpictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + gdpictureOCR.GetWordFontIsSmallcaps(resID, i).ToString();
}
MessageBox.Show(message, caption);
}
else
MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
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();
Example
How to find out the number of recognized words within the OCR result and some of the word's properties.
Dim caption As String = "Example: GetWordIsFromDictionary"
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"
'Release default languages.
gdpictureOCR.ResetSelectedDictionaries()
'Add required languages.
gdpictureOCR.AddLanguage(OCRLanguage.Slovak)
gdpictureOCR.AddLanguage(OCRLanguage.Czech)
'Set up the OCR mode.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy
'Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
gdpictureOCR.CharacterSet = ""
'Set up the area to be processed by the OCR.
gdpictureOCR.SetROI(100, 100, 200, 200)
'Run the OCR process.
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 message As String = "The number of recognized words: " + wordCount.ToString()
'Analyze the results.
For i As Integer = 0 To wordCount - 1
message = message + vbCrLf + i.ToString() + ".word: " + gdpictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + gdpictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + gdpictureOCR.GetWordRecognitionLanguage(resID, i) + vbCrLf +
message = " Font: " + gdpictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + gdpictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + gdpictureOCR.GetWordFontStyle(resID, i).ToString() + vbCrLf +
" monospaced" + gdpictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + gdpictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + gdpictureOCR.GetWordFontIsSmallcaps(resID, i).ToString()
Next
MessageBox.Show(message, 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: GetWordIsFromDictionary";
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";
//Release default languages.
gdpictureOCR.ResetSelectedDictionaries();
//Add required languages.
gdpictureOCR.AddLanguage(OCRLanguage.Slovak);
gdpictureOCR.AddLanguage(OCRLanguage.Czech);
//Set up the OCR mode.
gdpictureOCR.OCRMode = OCRMode.FavorAccuracy;
//Set up the OCR context and the character list.
gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
gdpictureOCR.CharacterSet = "";
//Set up the area to be processed by the OCR.
gdpictureOCR.SetROI(100, 100, 200, 200);
//Run the OCR process.
string resID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
int wordCount = gdpictureOCR.GetWordCount(resID);
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
string message = "The number of recognized words: " + wordCount.ToString();
//Analyze the results.
for (int i = 0; i < wordCount; i++)
{
message = message + "\n" + i.ToString() + ".word: " + gdpictureOCR.GetWordValue(resID, i) +
message = " IsFromDict: " + gdpictureOCR.GetWordIsFromDictionary(resID, i).ToString() +
message = " Language: " + gdpictureOCR.GetWordRecognitionLanguage(resID, i) +
message = "\n Font: " + gdpictureOCR.GetWordFontFamilyName(resID, i) +
" size: " + gdpictureOCR.GetWordFontSize(resID, i).ToString() +
" style: " + gdpictureOCR.GetWordFontStyle(resID, i).ToString() +
"\n: monospaced" + gdpictureOCR.GetWordFontIsMonospaced(resID, i).ToString() +
" serif" + gdpictureOCR.GetWordFontIsSerif(resID, i).ToString() +
" smallcaps" + gdpictureOCR.GetWordFontIsSmallcaps(resID, i).ToString();
}
MessageBox.Show(message, caption);
}
else
MessageBox.Show("The GetWordCount() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
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