/// <summary>
        /// Draw a line between two joints in a canvas
        /// </summary>
        /// <param name="canvas">the canvas</param>
        /// <param name="jstart">the joint where to start the line</param>
        /// <param name="jend">the joint where to end the line</param>
        /// <param name="vskeleton">the visual skeleton</param>
        private static void DrawLineBetween(Canvas canvas, Joint jstart, Joint jend, VisualSkeleton vskeleton)
        {
            if (vskeleton.positionMap.ContainsKey(jstart) && vskeleton.positionMap.ContainsKey(jend))
            {
                Line l = new Line();

                l.X1 = vskeleton.positionMap[jstart].X;
                l.Y1 = vskeleton.positionMap[jstart].Y;
                l.X2 = vskeleton.positionMap[jend].X;
                l.Y2 = vskeleton.positionMap[jend].Y;

                if (jstart.TrackingState == JointTrackingState.Inferred &&
                    jend.TrackingState == JointTrackingState.Inferred)
                {
                    l.Stroke = Brushes.Yellow;
                    l.StrokeThickness = 3;
                }
                else if (jstart.TrackingState == JointTrackingState.Tracked &&
                    jend.TrackingState == JointTrackingState.Tracked)
                {
                    l.Stroke = Brushes.Green;
                    l.StrokeThickness = 3;
                }
                else if (jstart.TrackingState == JointTrackingState.NotTracked ||
                    jend.TrackingState == JointTrackingState.NotTracked)
                {
                    l.Stroke = Brushes.Transparent;
                    l.StrokeThickness = 0;
                }

                canvas.Children.Add(l);
            }
        }
Example #2
0
        /// <summary>
        /// Draw a line between two joints in a canvas
        /// </summary>
        /// <param name="canvas">the canvas</param>
        /// <param name="jstart">the joint where to start the line</param>
        /// <param name="jend">the joint where to end the line</param>
        /// <param name="vskeleton">the visual skeleton</param>
        private static void DrawLineBetween(Canvas canvas, Joint jstart, Joint jend, VisualSkeleton vskeleton)
        {
            if (vskeleton.positionMap.ContainsKey(jstart) && vskeleton.positionMap.ContainsKey(jend))
            {
                Line l = new Line();

                l.X1 = vskeleton.positionMap[jstart].X;
                l.Y1 = vskeleton.positionMap[jstart].Y;
                l.X2 = vskeleton.positionMap[jend].X;
                l.Y2 = vskeleton.positionMap[jend].Y;


                if (jstart.TrackingState == JointTrackingState.Inferred &&
                    jend.TrackingState == JointTrackingState.Inferred)
                {
                    l.Stroke          = Brushes.Yellow;
                    l.StrokeThickness = 3;
                }
                else if (jstart.TrackingState == JointTrackingState.Tracked &&
                         jend.TrackingState == JointTrackingState.Tracked)
                {
                    l.Stroke          = Brushes.Green;
                    l.StrokeThickness = 3;
                }
                else if (jstart.TrackingState == JointTrackingState.NotTracked ||
                         jend.TrackingState == JointTrackingState.NotTracked)
                {
                    l.Stroke          = Brushes.Transparent;
                    l.StrokeThickness = 0;
                }

                canvas.Children.Add(l);
            }
        }
        /// <summary>
        /// Draw the skeleton joints
        /// </summary>
        /// <param name="canvas">the canvas where to draw the skeletons</param>
        /// <param name="vskeleton">the visual skeleton</param>
        private static void DrawJoints(Canvas canvas, VisualSkeleton vskeleton)
        {
            foreach (Joint j in vskeleton.skeleton.Joints)
            {
                if (vskeleton.visualMap.ContainsKey(j) && vskeleton.positionMap.ContainsKey(j))
                {
                    Ellipse e = vskeleton.visualMap[j];
                    Point2D pos = vskeleton.positionMap[j];

                    Canvas.SetLeft(e, pos.X);
                    Canvas.SetTop(e, pos.Y);
                    canvas.Children.Add(e);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Draw the skeleton joints
        /// </summary>
        /// <param name="canvas">the canvas where to draw the skeletons</param>
        /// <param name="vskeleton">the visual skeleton</param>
        private static void DrawJoints(Canvas canvas, VisualSkeleton vskeleton)
        {
            foreach (Joint j in vskeleton.skeleton.Joints)
            {
                if (vskeleton.visualMap.ContainsKey(j) && vskeleton.positionMap.ContainsKey(j))
                {
                    Ellipse e   = vskeleton.visualMap[j];
                    Point2D pos = vskeleton.positionMap[j];

                    Canvas.SetLeft(e, pos.X);
                    Canvas.SetTop(e, pos.Y);
                    canvas.Children.Add(e);
                }
            }
        }
        /// <summary>
        /// draw in the canvas the visual skeleton scaled to the canvas size
        /// </summary>
        /// <param name="canvas">the canvas</param>
        /// <param name="skeleton">the visual skeleton</param>
        /// <param name="color">the color of the skeleton</param>
        public static void DrawSkeleton(this Canvas canvas, Skeleton skeleton, Brush color)
        {
            //create the visual skeleton
            VisualSkeleton vskeleton = new VisualSkeleton(skeleton, color);

            //transform the data into the correct space
            foreach (Joint j in skeleton.Joints)
            {
                vskeleton.positionMap.Add(j, j.Get2DPosition(KinectHelper.Instance._sensor, (int)canvas.Width, (int)canvas.Height));
            }

            ///////
            //  Draw the joints
            ///////
            DrawJoints(canvas, vskeleton);

            ///////
            //  Draw the lines
            ///////
            DrawLines(canvas, vskeleton);
        }
Example #6
0
        /// <summary>
        /// draw in the canvas the visual skeleton scaled to the canvas size
        /// </summary>
        /// <param name="canvas">the canvas</param>
        /// <param name="skeleton">the visual skeleton</param>
        /// <param name="color">the color of the skeleton</param>
        public static void DrawSkeleton(this Canvas canvas, Skeleton skeleton, Brush color)
        {
            //create the visual skeleton
            VisualSkeleton vskeleton = new VisualSkeleton(skeleton, color);

            //transform the data into the correct space
            foreach (Joint j in skeleton.Joints)
            {
                vskeleton.positionMap.Add(j, j.Get2DPosition(KinectHelper.Instance._sensor, (int)canvas.Width, (int)canvas.Height));
            }

            ///////
            //  Draw the joints
            ///////
            DrawJoints(canvas, vskeleton);

            ///////
            //  Draw the lines
            ///////
            DrawLines(canvas, vskeleton);
        }
Example #7
0
 /// <summary>
 /// Draw the skeleton lines
 /// </summary>
 /// <param name="canvas">the canvas where to draw the skeletons</param>
 /// <param name="vskeleton">the visual skeleton</param>
 private static void DrawLines(Canvas canvas, VisualSkeleton vskeleton)
 {
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HandLeft], vskeleton.skeleton.Joints[JointType.WristLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.WristLeft], vskeleton.skeleton.Joints[JointType.ElbowLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ElbowLeft], vskeleton.skeleton.Joints[JointType.ShoulderLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderLeft], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HandRight], vskeleton.skeleton.Joints[JointType.WristRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.WristRight], vskeleton.skeleton.Joints[JointType.ElbowRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ElbowRight], vskeleton.skeleton.Joints[JointType.ShoulderRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderRight], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.Head], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton.skeleton.Joints[JointType.Spine], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.Spine], vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton.skeleton.Joints[JointType.HipLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipLeft], vskeleton.skeleton.Joints[JointType.KneeLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.KneeLeft], vskeleton.skeleton.Joints[JointType.AnkleLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.AnkleLeft], vskeleton.skeleton.Joints[JointType.FootLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton.skeleton.Joints[JointType.HipRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipRight], vskeleton.skeleton.Joints[JointType.KneeRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.KneeRight], vskeleton.skeleton.Joints[JointType.AnkleRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.AnkleRight], vskeleton.skeleton.Joints[JointType.FootRight], vskeleton);
 }
 /// <summary>
 /// Draw the skeleton lines
 /// </summary>
 /// <param name="canvas">the canvas where to draw the skeletons</param>
 /// <param name="vskeleton">the visual skeleton</param>
 private static void DrawLines(Canvas canvas, VisualSkeleton vskeleton)
 {
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HandLeft], vskeleton.skeleton.Joints[JointType.WristLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.WristLeft], vskeleton.skeleton.Joints[JointType.ElbowLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ElbowLeft], vskeleton.skeleton.Joints[JointType.ShoulderLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderLeft], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HandRight], vskeleton.skeleton.Joints[JointType.WristRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.WristRight], vskeleton.skeleton.Joints[JointType.ElbowRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ElbowRight], vskeleton.skeleton.Joints[JointType.ShoulderRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderRight], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.Head], vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.ShoulderCenter], vskeleton.skeleton.Joints[JointType.Spine], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.Spine], vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton.skeleton.Joints[JointType.HipLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipLeft], vskeleton.skeleton.Joints[JointType.KneeLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.KneeLeft], vskeleton.skeleton.Joints[JointType.AnkleLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.AnkleLeft], vskeleton.skeleton.Joints[JointType.FootLeft], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipCenter], vskeleton.skeleton.Joints[JointType.HipRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.HipRight], vskeleton.skeleton.Joints[JointType.KneeRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.KneeRight], vskeleton.skeleton.Joints[JointType.AnkleRight], vskeleton);
     DrawLineBetween(canvas, vskeleton.skeleton.Joints[JointType.AnkleRight], vskeleton.skeleton.Joints[JointType.FootRight], vskeleton);
 }