Google 到 API 的视觉连接,无需外部 google DLL
Google vision connection to API without external google DLL
如何在不使用外部 dll 的情况下连接到 google 云视觉?
首先,你必须生成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);
其次,您需要post简单的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
如何在不使用外部 dll 的情况下连接到 google 云视觉?
首先,你必须生成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);
其次,您需要post简单的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