Я создал простой класс для тестирования OCR API Googles vision. Я передаю простое изображение с 5 буквами, которое должно вернуть строку с "CRAIG" в нем. Хотя этот вызов 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
}
Как получить взамен только возвращаемые буквы?
class:
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));
}
}
}
}
Изображение Iпередано было простое слово, которое я нарисовал краской: