private void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null || _sensor == null) return; // DepthImagePoint headDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); // right hand point information DepthImagePoint RightHandDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); RightHandPoint newRightHandPoint = new RightHandPoint() { X = RightHandDepthPoint.X, Y = RightHandDepthPoint.Y, Z = RightHandDepthPoint.Depth, T = DateTime.Now }; //left hand point information DepthImagePoint LeftHandDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); LeftHandPoint newLeftHandPoint = new LeftHandPoint() { X = LeftHandDepthPoint.X, Y = LeftHandDepthPoint.Y, Z = LeftHandDepthPoint.Depth, T = DateTime.Now }; // right shoulder point information DepthImagePoint RightShoulderDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ShoulderRight].Position); RightShoulderPoint newRightShoulderPoint = new RightShoulderPoint() { X = RightShoulderDepthPoint.X, Y = RightShoulderDepthPoint.Y, Z = RightShoulderDepthPoint.Depth, T = DateTime.Now }; // left shoulder point information DepthImagePoint LeftShoulderDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ShoulderLeft].Position); LeftShoulderPoint newLeftShoulderPoint = new LeftShoulderPoint() { X = LeftShoulderDepthPoint.X, Y = LeftShoulderDepthPoint.Y, Z = LeftShoulderDepthPoint.Depth, T = DateTime.Now }; // right elbow point DepthImagePoint RightElbowDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ElbowRight].Position); RightElbowPoint newRightElbowPoint = new RightElbowPoint() { X = RightElbowDepthPoint.X, Y = RightElbowDepthPoint.Y, Z = RightElbowDepthPoint.Depth, T = DateTime.Now }; // left elbow point DepthImagePoint LeftElbowDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ElbowLeft].Position); LeftElbowPoint newLeftElbowPoint = new LeftElbowPoint() { X = LeftElbowDepthPoint.X, Y = LeftElbowDepthPoint.Y, Z = LeftElbowDepthPoint.Depth, T = DateTime.Now }; DepthImagePoint RightWristDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.WristRight].Position); RightWristPoint newRightWristPoint = new RightWristPoint() { X = RightWristDepthPoint.X, Y = RightWristDepthPoint.Y, Z = RightWristDepthPoint.Depth, T = DateTime.Now }; DepthImagePoint HeadDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); HeadPoint newHeadPoint = new HeadPoint() { X = HeadDepthPoint.X, Y = HeadDepthPoint.Y, Z = HeadDepthPoint.Depth, T = DateTime.Now }; //user should stand in the right place before eveything start // the two if condition requires the user to stand in front of Kinect in a box area if (newHeadPoint.Z < 1700 || newHeadPoint.Z > 2000) { StatusLabel.Content = ""; ProgressBar.Visibility = System.Windows.Visibility.Hidden; label1.Visibility = System.Windows.Visibility.Hidden; label2.Visibility = System.Windows.Visibility.Hidden; LeftHandPointsList.Clear(); return; } // user should stand right in front of Kinect //if (newHeadPoint.X > 320 || newHeadPoint.X < 280) //{ // StatusLabel.Content = ""; // return; //} StatusLabel.Content = "Control Mode(1.7m~2m): "+ newHeadPoint.Z/1000+ "m"; ProgressBar.Visibility = System.Windows.Visibility.Visible; label1.Visibility = System.Windows.Visibility.Visible; label2.Visibility = System.Windows.Visibility.Visible; // the left hand push event; if (newLeftHandPoint.X > newLeftElbowPoint.X) { Push(newLeftHandPoint, newLeftElbowPoint); } if (newLeftHandPoint.Y < newHeadPoint.Y)// left hand wave to quit { // MessageBox.Show("Left wave"); LeftHandWave(newLeftHandPoint, newHeadPoint, newLeftElbowPoint); } else { IsLeftHandWave = false; } //Volume control if (Math.Abs(newRightHandPoint.Y - newHeadPoint.Y) < newRightShoulderPoint.Y - newHeadPoint.Y && Math.Abs(newRightHandPoint.X - newRightShoulderPoint.X) < newRightShoulderPoint.X - newHeadPoint.X) { VolumeControl(newRightHandPoint, newHeadPoint); } else { IsVolumeStart = false; } if (newRightHandPoint.Y > newRightShoulderPoint.Y && newRightHandPoint.X > newHeadPoint.X + 200)//right swipe { //trigger the right swipe gesture rightSwipeGesture(); } else { IsRightSwipeStart = false; } //left swipe if ( newLeftHandPoint.Y > newLeftShoulderPoint.Y && newLeftHandPoint.X < newHeadPoint.X - 200) { leftSwipeGesture(); } else { IsLeftSwipeStart = false; } }// end of using statement }
private void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame == null || _sensor == null) return; // DepthImagePoint headDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); // right hand point information DepthImagePoint RightHandDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); RightHandPoint newRightHandPoint = new RightHandPoint() { X = RightHandDepthPoint.X, Y = RightHandDepthPoint.Y, Z = RightHandDepthPoint.Depth, T = DateTime.Now }; RightHandPoint startRightHandPoint; //left hand point information DepthImagePoint LeftHandDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); LeftHandPoint newLeftHandPoint = new LeftHandPoint() { X = LeftHandDepthPoint.X, Y = LeftHandDepthPoint.Y, Z = LeftHandDepthPoint.Depth, T = DateTime.Now }; LeftHandPoint startLeftHandPoint; // right shoulder point information DepthImagePoint RightShoulderDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ShoulderRight].Position); RightShoulderPoint newRightShoulderPoint = new RightShoulderPoint() { X = RightShoulderDepthPoint.X, Y = RightShoulderDepthPoint.Y, Z = RightShoulderDepthPoint.Depth, T = DateTime.Now }; // left shoulder point information DepthImagePoint LeftShoulderDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ShoulderLeft].Position); LeftShoulderPoint newLeftShoulderPoint = new LeftShoulderPoint() { X = LeftShoulderDepthPoint.X, Y = LeftShoulderDepthPoint.Y, Z = LeftShoulderDepthPoint.Depth, T = DateTime.Now }; // right elbow point DepthImagePoint RightElbowDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ElbowRight].Position); RightElbowPoint newRightElbowPoint = new RightElbowPoint() { X = RightElbowDepthPoint.X, Y = RightElbowDepthPoint.Y, Z = RightElbowDepthPoint.Depth, T = DateTime.Now }; // left elbow point DepthImagePoint LeftElbowDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.ElbowLeft].Position); LeftElbowPoint newLeftElbowPoint = new LeftElbowPoint() { X = LeftElbowDepthPoint.X, Y = LeftElbowDepthPoint.Y, Z = LeftElbowDepthPoint.Depth, T = DateTime.Now }; DepthImagePoint RightWristDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.WristRight].Position); RightWristPoint newRightWristPoint = new RightWristPoint() { X = RightWristDepthPoint.X, Y = RightWristDepthPoint.Y, Z = RightWristDepthPoint.Depth, T = DateTime.Now }; DepthImagePoint HeadDepthPoint = depthFrame.MapFromSkeletonPoint(first.Joints[JointType.Head].Position); HeadPoint newHeadPoint = new HeadPoint() { X = HeadDepthPoint.X, Y = HeadDepthPoint.Y, Z = HeadDepthPoint.Depth, T = DateTime.Now }; if (newHeadPoint.Z < 1700 || newHeadPoint.Z > 2000) { StatusLabel.Content = ""; return; } StatusLabel.Content = "Control Mode(1.7m~2m): "+ newHeadPoint.Z/1000+ "m"; if (newRightHandPoint.Y - newHeadPoint.Y < 0 && newRightHandPoint.X - newRightShoulderPoint.X > -30) { VolumeControl(newRightHandPoint, newHeadPoint); } else { IsVolumeStart = false; } // left hand wave to quit if (newLeftHandPoint.Y < newHeadPoint.Y) { // MessageBox.Show("Left wave"); LeftHandWave(newLeftHandPoint, newHeadPoint); } else { IsLeftHandWave = false; } if (newRightHandPoint.Y > newRightShoulderPoint.Y && newRightHandPoint.X > newHeadPoint.X + 200)//right swipe { //trigger the right swipe gesture rightSwipeGesture(); } else { IsRightSwipeStart = false; } //left swipe if (newLeftHandPoint.Y > newLeftShoulderPoint.Y && newLeftHandPoint.X < newHeadPoint.X - 200) { //MessageBox.Show("Swipe left"); leftSwipeGesture(); } else { IsLeftSwipeStart = false; } } }