问题描述
我正在尝试开发C#Google Vision API函数.
I am trying to develop C# Google Vision API function.
该代码应编译为dll,并且应运行以执行以下步骤.
the code is supposed to compile into dll and it should run to do the following steps.
- 从图像路径获取图像.
- 将图像发送到Google视觉api
- 调用文档文本检测功能
- 获取返回值(文本字符串值)
- 完成
当我运行dll时,它一直给我抛出异常异常错误.我假设问题出在Google凭证上,但不确定...
When I run the dll, However, it keeps giving me an throw exception error. I am assuming that the problem is on the google credential but not sure...
有人可以帮我这个忙吗?我什至不知道var凭据= GoogleCredential.FromFile(Credential_Path);是调用json文件的正确方法...
Could somebody help me out with this? I don't even know that the var credential = GoogleCredential.FromFile(Credential_Path); would be the right way to call the json file...
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
,如此处
You just need to setup the environment variable GOOGLE_APPLICATION_CREDENTIALS
as mentioned here
这篇关于Google Vision API Document_Text_Detection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!