ocr http 调用
orc环境自行搭建,本文主要介绍http连接OCR的方式
http方法
public static Stream parsePIC(string base64Date)
{
try
{
string ocr = "http://***:***/predict/ocr_system";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ocr);
req.Method = "POST";
req.ContentType = "application/json";
string param = "{\"images\":[\"" + base64Date + "\"]}";
byte[] data = Encoding.UTF8.GetBytes(param);
req.ContentLength = data.Length;
using (Stream reqstream = req.GetRequestStream())
{
reqstream.Write(data, 0, data.Length);
reqstream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
return stream;
}
catch (Exception ex)
{
throw ex;
}
}
具体调用方式 首先要存在stream流文件
Stream stream = HttpHelper.parsePIC(base64);
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
text_region_xh = new List<List<int>>();
results = reader.ReadToEnd();
JObject jobject = JsonConvert.DeserializeObject<JObject>(results);
JArray jarray = (JArray)jobject.GetValue("results").First;
foreach (JObject item in jarray)
{
if (xh == item.GetValue("text").ToString())
}
}
其中JObject需要引用依赖Newtonsoft.Json.Linq
本文来自博客园,作者:zwbsoft,转载请注明原文链接:https://www.cnblogs.com/zwbsoft/p/16029567.html
电话微信:13514280351