void gr_gestureRecognized(Gesture g) { Console.WriteLine(g.gestureName); }
/// <summary> /// Called whenever a new skeleton frame is ready. /// </summary> /// <param name="e">The skeleton frame event that holds any frame information</param> /// <param name="Skeletons">Dictionary w/ player skeletons; each skeleton consists of a map of Joints and actual joint data</param> public void SkeletonFrame(SkeletonFrameReadyEventArgs e, Dictionary<int, Dictionary<JointType, Joint>> Skeletons) { //Console.WriteLine("SkeletonFrame."); try { // 1. For every skeleton... foreach (var s in Skeletons) { // (get the skeleton data dictionary) Dictionary<JointType, Joint> dict = s.Value; // 2. ... and every gesture that is supposed to be recognized... foreach (Gesture g in this.recognizableGestures) { // 3. ...test if gesture is recognized and the start conditions are conform if (g==currentGesture && g.startRecognition(dict)) { // set variable true, so that only this gesture is proofed and all others ignored isGestureRecording = true; // 4. ...set the start date of the gesture if (positions.Count == 0) { startdate = DateTime.Now; } // 5. ...tests if time is under maximal gestureDuration and smaller minimal gestureMove lenght if ((DateTime.Now - startdate).TotalMilliseconds < g.gestureDuration && g.getActualMoveLength() <= g.minimalLength) { if (g.saveObservation(dict)) { positions.Add(dict); } } else { if (g.isGesture(positions)) { //. ... and if this is the case, fire the appropriate event. GestureRecognized(g); Log("Gesture " + g.gestureName + " recognized ( Player " + s.Key + " )"); isGestureRecording = false; currentGesture = null; } else { Log("couldn't recognize "+g.gestureName + " (Player "+ s.Key + " )"); isGestureRecording = false; currentGesture = null; } } } else { //...if given Skeleton is start posture not registred yet and no gesture is recording if (g.isStartPosture(dict) && g!=currentGesture && !isGestureRecording) { if (currentGesture == null) { currentGesture = g; } // otherwise, currentGesture is set to a previously registered (as in start posture recognized) gesture Log("start posture of Player " + s.Key + " for gesture: " + g.gestureName + " recognized. Previously registered "+ currentGesture.gestureName + " is recording: " + currentGesture.startRecognition(dict) + ", positions recorded = " + positions.Count); //only current gesture which start posture is recognized is saved // maybe this should be changed: it will override the previous gesture even if it is already recording. this should check if a previously registered gesture could be recording. currentGesture = g; positions.Clear(); } } } } } catch (KeyNotFoundException) { Log("No skeleton found."); } }