Hi all,
I'm using Google.Cloud.Vision.V1 to get text in a single image. However when I run the code from the link
https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Vision.V1/latest/index
It always return duplicate text value in the result.
Do you know the root cause?
Please help me resolve this case.
Thanks a lot!
Solved! Go to Solution.
Good day @BTMVIT,
Welcome to Google Cloud Community!
The result of textAnnotations will contain the entire extracted string for its first description and then by every text or word detected in the image for the subsequent description, so this is working as intended. https://cloud.google.com/vision/docs/ocr#optical_character_recognition_ocr
Also here is an example of the result from the documentation: https://cloud.google.com/vision/docs/ocr#setting-the-location-using-the-client-libraries
Text detected in the image as a whole or full text annotation
"description": "WAITING?\nPLEASE\nTURN OFF\nYOUR\nENGINE\n"
Text detected in the image by word
"description": "WAITING?"
"description": "PLEASE"
"description": "TURN"
"description": "OFF"
"description": "YOUR"
"description": "ENGINE"
If you want to extract only the full string from the result, you can do this by removing the foreach loop and only extract the first element. Here is an example:
ImageAnnotatorClient client = ImageAnnotatorClient.Create();
IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image);
Console.WriteLine($"Description: {textAnnotations[0].Description}");
The result should be:
"Description: WAITING?\nPLEASE\nTURN OFF\nYOUR\nENGINE\n"
But if you want to extract only the description by words and you don't want to include the full string, you can do this by adding an if statement:
ImageAnnotatorClient client = ImageAnnotatorClient.Create();
IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image);
foreach (EntityAnnotation text in textAnnotations)
{
if (text != textAnnotations[0]){
Console.WriteLine($"Description: {text.Description}");
}
}
The result should be:
"Description: "WAITING?"
"Description: "PLEASE"
"Description: "TURN"
"Description: "OFF"
"Description: "YOUR"
"Description: "ENGINE"
Hope this helps!
Any body know the answer. Please help me!
Good day @BTMVIT,
Welcome to Google Cloud Community!
The result of textAnnotations will contain the entire extracted string for its first description and then by every text or word detected in the image for the subsequent description, so this is working as intended. https://cloud.google.com/vision/docs/ocr#optical_character_recognition_ocr
Also here is an example of the result from the documentation: https://cloud.google.com/vision/docs/ocr#setting-the-location-using-the-client-libraries
Text detected in the image as a whole or full text annotation
"description": "WAITING?\nPLEASE\nTURN OFF\nYOUR\nENGINE\n"
Text detected in the image by word
"description": "WAITING?"
"description": "PLEASE"
"description": "TURN"
"description": "OFF"
"description": "YOUR"
"description": "ENGINE"
If you want to extract only the full string from the result, you can do this by removing the foreach loop and only extract the first element. Here is an example:
ImageAnnotatorClient client = ImageAnnotatorClient.Create();
IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image);
Console.WriteLine($"Description: {textAnnotations[0].Description}");
The result should be:
"Description: WAITING?\nPLEASE\nTURN OFF\nYOUR\nENGINE\n"
But if you want to extract only the description by words and you don't want to include the full string, you can do this by adding an if statement:
ImageAnnotatorClient client = ImageAnnotatorClient.Create();
IReadOnlyList<EntityAnnotation> textAnnotations = client.DetectText(image);
foreach (EntityAnnotation text in textAnnotations)
{
if (text != textAnnotations[0]){
Console.WriteLine($"Description: {text.Description}");
}
}
The result should be:
"Description: "WAITING?"
"Description: "PLEASE"
"Description: "TURN"
"Description: "OFF"
"Description: "YOUR"
"Description: "ENGINE"
Hope this helps!