【问题标题】:Google vision connection to API without external google DLL谷歌视觉连接到 API 没有外部谷歌 DLL
【发布时间】:2020-09-09 04:04:50
【问题描述】:

如何在不使用外部dll的情况下连接谷歌云视觉?

【问题讨论】:

    标签: c# image-processing ocr google-cloud-vision google-vision


    【解决方案1】:

    首先,您必须生成 JSON 请求,简单示例:

                Request req = new Request();
                req.addFeature("DOCUMENT_TEXT_DETECTION"); //Add here all the feature types
                req.Image.content = Convert.ToBase64String(qq);//qq is a byte[]
                Requests reqList = new Requests(req);
                json = JsonConvert.SerializeObject(reqList);
    

    其次,您需要发布简单的 HTTP 请求:

    var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://vision.googleapis.com/v1/images:annotate?key="PLACE_YOURKEY_HERE"");
                    httpWebRequest.ContentType = "application/json";
                    httpWebRequest.Method = "POST";
                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        streamWriter.Write(json);
                    }
    
                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        response = streamReader.ReadToEnd();
                    }
    

    JSON 类的成员(应实现的方法):

        class Requests
    {
        public List<Request> Request { get; set; }
    }
    class Request
    {
        public Image1 Image { get; set; }
        public List<Feature> Features { get; set; }
    
    }
    public class Feature
    {
        public string Type { get; set; }
    }
    
    public class Image1
    {
        public string content { get; set; }
    }
    

    与主题相关的链接

    Google Vision API Document_Text_Detection

    Feature types

    Google vision

    【讨论】:

      猜你喜欢
      • 2017-06-14
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      相关资源
      最近更新 更多