尝试使用 Google Cloud Vision 使用 c# asp.net c# 检测图像值

Trying detect image Values using Google Cloud Vision using c# asp.net c#

尝试使用 Google Cloud Vision 使用 c# asp.net c# 检测图像值,但我遇到以下错误。

Error loading native library. Not found in any of the possible locations: C:\Users\mazharkhan\Documents\Visual Studio 2013\WebSites\googleapi\bin\grpc_csharp_ext.x86.dll,C:\Users\mazharkhan\Documents\Visual Studio 2013\WebSites\googleapi\bin\runtimes/win/native\grpc_csharp_ext.x86.dll,C:\Users\mazharkhan\Documents\Visual Studio 2013\WebSites\googleapi\bin\../..\runtimes/win/native\grpc_csharp_ext.x86.dll

我在下面一行中收到错误。并尝试打开此 url 无效:http://vision.googleapis.com

var channel = new Grpc.Core.Channel(@"http://vision.googleapis.com", credential.ToChannelCredentials()); // <-- Getting error in this line 

下面是我的设计代码。

<form id="form1" runat="server">
<div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>

下面是我的代码,它在点击按钮后显示在标签中

protected void Button1_Click(object sender, EventArgs e)
{
    var image = Google.Cloud.Vision.V1.Image.FromFile(@"C:\!\cat.jpg");
    var credential = GoogleCredential.FromFile(@"C:\!\Tutorials-0a2efaf1b53c.json");
    var channel = new Grpc.Core.Channel(@"http://vision.googleapis.com", credential.ToChannelCredentials()); // <-- Getting error in this line 
    var client = ImageAnnotatorClient.Create(channel);
    var response = client.DetectText(image); 
    foreach (var annotation in response)
    {
        if (annotation.Description != null)
            //    Console.WriteLine(annotation.Description);
            Label1.Text += annotation.Description + "\r\n";

    }

}

我用下面的例子url:

我也在 google 中为 json 文件创建了服务密钥帐户。

此错误实际上与 Vision API 或身份验证无关 - 这是因为 gRPC 未正确加载。听起来您使用的是 "Web Site" 项目而不是 "Web Application" 项目。这是一个 known issue - 在开始使用 gRPC 之前,有一个在执行时将相关库复制到 bin 目录的解决方法,但我建议不要这样做。

如果可能的话,我建议改用 Web 应用程序项目。