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 }
// end of GetCamera point private void VolumeControl(RightHandPoint newRightHandPoint, HeadPoint newHeadPoint) { switch (VolumeState) { case 0: if (newRightHandPoint.Y == newHeadPoint.Y) { // volumeLabel.Content = "Volume:" + VolumeSlider.Value; //VolumeSlider.Visibility = System.Windows.Visibility.Visible; VolumeState = 1; //volumeLabel.Content = "Volume:" + VolumeSlider.Value; } break; case 1: VolumeSlider.Value = PreviousVolumeValue + (newHeadPoint.Y - newRightHandPoint.Y); VolumeSlider.Visibility = System.Windows.Visibility.Visible; volumeLabel.Content = "Volume:" + VolumeSlider.Value;// ( newHeadPoint.Y - newRightHandPoint.Y ) if (newRightHandPoint.X - newHeadPoint.X < 50) { VolumeState = 2; IsVolumeStart = true; //MessageBox.Show("Value Changed1 "); } break; default: break; } if (!VolumeStart && IsVolumeStart == true) { //if (!VolumeStart) // MessageBox.Show("Value Changed2 " + (newHeadPoint.Y - newRightHandPoint.Y)); IsVolumeStart = false; PreviousVolumeValue = VolumeSlider.Value; volumeLabel.Content = ""; VolumeSlider.Visibility = System.Windows.Visibility.Hidden; VolumeStart = true; VolumeState = 0; //VolumeSlider.Value += newHeadPoint.Y - RightHandPointsList.Last().Y; //return; } else { VolumeStart = false; } }
private void VolumeControl(RightHandPoint newRightHandPoint, HeadPoint newHeadPoint) { if(!IsVolumeStart) { IsVolumeStart = true; StopKinect(_sensor); statusLabel.Content = "Loading..."; _sensor.AllFramesReady -= _sensor_AllFramesReady; PhotoVoiceControl newVoice = new PhotoVoiceControl("1",_sensor); this.NavigationService.Navigate(newVoice); return; } }
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; } } }
private void VolumeControl(RightHandPoint newRightHandPoint, HeadPoint newHeadPoint) { //volumeLabel.Content = "Volume:" + VolumeSlider.Value; // VolumeSlider.Visibility = System.Windows.Visibility.Visible; switch (VolumeState) { case 0: if (newRightHandPoint.Y == newHeadPoint.Y) { VolumeState = 1; GestureLabel.UpdateLayout(); if (GestureLabel.Visibility == Visibility.Hidden) { GestureLabel.Content = "Volume Control Stage 1"; GestureLabel.Visibility = Visibility.Visible; timer = new System.Threading.Timer( (state) => { GestureLabel.Dispatcher.BeginInvoke((Action)(() => { GestureLabel.Visibility = Visibility.Hidden; })); }, null, 1000, Int32.MaxValue); } else { GestureLabel.Content = "Volume Control Stage 1"; } //volumeLabel.Content = "Volume:" + VolumeSlider.Value; } break; case 1: if (newRightHandPoint.X - newHeadPoint.X < 50) { VolumeState = 2; IsVolumeStart = true; GestureLabel.UpdateLayout(); if (GestureLabel.Visibility == Visibility.Hidden) { GestureLabel.Content = "Volume Control Stage 2"; GestureLabel.Visibility = Visibility.Visible; timer = new System.Threading.Timer( (state) => { GestureLabel.Dispatcher.BeginInvoke((Action)(() => { GestureLabel.Visibility = Visibility.Hidden; })); }, null, 1000, Int32.MaxValue); } else { GestureLabel.Content = "Volume Control Stage 2"; } //MessageBox.Show("Value Changed1 "); } break; default: break; } if (!VolumeStart && IsVolumeStart == true) { IsVolumeStart = false; VolumeStart = true; VolumeState = 0; GestureLabel.UpdateLayout(); if (GestureLabel.Visibility == Visibility.Hidden) { GestureLabel.Content = "Volume Control Succeed!"; GestureLabel.Visibility = Visibility.Visible; timer = new System.Threading.Timer( (state) => { GestureLabel.Dispatcher.BeginInvoke((Action)(() => { GestureLabel.Visibility = Visibility.Hidden; })); }, null, 1000, Int32.MaxValue); } else { GestureLabel.Content = "Volume Control Succeed!"; } } else { VolumeStart = false; } }