GetKeyValuePairKeyString Method (GdPictureOCR)
In This Topic
Returns the string representation of the key part of a specified key-value pair.
Syntax
'Declaration
Public Function GetKeyValuePairKeyString( _
ByVal As String, _
ByVal As Integer _
) As String
public string GetKeyValuePairKeyString(
string ,
int
)
public function GetKeyValuePairKeyString(
: String;
: Integer
): String;
public function GetKeyValuePairKeyString(
: String,
: int
) : String;
public: string* GetKeyValuePairKeyString(
string* ,
int
)
public:
String^ GetKeyValuePairKeyString(
String^ ,
int
)
Parameters
- OCRResultID
- The unique result identifier of the executed OCR process obtained by the GdPictureOCR.RunOCR method.
- PairIdx
- The 0-based index of the key-value pair within the specified OCR result. It must be a value between 0 and GdPictureOCR.GetKeyValuePairCount(OCRResultID) - 1.
Return Value
The string representation of the key.
Example
Extracting key-value pairs from an image.
string caption = "Example: KVP/OCR";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
//Set up your prefered parameters for OCR.
gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
gdpictureOCR.EnableSkewDetection = true;
if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
{
//Set up the image you want to process.
GdPictureImaging gdpictureImaging = new GdPictureImaging();
//The standard open file dialog displays to allow you to select the file.
int image = gdpictureImaging.CreateGdPictureImageFromFile("");
gdpictureOCR.SetImage(image);
string ocrResultID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
string keyValuePairsData = "";
for (int pairIdx = 0; pairIdx < gdpictureOCR.GetKeyValuePairCount(ocrResultID); pairIdx++)
{
if (pairIdx != 0)
{
keyValuePairsData += "\n";
}
keyValuePairsData += "Name: " + gdpictureOCR.GetKeyValuePairKeyString(ocrResultID, pairIdx) + " | " +
"Value: " + gdpictureOCR.GetKeyValuePairValueString(ocrResultID, pairIdx) + " | " +
"Type: " + gdpictureOCR.GetKeyValuePairDataType(ocrResultID, pairIdx).ToString() + " | " +
"Accuracy: " + Math.Round(gdpictureOCR.GetKeyValuePairConfidence(ocrResultID, pairIdx), 1).ToString() + "%";
}
MessageBox.Show(keyValuePairsData, caption);
}
else
{
MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
//Release the used image.
gdpictureImaging.ReleaseGdPictureImage(image);
}
else
MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
gdpictureOCR.ReleaseOCRResults();
}
Example
Extracting key-value pairs from an image.
string caption = "Example: KVP/OCR";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
//Set up your prefered parameters for OCR.
gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
gdpictureOCR.EnableSkewDetection = true;
if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
{
//Set up the image you want to process.
GdPictureImaging gdpictureImaging = new GdPictureImaging();
//The standard open file dialog displays to allow you to select the file.
int image = gdpictureImaging.CreateGdPictureImageFromFile("");
gdpictureOCR.SetImage(image);
string ocrResultID = gdpictureOCR.RunOCR();
if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
{
string keyValuePairsData = "";
for (int pairIdx = 0; pairIdx < gdpictureOCR.GetKeyValuePairCount(ocrResultID); pairIdx++)
{
if (pairIdx != 0)
{
keyValuePairsData += "\n";
}
keyValuePairsData += "Name: " + gdpictureOCR.GetKeyValuePairKeyString(ocrResultID, pairIdx) + " | " +
"Value: " + gdpictureOCR.GetKeyValuePairValueString(ocrResultID, pairIdx) + " | " +
"Type: " + gdpictureOCR.GetKeyValuePairDataType(ocrResultID, pairIdx).ToString() + " | " +
"Accuracy: " + Math.Round(gdpictureOCR.GetKeyValuePairConfidence(ocrResultID, pairIdx), 1).ToString() + "%";
}
MessageBox.Show(keyValuePairsData, caption);
}
else
{
MessageBox.Show("The OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
}
//Release the used image.
gdpictureImaging.ReleaseGdPictureImage(image);
}
else
MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
gdpictureOCR.ReleaseOCRResults();
}
See Also