Exemplo n.º 1
0
        public static string Serialize(this List <Skeleton> skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    //ID = skeleton.TrackingID.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Joint scaled = joint.ScaleTo(640, 480);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = scaled.JointType.ToString().ToLower(),
                        X    = scaled.Position.X,
                        Y    = scaled.Position.Y,
                        Z    = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
Exemplo n.º 2
0
        public static string Serialize(this List<Skeleton> skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection { Skeletons = new List<JSONSkeleton>() };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID = skeleton.TrackingId.ToString(),
                    Joints = new List<JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Joint scaled = joint.ScaleTo(640, 480);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = scaled.JointType.ToString().ToLower(),
                        X = scaled.Position.X,
                        Y = scaled.Position.Y,
                        Z = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
                jsonSkeletons.type = "JSONSkeletonCollection";
            }

            return Serialize(jsonSkeletons);
        }
Exemplo n.º 3
0
        public static string Serialize(this List<Skeleton> skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection { Skeletons = new List<JSONSkeleton>() };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID = skeleton.TrackingId.ToString(),
                    Joints = new List<JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    //We only track left and right hand
                    if (joint.JointType != JointType.WristLeft && joint.JointType != JointType.WristRight)
                        continue;

                    Joint scaled = joint.ScaleTo(1000, 1000);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        X = scaled.Position.X,
                        Y = scaled.Position.Y,
                        Z = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return Serialize(jsonSkeletons);
        }
Exemplo n.º 4
0
        public static string Serialize(this Skeleton[] skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection { Skeletons = new List<JSONSkeleton>() };
            
            foreach (var skeleton in skeletons)
            {
                //not getting to here, there's no skeletons in the list..
                //Console.WriteLine("here i am");
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID = skeleton.TrackingId.ToString(),
                    Joints = new List<JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Joint scaled = joint;//.ScaleTo(640, 480);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = scaled.TrackingState.ToString().ToLower(),
                        X = scaled.Position.X,
                        Y = scaled.Position.Y,
                        Z = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return Serialize(jsonSkeletons);
        }
        public static string Serialize(this List<Skeleton> skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection { Skeletons = new List<JSONSkeleton>() };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID = skeleton.TrackingId.ToString(),
                    Joints = new List<JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {

                    //Joint scaled = joint.ScaleTo(1000, 1000);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Label = joint.JointType.ToString(),
                        X = joint.Position.X,
                        Y = joint.Position.Y,
                        Z = joint.Position.Z
                    });

                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return Serialize(jsonSkeletons);
        }
Exemplo n.º 6
0
        public static string Serialize(this Skeleton[] skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                //not getting to here, there's no skeletons in the list..
                //Console.WriteLine("here i am");
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Joint scaled = joint;//.ScaleTo(640, 480);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = scaled.TrackingState.ToString().ToLower(),
                        X    = scaled.Position.X,
                        Y    = scaled.Position.Y,
                        Z    = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
Exemplo n.º 7
0
        public static string Serialize(this List <Body> skeletons, CoordinateMapper mapper, Mode mode)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (Body skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton();
                if (skeleton.IsTracked)
                {
                    jsonSkeleton.command        = "bodyData";
                    jsonSkeleton.trackingID     = skeleton.TrackingId.ToString();
                    jsonSkeleton.Joints         = new List <JSONJoint>();
                    jsonSkeleton.HandLeftState  = skeleton.HandLeftState;
                    jsonSkeleton.HandRightState = skeleton.HandRightState;

                    foreach (var joint in skeleton.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 = point.X,
                            mappedY = point.Y,
                            Z       = joint.Value.Position.Z
                        });
                    }
                    jsonSkeletons.Skeletons.Add(jsonSkeleton);
                }
            }
            return(JsonConvert.SerializeObject(jsonSkeletons));
        }
Exemplo n.º 8
0
        //Serializes an array of Kinect skeletons into an array of JSON skeletons.The Kinect skeletons.The coordinate mapper.Mode (color or depth)
        public static string Serialize(this List <Skeleton> skeletons, CoordinateMapper mapper, Mode mode)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    Point point = new Point();

                    switch (mode)
                    {
                    case Mode.Color:
                        ColorImagePoint colorPoint = mapper.MapSkeletonPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                        point.X = colorPoint.X;
                        point.Y = colorPoint.Y;
                        break;

                    case Mode.Depth:
                        DepthImagePoint depthPoint = mapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution640x480Fps30);
                        point.X = depthPoint.X;
                        point.Y = depthPoint.Y;
                        break;

                    default:
                        break;
                    }

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = joint.JointType.ToString().ToLower(),
                        X    = joint.Position.X,
                        Y    = joint.Position.Y,
                        Z    = joint.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Serializes an array of Kinect skeletons into an array of JSON skeletons.
        /// </summary>
        /// <param name="skeletons">The Kinect skeletons.</param>
        /// <param name="mapper">The coordinate mapper.</param>
        /// <param name="mode">Mode (color or depth).</param>
        /// <returns>A JSON representation of the skeletons.</returns>
        public static string Serialize(this List <Body> skeletons, CoordinateMapper mapper, Mode mode)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints.Values)
                {
                    //switch (mode)
                    //{
                    //    case Mode.Color:

                    //        ColorSpacePoint colorPoint = mapper.MapBodyPointToColorPoint(joint.Position, ColorImageFormat.RgbResolution640x480Fps30);
                    //        point.X = colorPoint.X;
                    //        point.Y = colorPoint.Y;
                    //        break;
                    //        mapper.map
                    //    case Mode.Depth:
                    //        DepthImagePoint depthPoint = mapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution640x480Fps30);
                    //        point.X = depthPoint.X;
                    //        point.Y = depthPoint.Y;
                    //        break;
                    //    default:
                    //        break;
                    //}

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = joint.JointType.ToString(),
                        X    = joint.Position.X,
                        Y    = joint.Position.Y,
                        Z    = joint.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
        public static string Serialize(this List <Skeleton> skeletons)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints)
                {
                    //We only track left and right hand
                    if (joint.JointType != JointType.WristLeft && joint.JointType != JointType.WristRight)
                    {
                        continue;
                    }

                    Joint scaled = joint.ScaleTo(640, 480);

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        X = scaled.Position.X,
                        Y = scaled.Position.Y,
                        Z = scaled.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Serializes an array of Kinect skeletons into an array of JSON skeletons.
        /// </summary>
        /// <param name="skeletons">The Kinect skeletons.</param>
        /// <param name="mapper">The coordinate mapper.</param>
        /// <param name="mode">Mode (color or depth).</param>
        /// <returns>A JSON representation of the skeletons.</returns>
        public static string Serialize(this List <Body> skeletons, CoordinateMapper mapper, CameraMode mode)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>(), type = "skeleton"
            };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                foreach (Joint joint in skeleton.Joints.Values)
                {
                    //Joint currentJoint = new Joint();

                    /*if (joint.JointType != JointType.Head && joint.JointType != JointType.Neck && joint.JointType != JointType.SpineBase
                     *  && joint.JointType != JointType.SpineMid && joint.JointType != JointType.SpineShoulder
                     *  && joint.JointType != JointType.HandRight && joint.JointType != JointType.HandLeft)*/

                    //use if only need to send those joints
                    //if (joint.JointType != JointType.Neck && joint.JointType != JointType.SpineBase
                    //      && joint.JointType != JointType.HandRight && joint.JointType != JointType.HandLeft)
                    //
                    //continue;


                    CameraSpacePoint jointPosition = joint.Position;
                    Point            point         = new Point();

                    switch (mode)
                    {
                    case CameraMode.Color:
                        ColorSpacePoint colorPoint = mapper.MapCameraPointToColorSpace(jointPosition);    //(joint.Position); //, ColorImageFormat.RgbResolution640x480Fps30);
                        point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
                        point.X = Math.Round(point.X, 2);
                        point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
                        point.Y = Math.Round(point.Y, 2);
                        break;

                    case CameraMode.Depth:
                        DepthSpacePoint depthPoint = mapper.MapCameraPointToDepthSpace(joint.Position);    //, DepthSpaceFormat.Resolution640x480Fps30);
                        point.X = float.IsInfinity(depthPoint.X) ? 0 : depthPoint.X;
                        point.Y = float.IsInfinity(depthPoint.Y) ? 0 : depthPoint.Y;
                        break;

                    default:
                        break;
                    }

                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = joint.JointType.ToString(),
                        X    = joint.Position.X,
                        Y    = joint.Position.Y,
                        Z    = joint.Position.Z
                    });
                }

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return(Serialize(jsonSkeletons));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Serializes an array of Kinect skeletons into an array of JSON skeletons.
        /// </summary>
        /// <param name="skeletons">The Kinect skeletons.</param>
        /// <param name="correctionMatrix">Matrix to align the skeleton to world coordinates.</param>
        /// <returns>A JSON representation of the skeletons.</returns>
        public static string Serialize(this List<Body> skeletons, Matrix4x4 correctionMatrix)
        {
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection { Skeletons = new List<JSONSkeleton>() };

            foreach (var skeleton in skeletons)
            {
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID = skeleton.TrackingId.ToString(),
                    Joints = new List<JSONJoint>()
                };

                foreach(KeyValuePair<JointType,Joint> joint in skeleton.Joints)
                //foreach (Joint joint in skeleton.Joints)
                {
                    if (correctionMatrix != null)
                    {
                        Vector3 correctedJoint = Vector3.Transform( new Vector3(joint.Value.Position.X, joint.Value.Position.Y, joint.Value.Position.Z), correctionMatrix);

                        jsonSkeleton.Joints.Add(new JSONJoint
                        {
                            Name = joint.Key.ToString(),
                            X = correctedJoint.X,
                            Y = correctedJoint.Y,
                            Z = correctedJoint.Z
                        });

                    }
                    else
                    {
                        jsonSkeleton.Joints.Add(new JSONJoint
                        {
                            Name = joint.Key.ToString(),
                            X = joint.Value.Position.X,
                            Y = joint.Value.Position.Y,
                            Z = joint.Value.Position.Z
                        });
                    }

                }
                jsonSkeleton.Joints.Add(new JSONJoint
                {
                    Name = "lean",
                    X = skeleton.Lean.X,
                    Y = skeleton.Lean.Y,
                    Z = (skeleton.LeanTrackingState==Microsoft.Kinect.TrackingState.Tracked)?1:0
                });

                int handState = 0;
                if(skeleton.HandLeftState == Microsoft.Kinect.HandState.NotTracked)
                    handState = -1;
                //if(skeleton.HandLeftState == Microsoft.Kinect.HandState.Unknown)
                //    handState = 0;
                if(skeleton.HandLeftState == Microsoft.Kinect.HandState.Open)
                    handState = 1;
                if(skeleton.HandLeftState == Microsoft.Kinect.HandState.Closed)
                    handState = 2;
                if(skeleton.HandLeftState == Microsoft.Kinect.HandState.Lasso)
                    handState = 3;

                jsonSkeleton.Joints.Add(new JSONJoint
                {
                    Name = "HandStateLeft",
                    X = (skeleton.HandLeftConfidence==Microsoft.Kinect.TrackingConfidence.High) ? 1 : 0,
                    Y = handState,
                    Z = 0
                });

                handState = 0;
                if (skeleton.HandRightState== Microsoft.Kinect.HandState.NotTracked)
                    handState = -1;
                //if(skeleton.HandRightState == Microsoft.Kinect.HandState.Unknown)
                //    handState = 0;
                if (skeleton.HandRightState == Microsoft.Kinect.HandState.Open)
                    handState = 1;
                if (skeleton.HandRightState == Microsoft.Kinect.HandState.Closed)
                    handState = 2;
                if (skeleton.HandRightState == Microsoft.Kinect.HandState.Lasso)
                    handState = 3;

                jsonSkeleton.Joints.Add(new JSONJoint
                {
                    Name = "HandStateRight",
                    X = (skeleton.HandRightConfidence == Microsoft.Kinect.TrackingConfidence.High) ? 1 : 0,
                    Y = handState,
                    Z = 0
                });

                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            return Serialize(jsonSkeletons);
        }
        /**
         * Serializes an array of Kinect skeletons into an array of JSON skeletons.
         * @method Serialize
         * @param {List<Body>} skeletons
         * @param {CoordinateMapper} mapper
         * @param {Mode} mode
         * @return {String} A JSON representation of the skeletons
         */
        public static string Serialize(this List <Body> skeletons, CoordinateMapper mapper, Mode mode)
        {
            // instantiate the skeleton JSON object
            JSONSkeletonCollection jsonSkeletons = new JSONSkeletonCollection {
                Skeletons = new List <JSONSkeleton>()
            };


            // For each skeleton set in the camera view
            foreach (var skeleton in skeletons)
            {
                // set skeleton inside of JSON data
                JSONSkeleton jsonSkeleton = new JSONSkeleton
                {
                    ID     = skeleton.TrackingId.ToString(),
                    Joints = new List <JSONJoint>()
                };

                // loop through each joint in the skeleton
                for (int i = 0; i < skeleton.Joints.Count; i++)
                {
                    var   joint = skeleton.Joints.ElementAt(i);
                    Point point = new Point();

                    // depending on which mode the user is in, system will map the points to the frame spacce
                    switch (mode)
                    {
                    case Mode.Color:
                        ColorSpacePoint colorPoint = new ColorSpacePoint();
                        colorPoint = mapper.MapCameraPointToColorSpace(joint.Value.Position);
                        point.X    = colorPoint.X;
                        point.Y    = colorPoint.Y;
                        break;

                    case Mode.Depth:
                        DepthSpacePoint depthPoint = new DepthSpacePoint();
                        depthPoint = mapper.MapCameraPointToDepthSpace(joint.Value.Position);
                        point.X    = depthPoint.X;
                        point.Y    = depthPoint.Y;
                        break;

                    default:
                        break;
                    }

                    // add the joints to the json object
                    jsonSkeleton.Joints.Add(new JSONJoint
                    {
                        Name = joint.Key.ToString().ToLower(),
                        X    = point.X,
                        Y    = point.Y,
                        Z    = joint.Value.Position.Z
                    });
                }

                // add the completed skeleton to the json object
                jsonSkeletons.Skeletons.Add(jsonSkeleton);
            }

            // return the json string
            return(Serialize(jsonSkeletons));
        }