我正在尝试使用google cloud vision api文本检测。
using System;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Vision.V1;
using Google.Api.Gax.Grpc;
namespace blablabla
{
class Program
{
static void Main(string[] args)
{
string filePath = @"D:\Manisha\Pictures\1.png";
var image = Image.FromFile(filePath);
var client = ImageAnnotatorClient.Create();
var response = client.DetectText(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
Console.WriteLine(annotation.Description);
}
Console.ReadLine();
}
}
}
我在收到以下错误
"var客户端= ImageAnnotatorClient.Create();“
“应用程序默认凭据不可用。如果在Google Compute Engine中运行,则可以使用它们。否则,必须定义指向定义凭据的文件的环境变量GOOGLE_APPLICATION_CREDENTIALS。有关详细信息,请参阅https://developers.google.com/accounts/docs/application-default-credentials。”
我已经将GOOGLE_APPLICATION_CREDENTIALS设置为json文件路径。我到底哪里错了?我是否遗漏了一些重要的步骤?
发布于 2018-04-20 13:09:10
在这种情况下,您可以检查一些东西。
Studio是否需要restarted?
检查SDK正在使用的凭据的一种方法如下。
var credential = GoogleCredential.GetApplicationDefault();
这似乎是一种获取凭据实例的方法,以防您想要测试它。这对于ImageAnnotatorClient
本身并不是必需的。
https://stackoverflow.com/questions/49672973
复制相似问题