/// <summary> /// Add dynamic gesture to a dataset /// </summary> /// <param name="g">Gesture</param> public void AddDynamicGesture(DynamicGesture g) { if (g != null) { DynamicGestures.Add(g); } }
/// <summary> /// Notifies the user and executes defined actions for recognized dynamic gestures. /// </summary> /// <param name="rightGesture">Gesture (or null if none)</param> private void FrameProcessor_RightDynamicGestureUpdated(DynamicGesture rightGesture) { if (rightGesture != null) { String str = "Dynamic gesture:\n\n"; str += rightGesture.Name; RightDynamicResult.Text = str; } else { RightDynamicResult.Text = ""; } }
/// <summary> /// Notifies the user and executes defined actions for recognized dynamic gestures. /// </summary> /// <param name="leftGesture">Gesture (or null if none)</param> private void FrameProcessor_LeftDynamicGestureUpdated(DynamicGesture leftGesture) { if (leftGesture != null) { String str = "Dynamic gesture:\n\n"; str += leftGesture.Name; LeftDynamicResult.Text = str; } else { LeftDynamicResult.Text = ""; } }
/// <summary> /// Processes frame on the main thread. /// </summary> /// <param name="frame">Frame</param> public void ProcessFrame(MultiSourceFrame frame) { FrameData frameData = new FrameData(); // Get depth information using (var depthFrame = frame.DepthFrameReference.AcquireFrame()) { if (depthFrame != null) { depthFrame.CopyFrameDataToArray(frameData.DepthData); Utility.MinReliableDepth = depthFrame.DepthMinReliableDistance; Utility.MaxReliableDepth = depthFrame.DepthMaxReliableDistance; if (DepthReady != null) { BitmapSource depthImage = Utility.DrawDepthFrame(frameData.DepthData); DepthReady(depthImage); } } else { frameData = null; return; } } // Get skeleton information Dictionary <String, Joint> leftJoints = new Dictionary <String, Joint>(); Dictionary <String, Joint> rightJoints = new Dictionary <String, Joint>(); using (var bodyFrame = frame.BodyFrameReference.AcquireFrame()) { if (bodyFrame != null) { Body[] bodies = new Body[bodyFrame.BodyCount]; bodyFrame.GetAndRefreshBodyData(bodies); Body _activeBody = bodies.FirstOrDefault(body => body != null && body.IsTracked); if (_activeBody == null) { frameData = null; return; } leftJoints["hand"] = _activeBody.Joints[JointType.HandLeft]; leftJoints["wrist"] = _activeBody.Joints[JointType.WristLeft]; leftJoints["thumb"] = _activeBody.Joints[JointType.ThumbLeft]; leftJoints["handtip"] = _activeBody.Joints[JointType.HandTipLeft]; leftJoints["shoulder"] = _activeBody.Joints[JointType.ShoulderLeft]; leftJoints["elbow"] = _activeBody.Joints[JointType.ElbowLeft]; leftJoints["head"] = _activeBody.Joints[JointType.Head]; leftJoints["spine"] = _activeBody.Joints[JointType.SpineBase]; rightJoints["hand"] = _activeBody.Joints[JointType.HandRight]; rightJoints["wrist"] = _activeBody.Joints[JointType.WristRight]; rightJoints["thumb"] = _activeBody.Joints[JointType.ThumbRight]; rightJoints["handtip"] = _activeBody.Joints[JointType.HandTipRight]; rightJoints["shoulder"] = _activeBody.Joints[JointType.ShoulderRight]; rightJoints["elbow"] = _activeBody.Joints[JointType.ElbowRight]; rightJoints["head"] = _activeBody.Joints[JointType.Head]; rightJoints["spine"] = _activeBody.Joints[JointType.SpineBase]; } else { frameData = null; return; } } frameData.LeftJoints = leftJoints; frameData.RightJoints = rightJoints; // Identify left hand frameData.LeftHand = _leftHandRecognizer.IdentifyHand(frameData.DepthData, leftJoints); if (LeftHandReady != null) { LeftHandReady(frameData.LeftHand); } // Identify right hand frameData.RightHand = _rightHandRecognizer.IdentifyHand(frameData.DepthData, rightJoints); if (RightHandReady != null) { RightHandReady(frameData.RightHand); } // Scan left hand for gestures if (frameData.LeftHand != null) { frameData.LeftGesture = _leftGestureRecognizer.RecognizeGesture(frameData.LeftHand.MaskImage, frameData.LeftHand.Fingers.Count); if (LeftGestureUpdated != null) { LeftGestureUpdated(frameData.LeftGesture, frameData.LeftHand.Direction); } } // Scan right hand for gestures if (frameData.RightHand != null) { frameData.RightGesture = _rightGestureRecognizer.RecognizeGesture(frameData.RightHand.MaskImage, frameData.RightHand.Fingers.Count); if (RightGestureUpdated != null) { RightGestureUpdated(frameData.RightGesture, frameData.RightHand.Direction); } } FrameBuffer.PushFrame(frameData); DynamicGesture leftDynamicGesture = _leftGestureRecognizer.RecognizeDynamicGesture(); if (LeftDynamicGestureUpdated != null) { LeftDynamicGestureUpdated(leftDynamicGesture); } DynamicGesture rightDynamicGesture = _rightGestureRecognizer.RecognizeDynamicGesture(); if (RightDynamicGestureUpdated != null) { RightDynamicGestureUpdated(rightDynamicGesture); } }