首页 > 解决方案 > 如何使用谷歌图像到文本 API 获取文本的 XY 坐标?

问题描述

我正在尝试使用 Google.Cloud.Vision.V1的 Windows 应用程序我能够提取文本并能够翻译,但我目前的意图是获取图像上文本的 XY 坐标,所以稍后我可以显示翻译文本在原始图像上的确切位置。

有人可以告诉我如何实现吗?

我目前的方法如下

var credential = GoogleCredential.FromFile(JsonFilePath).CreateScoped(ImageAnnotatorClient.DefaultScopes);
var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());

var client = ImageAnnotatorClient.Create();

var image = Image.FromFile(@"D:\Work Temp\image_2.JPG");
// Performs label detection on the image file
var response = client.DetectText(image); // TODO: need to get XY Coordinates of those texts
foreach (var annotation in response)
{
   if (annotation.Description != null)
   {
     Console.WriteLine(annotation.Description);                        
     translatedText.Add(TranslateTextSample(annotation.Description, "en"));
    }
 }
 textTranslate.Lines = translatedText.ToArray();

标签: c#google-cloud-platformgoogle-apiocrgoogle-translate

解决方案


推荐阅读