public static T Get <T>(string url, Dictionary <string, string> param) { var preSignStr = HttpCore.CreateLinkString(param); if (preSignStr.Length > 0) { preSignStr = "?" + preSignStr; } var httpGetUrl = string.Concat(url, preSignStr); var wr = HttpRequest.Get(httpGetUrl); try { var response = wr.GetResponse(); var stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); var content = sr.ReadToEnd(); sr.Close(); JavaScriptSerializer serialize = new JavaScriptSerializer(); return(serialize.Deserialize <T>(content)); } catch (Exception ex) { return(default(T)); } }
public static T PostNoImage <T>(string url, Dictionary <string, string> param) { HttpWebRequest request = (HttpWebRequest)HttpRequest.Post(url); WebResponse response = null; StringBuilder sb = new StringBuilder(); try { var rs = request.GetRequestStream(); var preSignStr = HttpCore.CreateLinkString(param); var postdata = Encoding.UTF8.GetBytes(preSignStr); rs.Write(postdata, 0, postdata.Length); rs.Close(); response = request.GetResponse(); if (response != null) { var responseStream = response.GetResponseStream(); StreamReader sr = new StreamReader(responseStream); var content = sr.ReadToEnd(); sr.Close(); JavaScriptSerializer serialize = new JavaScriptSerializer(); return(serialize.Deserialize <T>(content)); } return(default(T)); } catch (Exception ex) { return(default(T)); } }
public void Run(string rtstpId, string videourl, float threshold) { this.rtstpId = rtstpId; //videourl = "rtsp://192.168.1.151/user=admin&password=&channel=1&stream=0.sdp?"; Console.WriteLine(videourl); Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("url", videourl); //抓拍的人脸张数(根据业务传) param.Add("limit", "10000"); param.Add("crop", "face"); //不转只进行抓拍 //param.Add("group", ""); //param.Add("threshold", threshold.ToString()); //抓图间隔 param.Add("interval", "3000"); //抓拍人脸的最小大小 param.Add("facemin", "100"); //websocket名称 param.Add("name", "snap"); var url = Constrants.url_video; var ext = HttpCore.CreateLinkString(param); url = url + "?" + ext; ws = new WebSocketSharp.WebSocket(url); ws.OnOpen += (a, b) => { Console.WriteLine("opened"); }; ws.OnClose += (a, b) => { Console.WriteLine("close"); }; ws.OnMessage += (a, m) => { Console.WriteLine("message coming..."); if (m.IsText) { Console.WriteLine("is text"); var result = GetFaceResult(m.Data); if (result.Type == "recognize") { if (result.Result.Face.Quality > threshold) { var temp = GetFaceResult(m.Data); temp.Face.Image = ""; var json = ToJson(temp); Console.WriteLine(json); if (OnFaceDetect != null) { OnFaceDetect(this.rtstpId, result); } } else { Console.WriteLine("低于阈值->" + result.Result.Face.Quality); } } else { Console.WriteLine("type=" + result.Type); } } if (m.IsBinary) { Console.WriteLine("is binary"); } if (m.IsPing) { Console.WriteLine("is ping"); } }; ws.Connect(); }
public void Run(string rtstpId, string videourl, float threshold) { this.rtstpId = rtstpId; Dictionary <string, string> param = new Dictionary <string, string>(); param.Add("url", videourl); //抓拍的人脸张数(根据业务传) param.Add("limit", "10000"); param.Add("crop", "face"); //不转只进行抓拍 //param.Add("group", ""); //param.Add("threshold", threshold.ToString()); //抓图间隔 param.Add("interval", "3000"); //抓拍人脸的最小大小 param.Add("facemin", "100"); //websocket名称 param.Add("name", "snap"); var url = Constrants.url_video; var ext = HttpCore.CreateLinkString(param); url = url + "?" + ext; ws = new WebSocketSharp.WebSocket(url); ws.OnOpen += (a, b) => { print("webscoket opened"); IsConnected = true; }; ws.OnClose += (a, b) => { print("webscoket close"); }; ws.OnMessage += (a, m) => { if (m.IsText) { var result = GetFaceResult(m.Data); if (result.Type == "recognize") { print("recognize"); if (result.Result.Face.Quality > threshold) { if (OnFaceDetect != null) { OnFaceDetect(this.rtstpId, result); } } else { print("低于阈值->" + result.Result.Face.Quality); } } else { print("type=" + result.Type); } } if (m.IsBinary) { print("is binary"); } if (m.IsPing) { print("is ping"); } }; ws.Connect(); }