void myBodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) { if (this.IsPaused) { return; } PreposeGesturesFrame retFrame = null; PreposeGesturesFrameArrivedEventArgs upArgs = new PreposeGesturesFrameArrivedEventArgs(); using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) { if (bodyFrame != null) { // Perform the gesture matching on this frame var z3body = new Z3Body(); bodyFrame.GetAndRefreshBodyData(this.bodies); foreach (var body in this.bodies) { if (body.TrackingId == this.mySource.TrackingId) { // We are at the correct body - go ahead and feed it to the BodyMatcher IReadOnlyDictionary <Microsoft.Kinect.JointType, Joint> joints = body.Joints; z3body = Z3KinectConverter.CreateZ3Body(joints); var result = this.PreposeGesturesFrameSource.myMatcher.TestBody(z3body); // Fill in the gesture results for this frame retFrame = new PreposeGesturesFrame(); retFrame.results = result; break; } } } } // TODO: revisit the way the PreposeGesturesFrameReference is implemented to avoid keeping around massive amounts of frames PreposeGesturesFrameReference retFrameReference = new PreposeGesturesFrameReference(retFrame); upArgs.FrameReference = retFrameReference; // Signal that we have a new PreposeGesturesFrame arrived FrameArrived(this, upArgs); }
/// <summary> /// Matches a Kinect body to a set of gestures within the app. /// </summary> /// <param name="kinectJoints">Body representation</param> /// <param name="jumpToNextPose">synthesizes a new body in correct position if true</param> /// <returns></returns> public static List <GestureStatus> TestBody(BodyMatcher matcher, IReadOnlyDictionary <Microsoft.Kinect.JointType, Microsoft.Kinect.Joint> kinectJoints, bool jumpToNextPose = false) { // convert Kinect.Body to Z3Body var body = new Z3Body(); if (!jumpToNextPose) { body = Z3KinectConverter.CreateZ3Body(kinectJoints); } else { //body = GetCopiedBodyValues(this.Gestures[this.GetMostAdvancedGesturesIDs()[0]].GetTarget().Body); var firstGestureBody = matcher.GetLastGestureTarget().Body; body = new Z3Body(firstGestureBody); } return(matcher.TestBody(body)); }