gpt4 book ai didi

c# - Google Vision API Document_Text_Detection

转载 作者:太空宇宙 更新时间:2023-11-03 22:38:29 35 4
gpt4 key购买 nike

我正在尝试开发 C# Google Vision API 函数。

代码应该编译成 dll 并且应该运行以执行以下步骤。

  1. 从图像路径获取图像。
  2. 将图像发送到 Google vision api
  3. 调用文档文本检测函数
  4. 获取返回值(文本字符串值)
  5. 完成

但是,当我运行 dll 时,它一直给我抛出异常错误。我假设问题出在 google 凭据上,但不确定...

有人可以帮我解决这个问题吗?我什至不知道 var credential = GoogleCredential.FromFile(Credential_Path);将是调用 json 文件的正确方法...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Google.Cloud.Vision.V1;
using Google.Apis.Auth.OAuth2;
using Image = Google.Cloud.Vision.V1.Image;


namespace DLL_TEST_NetFramework4._6._1version
{
public class Class1
{
public string doc_text_dection(string GVA_File_Path, string Credential_Path)
{
var credential = GoogleCredential.FromFile(Credential_Path);
//Load the image file into memory
var image = Image.FromFile(GVA_File_Path);

// Instantiates a client
ImageAnnotatorClient client = ImageAnnotatorClient.Create();

TextAnnotation text = client.DetectDocumentText(image);
//Console.WriteLine($"Text: {text.Text}");

return $"Text: {text.Text}";
//return "test image...";
}
}
}

最佳答案

您只需要设置环境变量GOOGLE_APPLICATION_CREDENTIALS,如前所述here

关于c# - Google Vision API Document_Text_Detection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701338/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com