private string ToJson(DynamicFaceResult content) { JavaScriptSerializer serialize = new JavaScriptSerializer(); var result = serialize.Serialize(content); return(result); }
private void Websocket_OnFaceDetect(string rtspId, DynamicFaceResult face) { lock (this) { print("检测到人脸"); if (clientProxyList.ContainsKey(rtspId)) { ClientData client = clientProxyList[rtspId]; if (client.messageType == queueMessageType) { client.queue.Enqueue(face); } else { var content = GetDynamicResutl(rtspId, face); client.proxy?.onRecv(content); } } } }
private string GetDynamicResutl(string rtspId, DynamicFaceResult face) { var sb = new StringBuilder(); sb.Append("xml".ElementBegin()); sb.Append("type".ElementText("dynamicDetectResult")); sb.Append("rtspId".ElementText(rtspId)); sb.Append("persons".ElementBegin()); sb.Append("person".ElementBegin()); sb.Append("imgData".ElementImage(face.Face.Image)); sb.Append("posX".ElementText(face.Result.Face.Rect.Left.ToString())); sb.Append("posY".ElementText(face.Result.Face.Rect.Top.ToString())); sb.Append("imgWidth".ElementText(face.Result.Face.Rect.Width.ToString())); sb.Append("imgHeight".ElementText(face.Result.Face.Rect.Height.ToString())); sb.Append("quality".ElementText(face.Result.Face.Quality.ToString())); sb.Append("person".ElementEnd()); sb.Append("persons".ElementEnd()); sb.Append("xml".ElementEnd()); var data = sb.ToString(); return(data); }