其他分享
首页 > 其他分享> > ocr http 调用

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

标签:调用,http,stream,Stream,req,ocr,data
来源: https://www.cnblogs.com/zwbsoft/p/16029567.html