I am currently using the client.DetectText method to extract data from some images. The images themselves never change location with specific data and I would like to get data for a specific area of the image.
Should I just reference the location in the text return (the specific line break) and hope that that is always it or is there a way with this code:
Google.Cloud.Vision.V1.Image image = Google.Cloud.Vision.V1.Image.FromFile(imagepath);
ImageAnnotatorClient client = ImageAnnotatorClient.Create();
IReadOnlyList<EntityAnnotation> response = client.DetectText(image);
string test = string.Empty;
foreach (EntityAnnotation annotation in response)
{
if (annotation.Description != null)
{
Console.WriteLine(annotation.Description);
test += Environment.NewLine + annotation.Description;
}
}
That I can add parameters to force a specific image location. Or maybe I guess I could crop the image before hand in code somehow?
Thanks.
If you want to change the ratio of the image before the detection is done you can use the CropHintsParams in the image context to build an AnnotateImageRequest instead of passing the image directly.
If you want to apply a bounding box before the detection I would suggest performing a handmade image crop, because currently I don't see any available option through the C# client library. Check this thread. Otherwise you can filter the results afterwards with the BoundingPoly field in the text annotation result.
I would take a look at the REST reference to understand how the request should be build.
You can also take a look at the Try it! page and check how the JSONs are built.