/// <summary> /// Serializes an array of Kinect bodies into an array of JSON skeletons. /// </summary> /// <param name="bodies">The Kinect bodies.</param> /// <returns>A JSON representation of the bodies.</returns> public static string Serialize(this Body[] bodies) { JSONBodyCollection jsonBodies = new JSONBodyCollection { Bodies = new List <JSONBody>() }; //Serializes all bodies in the body collection, regardless of content foreach (Body body in bodies) { JSONBody jsonBody = new JSONBody { ID = body.TrackingId.ToString(), Joints = new List <JSONJoint>(), LState = (int)body.HandLeftState, RState = (int)body.HandRightState }; //Add all joints, again, regardless of content foreach (KeyValuePair <JointType, Joint> joint in body.Joints) { jsonBody.Joints.Add(new JSONJoint { Name = joint.Key.ToString().ToLower(), X = joint.Value.Position.X, Y = joint.Value.Position.Y, Z = joint.Value.Position.Z }); } //Bodies is the name of the body array contained in jsonBodies. //Here the jsonBody is added to the array. jsonBodies.Bodies.Add(jsonBody); } return(Serialize(jsonBodies)); }
/// <summary> /// Serializes an array of Kinect bodies into an array of JSON skeletons. /// </summary> /// <param name="bodies">The Kinect bodies.</param> /// <returns>A JSON representation of the bodies.</returns> public static string Serialize(this Body[] bodies) { JSONBodyCollection jsonBodies = new JSONBodyCollection { Bodies = new List<JSONBody>() }; //Serializes all bodies in the body collection, regardless of content foreach (Body body in bodies) { JSONBody jsonBody = new JSONBody { ID = body.TrackingId.ToString(), Joints = new List<JSONJoint>(), LState = (int)body.HandLeftState, RState = (int)body.HandRightState }; //Add all joints, again, regardless of content foreach (KeyValuePair<JointType, Joint> joint in body.Joints) { jsonBody.Joints.Add(new JSONJoint { Name = joint.Key.ToString().ToLower(), X = joint.Value.Position.X, Y = joint.Value.Position.Y, Z = joint.Value.Position.Z }); } //Bodies is the name of the body array contained in jsonBodies. //Here the jsonBody is added to the array. jsonBodies.Bodies.Add(jsonBody); } return Serialize(jsonBodies); }
/// <summary> /// Serializes an array of Kinect bodies into an array of JSON skeletons. /// </summary> /// <param name="bodies">The Kinect bodies.</param> /// <returns>A JSON representation of the bodies.</returns> public static string Serialize(this Skeleton[] bodies) { JSONBodyCollection jsonBodies = new JSONBodyCollection { Bodies = new List <JSONBody>() }; //Serializes all bodies in the body collection, regardless of content foreach (Skeleton body in bodies) { JSONBody jsonBody = new JSONBody { ID = body.TrackingId.ToString(), Joints = new List <JSONJoint>(), }; //Add all joints, again, regardless of content foreach (Joint joint in body.Joints) { jsonBody.Joints.Add(new JSONJoint { Name = joint.JointType.ToString().ToLower(), X = joint.Position.X, Y = joint.Position.Y, Z = joint.Position.Z }); } //Bodies is the name of the body array contained in jsonBodies. //Here the jsonBody is added to the array. jsonBodies.Bodies.Add(jsonBody); } return(Serialize(jsonBodies)); }
public void Stop([FromBody] JSONBody json) { if (json.Id > 0 && json.Id < Repository.GetNextNumber()) { var report = Repository.Get(json.Id); report.Stop(); } }
/// <summary> /// Adds or changes a ContainerLevel object which consists of an ID and a fill level which can be retrieved from the json found as a parameter /// </summary> /// <param name="jsonBody">body containing json, retrieved from a incomming post request.</param> public IHttpActionResult Post([FromBody] JSONBody jsonBody) { try { if (jsonBody != null) { if (ModelState.IsValid) { ContainerLevel cl = new ContainerLevel(jsonBody.dev_id, jsonBody.payload_fields.fill_level); service.SetFillLevel(cl); return(Ok()); } else { return(BadRequest(ModelState)); } } return(BadRequest(ModelState)); } catch (ArgumentException e) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unfortunate son..."))); } }
public static string SerializeBodies(BodyEventModel bodyEvent) { Value jsonValue = new Value { Bodies = new List <JSONBody>() }; foreach (var body in bodyEvent.Bodies) { JSONBody jsonBody = new JSONBody { ID = body.TrackingId.ToString(), Joints = new List <JSONJoint>() }; foreach (var bodyJoint in body.Joints) { Joint joint = bodyJoint.Value; jsonBody.Joints.Add(new JSONJoint { Name = joint.JointType.ToString().ToLower(), X = joint.Position.X, Y = joint.Position.Y, Z = joint.Position.Z }); } jsonValue.Bodies.Add(jsonBody); } JSONEvent jsonEvent = new JSONEvent { Id = bodyEvent.Id, Event = bodyEvent.Event, Ts = bodyEvent.Timestamp, Value = jsonValue }; return(Serialize(jsonEvent)); }
/// <summary> /// Serializes an array of Kinect skeletons into an array of JSON skeletons. /// </summary> /// <param name="bodies">The Kinect bodies.</param> /// <param name="mapper">The coordinate mapper.</param> /// <param name="faceFrameResults">The kinect faces.</param> /// <returns>A JSON representation of the skeletons.</returns> public static string Serialize(this List <Body> bodies, CoordinateMapper mapper, FaceFrameResult[] faceFrameResults) { JSONBodyCollection jsonBodies = new JSONBodyCollection { Bodies = new List <JSONBody>() }; foreach (Body body in bodies) { JSONBody jsonBody = new JSONBody { ID = body.TrackingId.ToString(), Joints = new List <JSONJoint>() }; foreach (KeyValuePair <JointType, Joint> jointpair in body.Joints) { Joint joint = jointpair.Value; DepthSpacePoint depthPoint = mapper.MapCameraPointToDepthSpace(joint.Position); jsonBody.Joints.Add(new JSONJoint { Name = joint.JointType.ToString().ToLower(), MapX = depthPoint.X, MapY = depthPoint.Y, MapZ = joint.Position.Z, X = body.Joints[joint.JointType].Position.X, Y = body.Joints[joint.JointType].Position.Y, Z = body.Joints[joint.JointType].Position.Z, // absolute Quaternion_W = body.JointOrientations[joint.JointType].Orientation.W, Quaternion_X = body.JointOrientations[joint.JointType].Orientation.X, Quaternion_Y = body.JointOrientations[joint.JointType].Orientation.Y, Quaternion_Z = body.JointOrientations[joint.JointType].Orientation.Z, IsTracked = (body.Joints[joint.JointType].TrackingState == TrackingState.Tracked) }); } // faceとbodyの関連付け FaceFrameResult associatedFace = null; foreach (var f in faceFrameResults) { if (f == null) { continue; } if (f.TrackingId == body.TrackingId) { associatedFace = f; break; } } if (associatedFace != null) { jsonBody.Face = new JSONFace { Quaternion_W = associatedFace.FaceRotationQuaternion.W, Quaternion_X = associatedFace.FaceRotationQuaternion.X, Quaternion_Y = associatedFace.FaceRotationQuaternion.Y, Quaternion_Z = associatedFace.FaceRotationQuaternion.Z, MouthOpened = (associatedFace.FaceProperties[FaceProperty.MouthOpen] == DetectionResult.Maybe || associatedFace.FaceProperties[FaceProperty.MouthOpen] == DetectionResult.Yes), MouthMoved = (associatedFace.FaceProperties[FaceProperty.MouthMoved] == DetectionResult.Maybe || associatedFace.FaceProperties[FaceProperty.MouthMoved] == DetectionResult.Yes), LeftEyeClosed = (associatedFace.FaceProperties[FaceProperty.LeftEyeClosed] == DetectionResult.Maybe || associatedFace.FaceProperties[FaceProperty.LeftEyeClosed] == DetectionResult.Yes), RightEyeClosed = (associatedFace.FaceProperties[FaceProperty.RightEyeClosed] == DetectionResult.Maybe || associatedFace.FaceProperties[FaceProperty.RightEyeClosed] == DetectionResult.Yes) }; } // 立っている, 座っている, 寝ている の判定 int posture = PostureDetector.Detect(body); jsonBody.Posture = posture; jsonBodies.Bodies.Add(jsonBody); } return(Serialize(jsonBodies)); }