我创建了一个简单的类来测试googles vision。我正在传递一个简单的图像与5个字母,应该返回一个字符串与“克雷格”在其中。虽然这个API调用返回了许多额外的信息:
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"vertices": [
{
"x": 183,
"y": 105
},
{
"x": 674,
"y": 105
},
{
"x": 674,
"y": 253
},
{
"x": 183,
"y": 253
}
]
},
"symbols": [
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"vertices": [
{
"x": 183,
"y": 105
},
{
"x": 257,
"y": 105
},
{
"x": 257,
"y": 253
},
{
"x": 183,
"y": 253
}
]
},
"text": "C",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"vertices": [
{
"x": 249,
"y": 105
},
{
"x": 371,
"y": 105
},
{
"x": 371,
"y": 253
},
{
"x": 249,
"y": 253
}
]
},
"text": "R",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"vertices": [
{
"x": 459,
"y": 105
},
{
"x": 581,
"y": 105
},
{
"x": 581,
"y": 253
},
{
"x": 459,
"y": 253
}
]
},
"text": "A",
"confidence": 0.99
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
]
},
"boundingBox": {
"vertices": [
{
"x": 582,
"y": 105
},
{
"x": 638,
"y": 105
},
{
"x": 638,
"y": 253
},
{
"x": 582,
"y": 253
}
]
},
"text": "I",
"confidence": 0.98
},
{
"property": {
"detectedLanguages": [
{
"languageCode": "en"
}
],
"detectedBreak": {
"type": "LINE_BREAK"
}
},
"boundingBox": {
"vertices": [
{
"x": 636,
"y": 105
},
{
"x": 674,
"y": 105
},
{
"x": 674,
"y": 253
},
{
"x": 636,
"y": 253
}
]
},
"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));
}
}
}
}
我传入的图像是我在绘画中画出来的一个简单的词:
发布于 2019-11-06 14:40:14
经过一些研究,以下内容为我提供了这个词,也提供了一个更清晰的输出:
Block Text at (183, 105) - (674, 105) - (674, 253) - (183, 253)
Paragraph at (183, 105) - (674, 105) - (674, 253) - (183, 253)
Word: CRAIG
方法:
foreach (var page in response.Pages)
{
foreach (var block in page.Blocks)
{
string box = string.Join(" - ", block.BoundingBox.Vertices.Select(v => $"({v.X}, {v.Y})"));
Console.WriteLine($"Block {block.BlockType} at {box}");
foreach (var paragraph in block.Paragraphs)
{
box = string.Join(" - ", paragraph.BoundingBox.Vertices.Select(v => $"({v.X}, {v.Y})"));
Console.WriteLine($" Paragraph at {box}");
foreach (var word in paragraph.Words)
{
Console.WriteLine($" Word: {string.Join("", word.Symbols.Select(s => s.Text))}");
}
}
}
}
发布于 2019-11-06 15:02:15
试着换..。
var response = client.DetectDocumentText(image);
至
var response = client.DetectText(image);
解释
以下是谷歌云视觉API文档中的一些信息
视觉API可以从图像中检测和提取文本。有两个支持光学字符识别(OCR)的辅助注释功能:
https://stackoverflow.com/questions/58721876
复制相似问题