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 }
//a very simple version of left hand wave private void LeftHandWave(LeftHandPoint newLeftHandPoint, HeadPoint newHeadPoint, LeftElbowPoint newLeftElbowPoint) { //left hand wave gesture(start = 0, raisehand = 1, rightside = 2, leftside = 3, putdown = 4) if (!IsLeftHandWave && newHeadPoint.X - newLeftHandPoint.X > 200) //left hand wave gesture(start = 0, raisehand = 1, rightside = 2, leftside = 3, putdown = 4) { IsLeftHandWave = true; _sensor.AllFramesReady -= _sensor_AllFramesReady; (Application.Current.MainWindow.FindName("mainFrame") as Frame).Source = new Uri("Movie.xaml", UriKind.RelativeOrAbsolute); } // closing the event handler }
//left hand push gesture private void Push(LeftHandPoint newLeftHandPoint,LeftElbowPoint newLeftElbowPoint) { LeftHandPoint startLeftHandPoint; LeftHandPointsList.Add(newLeftHandPoint); startLeftHandPoint = LeftHandPointsList[0]; // check if press gesture is in the boundary box; if (Math.Abs(startLeftHandPoint.X - newLeftHandPoint.X) > 100 || Math.Abs(startLeftHandPoint.Y - newLeftHandPoint.Y) > 100) { LeftHandPointsList.Clear(); return; } if (Math.Abs(startLeftHandPoint.X - newLeftHandPoint.X) < 100 && Math.Abs(startLeftHandPoint.Y - newLeftHandPoint.Y) < 100) { if ((newLeftHandPoint.T - startLeftHandPoint.T).Milliseconds > 700) { LeftHandPointsList.RemoveAt(0); startLeftHandPoint = LeftHandPointsList[0]; } if (startLeftHandPoint.Z - newLeftHandPoint.Z > 250) { LeftHandPointsList.Clear(); if (!playOrNot) { MoviePlayer.Play(); playOrNot = true; Label1.UpdateLayout(); if (Label1.Visibility == Visibility.Hidden) { Label1.Content = "PLAY"; Label1.Visibility = Visibility.Visible; timer = new System.Threading.Timer( (state) => { Label1.Dispatcher.BeginInvoke((Action)(() => { Label1.Visibility = Visibility.Hidden; })); }, null, 1000, Int32.MaxValue); } else { Label1.Content = "PLAY"; } } else { MoviePlayer.Pause(); playOrNot = false; Label1.UpdateLayout(); if (Label1.Visibility == Visibility.Hidden) { Label1.Content = "PAUSE"; Label1.Visibility = Visibility.Visible; timer = new System.Threading.Timer( (state) => { Label1.Dispatcher.BeginInvoke((Action)(() => { Label1.Visibility = Visibility.Hidden; })); }, null, 1000, Int32.MaxValue); } else { Label1.Content = "PAUSE"; } } } } // end of lefthand press }
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; } } }