private void Updates(Skeleton skeleton) { //Dab counter dabCounter.Update(skeleton); ((UserControlDab)userControls[1]).label2.Content = dabCounter.dabCounter; Joint handJoint; float downLimit; if (skeleton.Joints[JointType.HandLeft].Position.Y > skeleton.Joints[JointType.HandRight].Position.Y) { handJoint = skeleton.Joints[JointType.HandLeft]; downLimit = skeleton.Joints[JointType.ElbowLeft].Position.Y; } else { handJoint = skeleton.Joints[JointType.HandRight]; downLimit = skeleton.Joints[JointType.ElbowRight].Position.Y; } //Hand has to be higher then if (downLimit < handJoint.Position.Y) { Point p = SkeletonPointToScreen(handJoint.Position); hand.Update(p); hand.Draw(My_Image); Hand.Gesture g = hand.CheckForGesture(); switch (g) { case Hand.Gesture.SWIPE_LEFT: ((UserControlDab)userControls[1]).label1.Content = "Left"; break; case Hand.Gesture.SWIPE_RIGTH: ((UserControlDab)userControls[1]).label1.Content = "Right"; break; case Hand.Gesture.SWIPE_UP: ((UserControlDab)userControls[1]).label1.Content = "Up"; break; case Hand.Gesture.SWIPE_DOWN: ((UserControlDab)userControls[1]).label1.Content = "Down"; break; default: break; } Point p2 = hand.LastPoint(); int x = (int)(p2.X * 3); int y = (int)(p2.Y * 2.25); NativeMethods.SetCursorPos(x, y); double left = x; double top = y; mouseEllipse.Margin = new Thickness(left, top, 0, 0); mouseEllipse.StrokeThickness = hand.radiusSmall; } else { hand.resetSmallRatius(); } // Set wpf Image to EmguImage imgBox.Source = BitmapSourceConvert.ToBitmapSource(My_Image); My_Image.SetZero(); }
private void Updates(Skeleton skeleton) { //Dab counter dabCounter.Update(skeleton); Joint handJoint; float downLimit; Boolean isLeftHand = false; //Get higher hand left else right if (skeleton.Joints[JointType.HandLeft].Position.Y > skeleton.Joints[JointType.HandRight].Position.Y) { handJoint = skeleton.Joints[JointType.HandLeft]; downLimit = skeleton.Joints[JointType.ElbowLeft].Position.Y; isLeftHand = true; } else { handJoint = skeleton.Joints[JointType.HandRight]; downLimit = skeleton.Joints[JointType.ElbowRight].Position.Y; } //Hand has to be higher then if (handJoint.Position.Y > downLimit) { Point p = SkeletonPointToScreen(handJoint.Position); hand.Update(p); Hand.Gesture g = hand.CheckForGesture(); switch (g) { case Hand.Gesture.SWIPE_LEFT: System.Diagnostics.Debug.WriteLine("Left"); setSlideManual(slideIndex--); break; case Hand.Gesture.SWIPE_RIGTH: System.Diagnostics.Debug.WriteLine("SWIPE_RIGTH"); setSlideManual(slideIndex++); break; case Hand.Gesture.SWIPE_UP: System.Diagnostics.Debug.WriteLine("SWIPE_UP"); break; case Hand.Gesture.SWIPE_DOWN: System.Diagnostics.Debug.WriteLine("SWIPE_DOWN"); break; default: break; } //Setting mouse position with scaling Point headPoint = SkeletonPointToScreen(skeleton.Joints[JointType.Head].Position); Point p2 = hand.LastPoint(); int x; if (isLeftHand) { x = (int)(p2.X * 3 * 3) - 500; } else { x = (int)(p2.X * 3 * 3) - (int)(headPoint.X * 3 * 2) - 500; } int y = (int)(p2.Y * 2.25 * 2) - (int)(headPoint.Y * 2.25); NativeMethods.SetCursorPos(x, y); //Moving ellipse with mouse Point p3 = Mouse.GetPosition(OverGrid); int x3 = (int)p3.X; int y3 = (int)p3.Y; double x1 = (x3) * 2 - 1250; double y2 = (y3) * 2 - 630; mouseEllipse.Margin = new Thickness(x1, y2, 0, 0); //Animation of ellipse double procentageRadius = hand.radiusSmall / hand.radiusBig; double maxThickness = 30; mouseEllipse.StrokeThickness = procentageRadius > 1 ? maxThickness : procentageRadius < 0.1 ? 0.1 * maxThickness : procentageRadius * maxThickness; if (procentageRadius >= 1) { mouseEllipse.Fill.Opacity = 0.3; System.Diagnostics.Debug.WriteLine(handJoint.Position.Z - lastHandZ); if (lastHandZ - handJoint.Position.Z > 0.015) { LeftMouseClick(x, y); } lastHandZ = handJoint.Position.Z; } else { mouseEllipse.Fill.Opacity = 0.3; } } else { hand.resetSmallRatius(); } }