Google Cloud Vision API - client.DetectText - 如何获取特定的图像位置数据?
Google Cloud Vision API - client.DetectText - How Can I Get Specific Image Location Data?
我目前正在使用 client.DetectText 方法从一些图像中提取数据。图像本身不会随特定数据改变位置,我想获取图像特定区域的数据。
我是否应该只引用文本中的位置 return(特定的换行符)并希望始终如此,或者是否可以使用此代码:
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;
}
}
我可以添加参数来强制指定图像位置。或者我想我可以在提交代码之前以某种方式裁剪图像?
谢谢。
如果您想在检测完成之前更改图像的比例,您可以使用 CropHintsParams in the image context to build an AnnotateImageRequest 而不是直接传递图像。
如果您想在检测之前应用边界框,我建议执行手工图像裁剪,因为目前我没有通过 C# 客户端库看到任何可用选项。检查this thread.否则您可以在文本注释结果中使用 BoundingPoly 字段过滤结果。
我会看一下 REST reference 以了解应如何构建请求。
您还可以查看 Try it! 页面并检查 JSON 的构建方式。
我目前正在使用 client.DetectText 方法从一些图像中提取数据。图像本身不会随特定数据改变位置,我想获取图像特定区域的数据。
我是否应该只引用文本中的位置 return(特定的换行符)并希望始终如此,或者是否可以使用此代码:
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;
}
}
我可以添加参数来强制指定图像位置。或者我想我可以在提交代码之前以某种方式裁剪图像?
谢谢。
如果您想在检测完成之前更改图像的比例,您可以使用 CropHintsParams in the image context to build an AnnotateImageRequest 而不是直接传递图像。
如果您想在检测之前应用边界框,我建议执行手工图像裁剪,因为目前我没有通过 C# 客户端库看到任何可用选项。检查this thread.否则您可以在文本注释结果中使用 BoundingPoly 字段过滤结果。
我会看一下 REST reference 以了解应如何构建请求。
您还可以查看 Try it! 页面并检查 JSON 的构建方式。