void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.skeletonCanvas1 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;

            case 2:
                this.skeletonCanvas2 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;

            case 3:
                this.skeletonCanvas3 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;

            case 4:
                this.skeletonCanvas4 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;

            case 5:
                this.skeletonCanvas5 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;

            case 6:
                this.skeletonCanvas6 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 2
0
        private void adjustBoneRendering(JointCollection joints, KinectSkeleton skeletonCanvas, DepthImageFrame depthFrame, int canvasChildIndex, params JointType[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);

            for (int i = 0; i < ids.Length; ++i)
            {
                if (joints[ids[i]].TrackingState != JointTrackingState.NotTracked)
                {
                    points.Add(getJoint2DLocation(joints[ids[i]], skeletonCanvas, depthFrame));
                }
            }
            Polyline polyline = (Polyline)skeletonCanvas.Children[canvasChildIndex];

            polyline.Points = points;
            switch (joints[ids[ids.Length - 1]].TrackingState)
            {
            case JointTrackingState.Tracked:
                polyline.Stroke = Brushes.Green;
                break;

            case JointTrackingState.Inferred:
                polyline.Stroke = Brushes.Yellow;
                break;

            case JointTrackingState.NotTracked:
                //no rendering
                break;
            }
        }
Esempio n. 3
0
        private void KinectSkeletonViewer_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Build a set of Skeletons, and bind each of their control properties to those
            // exposed on this class so that changes are propagated.
            for (int i = 0; i < SkeletonCount; i++)
            {
                var skeletonCanvas = new KinectSkeleton();
                skeletonCanvas.ClipToBounds = true;

                var showBonesBinding = new Binding("ShowBones");
                showBonesBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowBonesProperty, showBonesBinding);

                var showJointsBinding = new Binding("ShowJoints");
                showJointsBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowJointsProperty, showJointsBinding);

                var showCenterBinding = new Binding("ShowCenter");
                showCenterBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowCenterProperty, showCenterBinding);

                this.skeletonCanvases.Add(skeletonCanvas);
                this.jointMappings.Add(new Dictionary <JointType, JointMapping>());
                this.SkeletonCanvasPanel.Children.Add(skeletonCanvas);
            }
        }
Esempio n. 4
0
        private void adjustLocationOfJoints(Skeleton skeletonData, KinectSkeleton skeletonCanvas, DepthImageFrame depthFrame)
        {
            int jointIndex = 0;

            foreach (Joint joint in skeletonData.Joints)
            {
                Point jointPos  = getJoint2DLocation(joint, skeletonCanvas, depthFrame);
                Line  jointLine = (Line)skeletonCanvas.Children[7 + jointIndex++]; // 7 - is the first Line element in the skeletonCanvas.
                jointLine.X1 = jointPos.X - JointAdjustment;
                jointLine.X2 = jointLine.X1 + JointWidth;
                jointLine.Y1 = jointLine.Y2 = jointPos.Y;
                switch (joint.TrackingState)
                {
                case JointTrackingState.Tracked:
                    jointLine.Stroke = Brushes.Green;
                    break;

                case JointTrackingState.Inferred:
                    jointLine.Stroke = Brushes.Yellow;
                    break;

                case JointTrackingState.NotTracked:
                    jointLine.Stroke = Brushes.Red;
                    break;
                }
            }
        }
Esempio n. 5
0
 private void adjustLocationOfBones(Skeleton skeletonData, KinectSkeleton skeletonCanvas, DepthImageFrame depthFrame)
 {
     //the 3rd param are the child id of the bone PolyLines in skeletonCanvas.
     //Draw Core Bones
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 0, JointType.Head, JointType.ShoulderCenter, JointType.Spine, JointType.HipCenter);
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 1, JointType.HipLeft, JointType.HipCenter, JointType.HipRight);
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 2, JointType.ShoulderLeft, JointType.ShoulderCenter, JointType.ShoulderRight);
     //Draw Arms
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 3, JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft);
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 4, JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight);
     //Draw Legs
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 5, JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft);
     adjustBoneRendering(skeletonData.Joints, skeletonCanvas, depthFrame, 6, JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight);
 }
Esempio n. 6
0
        private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            // Have we already been "shut down" by the user of this viewer,
            // or has the SkeletonStream been disabled since this event was posted?
            if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled)
            {
                return;
            }
            // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  0  ");
            bool haveSkeletonData = false;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                //   File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  1  ");
                if (skeletonFrame != null)
                {
                    if (this.skeletonCanvases == null)
                    {
                        // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  2  ");
                        this.CreateListOfSkeletonCanvases();
                    }

                    if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
                    {
                        this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        //  File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  3  ");
                    }

                    skeletonFrame.CopySkeletonDataTo(this.skeletonData);

                    haveSkeletonData = true;
                }
            }


            if (haveSkeletonData)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    if (depthImageFrame != null)
                    {
                        // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  4  ");
                        int trackedSkeletons = 0;
                        foreach (Skeleton skeleton in this.skeletonData)
                        {
                            if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                //   File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt","Tracked");
                            }
                            else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", trackedSkeletons.ToString() + "  10  ");
                            }
                            else if (skeleton.TrackingState == SkeletonTrackingState.NotTracked)
                            {
                                //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "Nottrack");
                            }
                            Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons];
                            jointMapping.Clear();

                            KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++];
                            skeletonCanvas.ShowBones  = this.ShowBones;
                            skeletonCanvas.ShowJoints = this.ShowJoints;
                            skeletonCanvas.ShowCenter = this.ShowCenter;
                            int      temp       = 0;
                            int      count1     = 0;
                            float [] data_joint = new float [42];
                            // Transform the data into the correct space
                            // For each joint, we determine the exact X/Y coordinates for the target view
                            foreach (Joint joint in skeleton.Joints)
                            {
                                // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  6  ");
                                Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);
                                jointMapping[joint.JointType] = new JointMapping
                                {
                                    Joint       = joint,
                                    MappedPoint = mappedPoint
                                };

                                Joint asd = joint;
                                if (asd.TrackingState == JointTrackingState.Tracked && asd != skeleton.Joints[JointType.FootRight] && asd != skeleton.Joints[JointType.FootLeft] && asd != skeleton.Joints[JointType.KneeLeft] && asd != skeleton.Joints[JointType.AnkleLeft] && asd != skeleton.Joints[JointType.KneeRight] && asd != skeleton.Joints[JointType.AnkleRight])
                                {
                                    // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", " j "+ j.ToString());
                                    temp++;
                                    //  File.AppendAllText(path,p.ToString()+" "+q.ToString()+" " +" ");
                                    data_joint[count1] = asd.Position.X;
                                    count1++;
                                    data_joint[count1] = asd.Position.Y;
                                    count1++;
                                    data_joint[count1] = asd.Position.Z;
                                    count1++;
                                    //string text;
                                    // text =(asd.Position.Z).ToString()+" ";
                                    // WriteAllText creates a file, writes the specified string to the file,
                                    // and then closes the file.    You do NOT need to call Flush() or Close().
                                    //  System.IO.File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", text);
                                    // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt",asd.Position.X.ToString() + "  " + asd.Position.Y.ToString() + "  " + asd.Position.Z.ToString());
                                    //  Console.WriteLine(asd.Position.X.ToString() + asd.Position.Y.ToString() + asd.Position.Z.ToString());
                                }

                                /* else if(j!=1 )
                                 * {
                                 *  // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "NONE track"+ count.ToString() +  Environment.NewLine);
                                 *
                                 *   //File.AppendAllText(@"C:\Users\pk1601cs33\helll.csv", " -1 -1 -1 ");
                                 *   j = 0;
                                 * }*/
                            }

                            if (temp == 14)
                            {
                                useless++;

                                /*string path=@"C:\Users\pk1601cs33\exer.csv";
                                 *   StringBuilder sbOutput = new StringBuilder();
                                 * for(int j =0 ; j< 42 ; j++)
                                 * {
                                 *   if(j==0)
                                 *   File.AppendAllText(path,data_joint[j].ToString());
                                 *   else
                                 *       File.AppendAllText(path," "+ data_joint[j].ToString());
                                 *
                                 * }
                                 * File.AppendAllText(path, Environment.NewLine);
                                 */
                                if (useless >= 10)
                                {
                                    useless = 0;
                                    Insert(data_joint);
                                }

                                temp = 0;
                            }

                            //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", Environment.NewLine + count.ToString() + "  " +Environment.NewLine);

                            /*     if (i == 1)
                             *   {
                             *      File.AppendAllText(@"C:\Users\pk1601cs33\not_valid.csv",Environment.NewLine);
                             *       i = 0;
                             *   }
                             */

                            //  button1_Click(null, null);
                            // Look up the center point
                            Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position);

                            // Scale the skeleton thickness
                            // 1.0 is the desired size at 640 width
                            double scale = this.RenderSize.Width / 640;

                            skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale);
                        }

                        if (ImageType == ImageType.Depth)
                        {
                            this.ChooseTrackedSkeletons(this.skeletonData);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.skeletonCanvas1 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     case 2:
     this.skeletonCanvas2 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     case 3:
     this.skeletonCanvas3 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     case 4:
     this.skeletonCanvas4 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     case 5:
     this.skeletonCanvas5 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     case 6:
     this.skeletonCanvas6 = ((Microsoft.Samples.Kinect.WpfViewers.KinectSkeleton)(target));
     return;
     }
     this._contentLoaded = true;
 }
        private void KinectSkeletonViewer_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Build a set of Skeletons, and bind each of their control properties to those
            // exposed on this class so that changes are propagated.
            for (int i = 0; i < SkeletonCount; i++)
            {
                var skeletonCanvas = new KinectSkeleton();
                skeletonCanvas.ClipToBounds = true;

                var showBonesBinding = new Binding("ShowBones");
                showBonesBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowBonesProperty, showBonesBinding);

                var showJointsBinding = new Binding("ShowJoints");
                showJointsBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowJointsProperty, showJointsBinding);

                var showCenterBinding = new Binding("ShowCenter");
                showCenterBinding.Source = this;
                skeletonCanvas.SetBinding(KinectSkeleton.ShowCenterProperty, showCenterBinding);

                this.skeletonCanvases.Add(skeletonCanvas);
                this.jointMappings.Add(new Dictionary<JointType, JointMapping>());
                this.SkeletonCanvasPanel.Children.Add(skeletonCanvas);
            }
        }
        private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            // Have we already been "shut down" by the user of this viewer,
            // or has the SkeletonStream been disabled since this event was posted?
            if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled)
            {
                return;
            }

            bool haveSkeletonData = false;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    if (this.skeletonCanvases == null)
                    {
                        this.CreateListOfSkeletonCanvases();
                    }

                    if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
                    {
                        this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    }

                    skeletonFrame.CopySkeletonDataTo(this.skeletonData);

                    haveSkeletonData = true;
                }
            }

            if (haveSkeletonData)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    if (depthImageFrame != null)
                    {
                        int trackedSkeletons = 0;

                        foreach (Skeleton skeleton in this.skeletonData)
                        {
                            Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons];
                            jointMapping.Clear();

                            KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++];
                            skeletonCanvas.ShowBones  = this.ShowBones;
                            skeletonCanvas.ShowJoints = this.ShowJoints;
                            skeletonCanvas.ShowCenter = this.ShowCenter;

                            // ***PIAD
                            if (this.enregistrement && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && !firstTracked)
                            {
                                firstTracked        = true;
                                decompte            = DateTime.Now.AddSeconds(5);
                                enregistrementSquel = new Dictionary <int, Dictionary <JointType, SkeletonPoint> >();
                                nb_iterations       = 1;
                            }

                            if (firstTracked && decompte > DateTime.Now)
                            {
                                this.labelDecompte.Content = (decompte - DateTime.Now).Seconds;
                            }

                            //if (this.enregistrement && firstTracked && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && decompte <= DateTime.Now)
                            //{
                            //    this.labelDecompte.Content = "Enregistrement en cours...";
                            //    //System.Console.WriteLine(skeleton.Joints[JointType.Head].Position.X);
                            //    //enregistrementSquel.Add(skeleton);
                            //}
                            // PIAD***

                            // Transform the data into the correct space
                            // For each joint, we determine the exact X/Y coordinates for the target view
                            Dictionary <JointType, SkeletonPoint> temp = new Dictionary <JointType, SkeletonPoint>();
                            foreach (Joint joint in skeleton.Joints)
                            {
                                temp.Add(joint.JointType, joint.Position);

                                Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);
                                jointMapping[joint.JointType] = new JointMapping
                                {
                                    Joint       = joint,
                                    MappedPoint = mappedPoint
                                };
                            }

                            if (this.enregistrement && firstTracked && skeleton.TrackingState.Equals(SkeletonTrackingState.Tracked) && decompte <= DateTime.Now)
                            {
                                this.labelDecompte.Content = "Enregistrement en cours...";
                                enregistrementSquel.Add(nb_iterations, temp);
                                nb_iterations++;
                                //System.Console.WriteLine(skeleton.Joints[JointType.Head].Position.X);
                                //enregistrementSquel.Add(skeleton);
                            }

                            // Look up the center point
                            Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position);

                            // Scale the skeleton thickness
                            // 1.0 is the desired size at 640 width
                            double scale = this.RenderSize.Width / 640;

                            skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale);
                        }

                        if (ImageType == ImageType.Depth)
                        {
                            this.ChooseTrackedSkeletons(this.skeletonData);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private void _Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            // Have we already been "shut down" by the user of this viewer?
            if (this.Kinect == null)
            {
                return;
            }

            bool haveSkeletonData = false;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    if (skeletonCanvases == null)
                    {
                        CreateListOfSkeletonCanvases();
                    }

                    if ((skeletonData == null) || (skeletonData.Length != skeletonFrame.SkeletonArrayLength))
                    {
                        skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    }

                    skeletonFrame.CopySkeletonDataTo(skeletonData);

                    haveSkeletonData = true;
                }
            }

            if (haveSkeletonData)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    if (depthImageFrame != null)
                    {
                        int trackedSkeletons = 0;

                        foreach (Skeleton skeleton in skeletonData)
                        {
                            KinectSkeleton skeletonCanvas = skeletonCanvases[trackedSkeletons++];

                            switch (skeleton.TrackingState)
                            {
                            case SkeletonTrackingState.Tracked:
                                skeletonCanvas.ShowCenter = false;
                                if (skeletonCanvases != null)
                                {
                                    skeletonCanvas.Visibility = ShowJoints || ShowBones
                                                                        ? Visibility.Visible
                                                                        : Visibility.Hidden;
                                    if (ShowBones)
                                    {
                                        adjustLocationOfBones(skeleton, skeletonCanvas, depthImageFrame);
                                    }
                                    if (ShowJoints)
                                    {
                                        adjustLocationOfJoints(skeleton, skeletonCanvas, depthImageFrame);
                                    }
                                }
                                break;

                            case SkeletonTrackingState.PositionOnly:
                                skeletonCanvas.ShowCenter  = true;
                                skeletonCanvas.Visibility  = ShowCenter ? Visibility.Visible : Visibility.Hidden;
                                skeletonCanvas.CenterPoint = getPosition2DLocation(skeleton.Position, skeletonCanvas, depthImageFrame);
                                break;

                            default:
                                //when people leave the scene, hide their skeletons
                                skeletonCanvas.Visibility = Visibility.Hidden;
                                break;
                            }
                        }

                        //when people leave the scene, hide their skeleton.
                        switch (trackedSkeletons)
                        {
                        case 0:
                            skeletonCanvas1.Visibility = System.Windows.Visibility.Hidden;
                            skeletonCanvas2.Visibility = System.Windows.Visibility.Hidden;
                            break;

                        case 1:
                            skeletonCanvas2.Visibility = System.Windows.Visibility.Hidden;
                            break;
                        }

                        if (ImageType == ImageType.Depth)
                        {
                            ChooseTrackedSkeletons(skeletonData);
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            // Have we already been "shut down" by the user of this viewer,
            // or has the SkeletonStream been disabled since this event was posted?
            if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled)
            {
                return;
            }
            // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  0  ");
            bool haveSkeletonData = false;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                //   File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  1  ");
                if (skeletonFrame != null)
                {
                    if (this.skeletonCanvases == null)
                    {
                        // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  2  ");
                        this.CreateListOfSkeletonCanvases();
                    }

                    if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
                    {
                        this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        //  File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  3  ");
                    }

                    skeletonFrame.CopySkeletonDataTo(this.skeletonData);

                    haveSkeletonData = true;
                }
            }

            if (haveSkeletonData)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    if (depthImageFrame != null)
                    {
                        // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "  4  ");
                        int trackedSkeletons = 0;
                        foreach (Skeleton skeleton in this.skeletonData)
                        {
                            if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                //   File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt","Tracked");
                            }
                            else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                // File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", trackedSkeletons.ToString() + "  10  ");
                            }
                            else if (skeleton.TrackingState == SkeletonTrackingState.NotTracked)
                            {
                                //File.AppendAllText(@"C:\Users\pk1601cs33\hell.txt", "Nottrack");
                            }
                            Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons];
                            jointMapping.Clear();

                            KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++];
                            skeletonCanvas.ShowBones  = this.ShowBones;
                            skeletonCanvas.ShowJoints = this.ShowJoints;
                            skeletonCanvas.ShowCenter = this.ShowCenter;

                            foreach (Joint joint in skeleton.Joints)
                            {
                                Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);
                                jointMapping[joint.JointType] = new JointMapping
                                {
                                    Joint       = joint,
                                    MappedPoint = mappedPoint
                                };

                                Joint asd = joint;
                                if (asd.TrackingState == JointTrackingState.Tracked)
                                {
                                    Vector3D elbowl       = new Vector3D(skeleton.Joints[JointType.ElbowLeft].Position.X, skeleton.Joints[JointType.ElbowLeft].Position.Y, skeleton.Joints[JointType.ElbowLeft].Position.Z);
                                    Vector3D WristLeft    = new Vector3D(skeleton.Joints[JointType.WristLeft].Position.X, skeleton.Joints[JointType.WristLeft].Position.Y, skeleton.Joints[JointType.WristLeft].Position.Z);
                                    Vector3D ShoulderLeft = new Vector3D(skeleton.Joints[JointType.ShoulderLeft].Position.X, skeleton.Joints[JointType.ShoulderLeft].Position.Y, skeleton.Joints[JointType.ShoulderLeft].Position.Z);

                                    Vector3D Head = new Vector3D(skeleton.Joints[JointType.ShoulderCenter].Position.X, skeleton.Joints[JointType.ShoulderCenter].Position.Y, skeleton.Joints[JointType.ShoulderCenter].Position.Z);
                                    Vector3D Neck = new Vector3D(skeleton.Joints[JointType.Spine].Position.X, skeleton.Joints[JointType.Spine].Position.Y, skeleton.Joints[JointType.Spine].Position.Z);

                                    //for two hand
                                    Vector3D shoulderright = new Vector3D(skeleton.Joints[JointType.ShoulderRight].Position.X, skeleton.Joints[JointType.ShoulderRight].Position.Y, skeleton.Joints[JointType.ShoulderRight].Position.Z);
                                    Vector3D elbowright    = new Vector3D(skeleton.Joints[JointType.ElbowRight].Position.X, skeleton.Joints[JointType.ElbowRight].Position.Y, skeleton.Joints[JointType.ElbowRight].Position.Z);
                                    //vector for high knees

                                    Vector3D ankleleft = new Vector3D(skeleton.Joints[JointType.AnkleLeft].Position.X, skeleton.Joints[JointType.AnkleLeft].Position.Y, skeleton.Joints[JointType.AnkleLeft].Position.Z);
                                    Vector3D kneeleft  = new Vector3D(skeleton.Joints[JointType.KneeLeft].Position.X, skeleton.Joints[JointType.KneeLeft].Position.Y, skeleton.Joints[JointType.KneeLeft].Position.Z);
                                    Vector3D hipleft   = new Vector3D(skeleton.Joints[JointType.HipLeft].Position.X, skeleton.Joints[JointType.HipLeft].Position.Y, skeleton.Joints[JointType.HipLeft].Position.Z);
                                    //Vector3D SpineShoulder = new Vector3D(skeleton.Joints[JointType.SpineShoulder].Position.X, skeleton.Joints[JointType.SpineShoulder].Position.Y, skeleton.Joints[JointType.SpineShoulder].Position.Z);
                                    LeftElbowAngle = AngleBetweenTwoVectors(elbowl - ShoulderLeft, elbowl - WristLeft);
                                    rotationAngle  = AngleBetweenTwoVectors(elbowl - ShoulderLeft, Neck - Head);
                                    rottwohand     = AngleBetweenTwoVectors(kneeleft - ankleleft, kneeleft - hipleft);
                                    footrot        = AngleBetweenTwoVectors(ShoulderLeft - elbowl, shoulderright - elbowright);

                                    if (footrot >= 0 && footrot <= 100)
                                    {
                                        if (tempcount4 == 0)
                                        {
                                            countnumber4++;
                                        }

                                        tempcount4 = 1;
                                    }

                                    else
                                    {
                                        if (tempcount4 == 1)
                                        {
                                            // countnumber3++;
                                        }

                                        tempcount4 = 0;
                                    }
                                    if (rottwohand >= 0 && rottwohand <= 120)
                                    {
                                        if (tempcount3 == 0)
                                        {
                                            countnumber3++;
                                        }

                                        tempcount3 = 1;
                                    }
                                    else
                                    {
                                        if (tempcount3 == 1)
                                        {
                                            // countnumber3++;
                                        }

                                        tempcount3 = 0;
                                    }


                                    if (LeftElbowAngle >= 0 && LeftElbowAngle <= 90)
                                    {
                                        if (tempcount1 == 0)
                                        {
                                            countnumber1++;
                                        }

                                        tempcount1 = 1;
                                    }

                                    else
                                    {
                                        if (tempcount1 == 1)
                                        {
                                            //countnumber1++;
                                        }

                                        tempcount1 = 0;
                                    }


                                    if (rotationAngle >= 0 && rotationAngle <= 90)
                                    {
                                        if (tempcount2 == 0)
                                        {
                                            countnumber2++;
                                        }

                                        tempcount2 = 1;
                                    }
                                    else
                                    {
                                        if (tempcount2 == 1)
                                        {
                                            countnumber2++;
                                        }

                                        tempcount2 = 0;
                                    }

                                    // double angle=AngleBetweenTwoVectors(ElbowLeft, WristLeft);
                                    // Console.WriteLine("angle1 = " + LeftElbowAngle.ToString() + "count1 = " + countnumber1.ToString() + "result1= " + tempcount1.ToString());
                                    // Console.WriteLine("angle2 = " + rotationAngle.ToString() + "count2 = " + countnumber2.ToString() + "result2= " + tempcount2.ToString());
                                }
                            }
                            // Console.WriteLine("angle1 = " + LeftElbowAngle.ToString() + "ElbowRotation= " + countnumber1.ToString());
                            // Console.WriteLine("angle2 = " + rotationAngle.ToString() + "LefthandRotation = " + countnumber2.ToString());
                            //Console.WriteLine("angle3 = " + rottwohand.ToString() + "HighKnees = " + countnumber3.ToString());
                            Console.WriteLine("angle4 = " + footrot.ToString() + "BothHandSwing = " + (countnumber4 - 1).ToString());
                            Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position);

                            // Scale the skeleton thickness
                            // 1.0 is the desired size at 640 width
                            double scale = this.RenderSize.Width / 640;

                            skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale);
                        }

                        if (ImageType == ImageType.Depth)
                        {
                            this.ChooseTrackedSkeletons(this.skeletonData);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        private void KinectAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            // Have we already been "shut down" by the user of this viewer,
            // or has the SkeletonStream been disabled since this event was posted?
            if ((this.Kinect == null) || !((KinectSensor)sender).SkeletonStream.IsEnabled)
            {
                return;
            }

            bool haveSkeletonData = false;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    if (this.skeletonCanvases == null)
                    {
                        this.CreateListOfSkeletonCanvases();
                    }

                    if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
                    {
                        this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    }

                    skeletonFrame.CopySkeletonDataTo(this.skeletonData);

                    haveSkeletonData = true;
                }
            }

            if (haveSkeletonData)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    if (depthImageFrame != null)
                    {
                        int trackedSkeletons = 0;

                        foreach (Skeleton skeleton in this.skeletonData)
                        {
                            Dictionary <JointType, JointMapping> jointMapping = this.jointMappings[trackedSkeletons];
                            jointMapping.Clear();

                            KinectSkeleton skeletonCanvas = this.skeletonCanvases[trackedSkeletons++];
                            skeletonCanvas.ShowBones  = this.ShowBones;
                            skeletonCanvas.ShowJoints = this.ShowJoints;
                            skeletonCanvas.ShowCenter = this.ShowCenter;

                            // Transform the data into the correct space
                            // For each joint, we determine the exact X/Y coordinates for the target view
                            foreach (Joint joint in skeleton.Joints)
                            {
                                Console.WriteLine("Here they are: " + joint.Position.X + "" + joint.Position.Y + "" + "" + joint.Position.Z);
                                Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);
                                jointMapping[joint.JointType] = new JointMapping
                                {
                                    Joint       = joint,
                                    MappedPoint = mappedPoint
                                };
                            }

                            // Look up the center point
                            Point centerPoint = this.GetPosition2DLocation(depthImageFrame, skeleton.Position);

                            // Scale the skeleton thickness
                            // 1.0 is the desired size at 640 width
                            double scale = this.RenderSize.Width / 640;

                            skeletonCanvas.RefreshSkeleton(skeleton, jointMapping, centerPoint, scale);
                        }

                        if (ImageType == ImageType.Depth)
                        {
                            this.ChooseTrackedSkeletons(this.skeletonData);
                        }
                    }
                }
            }
        }