我创建了一个简单的类来测试Google视觉OCR API。我正在传递一个包含5个字母的简单图像,该图像应该返回其中包含“ CRAIG”的字符串。尽管此API调用返回了很多额外的信息:
{
"property": {
"detectedLanguages": [
{
"languagecode": "en"
}
]
},"boundingBox": {
"vertices": [
{
"x": 183,"y": 105
},{
"x": 674,"y": 253
},{
"x": 183,"y": 253
}
]
},"symbols": [
{
"property": {
"detectedLanguages": [
{
"languagecode": "en"
}
]
},"boundingBox": {
"vertices": [
{
"x": 183,"y": 105
},{
"x": 257,"y": 253
},{
"x": 183,"y": 253
}
]
},"text": "C","confidence": 0.99
},{
"property": {
"detectedLanguages": [
{
"languagecode": "en"
}
]
},"boundingBox": {
"vertices": [
{
"x": 249,{
"x": 371,{
"x": 249,"text": "R","boundingBox": {
"vertices": [
{
"x": 459,{
"x": 581,{
"x": 459,"text": "A","boundingBox": {
"vertices": [
{
"x": 582,{
"x": 638,{
"x": 582,"text": "I","confidence": 0.98
},{
"property": {
"detectedLanguages": [
{
"languagecode": "en"
}
],"detectedBreak": {
"type": "LINE_BREAK"
}
},"boundingBox": {
"vertices": [
{
"x": 636,{
"x": 674,{
"x": 636,"text": "G","confidence": 0.99
}
],"confidence": 0.98
}
我如何只取回信件?
班级:
public static void Main(string[] args)
{
string credential_path = @"C:\Users\35385\nodal.json";
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS",credential_path);
// Instantiates a client
var client = ImageAnnotatorClient.Create();
// Load the image file into memory
var image = Image.FromFile("vision.jpg");
// Performs label detection on the image file
var response = client.DetectDocumentText(image);
foreach (var page in response.Pages)
{
foreach (var block in page.Blocks)
{
foreach (var paragraph in block.Paragraphs)
{
Console.WriteLine(string.Join("\n",paragraph.Words));
}
}
}
}
我传入的图像是我用油漆画出的一个简单单词: