/// <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 JSONBodySerialize() { jsonSkeletons = new JSONBodyCollection { Bodies = new List <JSONBody>() }; }
/// <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)); }
public static string Serialize(this List <Body> bodies, KinectSensor sensor, CoordinateMapper mapper, Mode mode) { List <GestureDetector> gestureDetectorList = new List <GestureDetector>(); // create gesture detector for each body int bodyCount = bodies.Count; //for (int i = 0; i < bodyCount; ++i) //{ // GestureResult result = new GestureResult(i, false, false, 0.0f); // String appCurrentPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); // String database = Path.Combine(appCurrentPath,"Database\\WaveHand.gbd"); // //Console.WriteLine(database); // GestureDetector detector = new GestureDetector(sensor, result, database, "Wave_Left"); // gestureDetectorList.Add(detector); //} JSONBodyCollection jsonSkeletons = new JSONBodyCollection { Bodies = new List <JSONBody>() }; jsonSkeletons.command = "bodyData"; for (int i = 0; i < bodyCount; ++i) { JSONBody jsonSkeleton = new JSONBody(); if (bodies[i].IsTracked) { ulong trackingId = bodies[i].TrackingId; //if (trackingId != gestureDetectorList[i].TrackingId) //{ // gestureDetectorList[i].TrackingId = trackingId; // gestureDetectorList[i].IsPaused = (trackingId == 0); //} jsonSkeleton.trackingID = bodies[i].TrackingId.ToString(); jsonSkeleton.Joints = new List <JSONJoint>(); jsonSkeleton.HandLeftState = bodies[i].HandLeftState; jsonSkeleton.HandRightState = bodies[i].HandRightState; //jsonSkeleton.Gestures = new List<JSONGesture>(); //if (gestureDetectorList[i].GestureResult.Detected) //{ // jsonSkeleton.Gestures.Add(new JSONGesture // { // Name = gestureDetectorList[i].gestureName, // Confidence = gestureDetectorList[i].GestureResult.Confidence // }); //} foreach (var joint in bodies[i].Joints) { Point point = new Point(); switch (mode) { case Mode.Color: ColorSpacePoint colorPoint = mapper.MapCameraPointToColorSpace(joint.Value.Position); point.X = colorPoint.X; point.Y = colorPoint.Y; break; case Mode.Depth: DepthSpacePoint depthPoint = mapper.MapCameraPointToDepthSpace(joint.Value.Position); point.X = depthPoint.X; point.Y = depthPoint.Y; break; default: break; } jsonSkeleton.Joints.Add(new JSONJoint { Name = joint.Key.ToString().ToLower(), X = joint.Value.Position.X, Y = joint.Value.Position.Y, mappedX = Double.IsInfinity(point.X) ? -1 : point.X, mappedY = Double.IsInfinity(point.X) ? -1 : point.Y, Z = joint.Value.Position.Z }); } jsonSkeletons.Bodies.Add(jsonSkeleton); } } return(JsonConvert.SerializeObject(jsonSkeletons)); }