/// <summary> /// Handles gesture detection results arriving from the sensor for the associated body tracking Id /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e) { _gestureName = null; using (VisualGestureBuilderFrame frame = _vgbFrameReader.CalculateAndAcquireLatestFrame()) { if (frame != null) { // get the discrete gesture results which arrived with the latest frame IReadOnlyDictionary <Gesture, DiscreteGestureResult> discreteResults = frame.DiscreteGestureResults; if (discreteResults != null) { foreach (Gesture gesture in _vgbFrameSource.Gestures) { DiscreteGestureResult result; discreteResults.TryGetValue(gesture, out result); if (result != null) { if (gesture.Name.Equals(_pickUp) && gesture.GestureType == GestureType.Discrete && result.Confidence > 0.05) { // update the GestureResultView object with new gesture result values GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, gesture.Name); _gestureName = "PickUp"; } else if (gesture.Name.Equals(_putDown) && gesture.GestureType == GestureType.Discrete && result.Confidence > 0.05) { // update the GestureResultView object with new gesture result values GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, gesture.Name); _gestureName = "PutDown"; } else if (gesture.Name.Equals(_openDoor) && gesture.GestureType == GestureType.Discrete && result.Confidence > 0.05) { // update the GestureResultView object with new gesture result values GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, gesture.Name); _gestureName = "OpenDoor"; } else if (gesture.Name.Equals(_handToMouth) && gesture.GestureType == GestureType.Discrete && result.Confidence > 0.05) { // update the GestureResultView object with new gesture result values GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, gesture.Name); _gestureName = "HandToMouth"; } else if (gesture.Name.Equals(_pour) && gesture.GestureType == GestureType.Discrete && result.Confidence > 0.05) { // update the GestureResultView object with new gesture result values GestureResultView.UpdateGestureResult(true, result.Detected, result.Confidence, gesture.Name); _gestureName = "Pour"; } else { _gestureName = "No Gesture"; } } } } } } }
/// <summary> /// Handles the TrackingIdLost event for the VisualGestureBuilderSource object /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Source_TrackingIdLost(object sender, TrackingIdLostEventArgs e) { // update the GestureResultView object to show the 'Not Tracked' image in the UI GestureResultView.UpdateGestureResult(false, false, 0.0f, null); }