示例#1
0
 /// <summary>
 /// Updates the specified drawn skeleton with the new positions
 /// </summary>
 /// <param name="skeleton">The skeleton source.</param>
 /// <param name="drawing">The target drawing.</param>
 private void Update(Skeleton skeleton, SkeletonDrawing drawing)
 {
 }
示例#2
0
        /// <summary>
        /// Handles the SkeletonFrameReady event of the newKinect control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.Kinect.SkeletonFrameReadyEventArgs"/> instance containing the event data.</param>
        void Kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            // use flag not to track movements, on timer flag will change to true.
            if (bFlag == false)
            {
                return;
            }

            // Opens the received SkeletonFrame
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                // Skeleton frame might be null if we are too late or if the Kinect has been stopped
                if (skeletonFrame == null)
                {
                    return;
                }

                // Copies the data in a Skeleton array (6 items)
                skeletonFrame.CopySkeletonDataTo(skeletonData);

                // Retrieves Skeleton objects with Tracked state
                var trackedSkeletons = skeletonData.Where(s => s.TrackingState == SkeletonTrackingState.Tracked);

                // By default, assume all the drawn skeletons are inactive
                foreach (SkeletonDrawing skeleton in drawnSkeletons.Values)
                {
                    skeleton.Status = ActivityState.Inactive;
                }

                foreach (Skeleton trackedSkeleton in trackedSkeletons)
                {
                    SkeletonDrawing skeletonDrawing;
                    // Checks if the tracked skeleton is already drawn.
                    if (!drawnSkeletons.ContainsKey(trackedSkeleton.TrackingId))
                    {
                        // If not, create a new drawing on our canvas
                        skeletonDrawing = new SkeletonDrawing(this.SkeletonCanvas);
                        drawnSkeletons.Add(trackedSkeleton.TrackingId, skeletonDrawing);
                    }
                    else
                    {
                        skeletonDrawing = drawnSkeletons[trackedSkeleton.TrackingId];
                    }

                    // Update the drawing
                    foreach (Joint joint in trackedSkeleton.Joints)
                    {
                        // Transforms a SkeletonPoint to a ColorImagePoint
                        //var colorPoint = Kinect.MapSkeletonPointToColor(joint.Position, Kinect.ColorStream.Format);
                        var colorPoint = Kinect.CoordinateMapper.MapSkeletonPointToColorPoint(joint.Position, Kinect.ColorStream.Format);
                        // Scale the ColorImagePoint position to the current window size
                        var point = new Point((int)colorPoint.X / 640.0 * this.ActualWidth, (int)colorPoint.Y / 480.0 * this.ActualHeight);
                        // update the position of that joint
                        skeletonDrawing.Update(joint.JointType, point, joint.Position.Z);

                        JointData data = new JointData(sw.Elapsed, joint.JointType, joint.TrackingState, joint.Position.X, joint.Position.Y, joint.Position.Z);
                        //CurrentExamData.Data.Add(new JointData(sw.Elapsed, joint));
                        if (joint.JointType == JointType.ElbowLeft || joint.JointType == JointType.ElbowRight)
                        {
                            CurrentExamData.Data.Add(data);
                        }
                    }

                    skeletonDrawing.Status = ActivityState.Active;
                }


                foreach (SkeletonDrawing skeleton in drawnSkeletons.Values)
                {
                    // Erase all the still inactive drawing. It means they are not tracked anymore.
                    if (skeleton.Status == ActivityState.Inactive)
                    {
                        skeleton.Erase();
                    }
                }

                this.InvalidateVisual();
            }
        }