ocr http 呼叫
阿新 • • 發佈:2022-03-20
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