public void Update(Skeleton sk) { _stay = false; _slow = false; _complete = false; _angleB = false; _alignment = false; _leftHand = false; nbFrames++; Point3D hand = new Point3D(sk.Joints[JointType.HandRight].Position); Point3D elbow = new Point3D(sk.Joints[JointType.ElbowRight].Position); Point3D shoulder = new Point3D(sk.Joints[JointType.ShoulderRight].Position); Point3D shoulderLeft = new Point3D(sk.Joints[JointType.ShoulderLeft].Position); Point3D head = new Point3D(sk.Joints[JointType.Head].Position); Point3D handLeft = new Point3D(sk.Joints[JointType.HandLeft].Position); Point3D hipLeft = new Point3D(sk.Joints[JointType.HipLeft].Position); if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted) { DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Do the military salute"; } //calculation of the angle formed by the arm double lenghtHandElbow = Math.Sqrt(Math.Pow(hand.X - elbow.X, 2) + Math.Pow(hand.Y - elbow.Y, 2) + Math.Pow(hand.Z - elbow.Z, 2)); double lenghtHandShoulder = Math.Sqrt(Math.Pow(hand.X - shoulder.X, 2) + Math.Pow(hand.Y - shoulder.Y, 2) + Math.Pow(hand.Z - shoulder.Z, 2)); double lenghtElbowShoulder = Math.Sqrt(Math.Pow(shoulder.X - elbow.X, 2) + Math.Pow(shoulder.Y - elbow.Y, 2) + Math.Pow(shoulder.Z - elbow.Z, 2)); double cosAngle = (Math.Pow(lenghtElbowShoulder, 2) - Math.Pow(lenghtHandShoulder, 2) - Math.Pow(lenghtHandElbow, 2)) / (-2 * lenghtHandShoulder * lenghtHandElbow); double angle = Math.Acos(cosAngle) * 180 / Math.PI; //arm alignment check (version 1) /*Vector3 vectorShoulder = new Vector3((float)(shoulder.X - shoulderLeft.X), (float)(shoulder.Y - shoulderLeft.Y), (float)(shoulder.Z - shoulderLeft.Z)); * Vector3 vectorShoulderElbow = new Vector3((float)(elbow.X - shoulder.X), (float)(elbow.Y - shoulder.Y), (float)(elbow.Z - shoulder.Z)); * * float crossProductX = vectorShoulder.Y * vectorShoulderElbow.Z - vectorShoulder.Z * vectorShoulderElbow.Y; * float crossProductY = vectorShoulder.Z * vectorShoulderElbow.X - vectorShoulder.X * vectorShoulderElbow.Z; * float crossProductZ = vectorShoulder.X * vectorShoulderElbow.Y - vectorShoulder.Y * vectorShoulderElbow.X;*/ //arm alignment check (version 2) double directionVector = (shoulder.Y - shoulderLeft.Y) / (shoulder.X - shoulderLeft.X); double k = shoulder.Y - (shoulder.X * directionVector); double theoreticalY = elbow.X * directionVector + k; //distance between left hand and hip double distance = Math.Sqrt(Geometry.distanceSquare(handLeft, hipLeft)); //if the salute is not made in time if (!start && nbFrames > TOO_SLOW) { countError = 0; nbFrames = 0; //wrong left hand position if (!(distance < 0.3)) { _leftHand = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } //wrong arm alignment else if (!(Math.Abs(theoreticalY - elbow.Y) < 0.05)) { _alignment = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } //wrong arm angle else if (!(Math.Abs(angle - 45) < 1)) { _angleB = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } //good position of salute if (/*Math.Abs(angle - 45) < 5 &&*/ Math.Abs(theoreticalY - elbow.Y) < 0.1 && Math.Abs(head.Y - hand.Y) < 0.1 && Math.Abs(head.Z - hand.Z) < 0.1 && Math.Abs(head.X - hand.X) < 0.3 && distance < 0.3) { start = true; nbStay++; //salute complete if (nbStay >= WAITING_TIME) { start = false; countError = 0; nbFrames = 0; nbStay = 0; _complete = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } else { if (start) { countError++; } //if the user does not stay waiting if (start && nbFrames < TOO_FAST && countError > ERROR_MAX) { countError = 0; nbFrames = 0; nbStay = 0; start = false; _stay = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } }
public void Update(Skeleton sk) { if (!AudioProvider.detectionActive) { TrackingSideTool.Get().SpeedRateDetectionCheckBox.IsChecked = true; } _up = false; _complete = false; _lookingDir = false; frame++; if (frame > NB_FRAME_MAX) { frame = 0; start = false; right = false; left = false; _up = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted && !start) { DrawingSheetAvatarViewModel.displayCustomText = "Look at the direction of your raised arm then speak"; } try { var face = KinectDevice.skeletonFaceTracker.facePoints3D; Vector3DF rightEye = face.ElementAt(20); Vector3DF leftEye = face.ElementAt(53); Point3D handRight = new Point3D(sk.Joints[JointType.HandRight].Position); Point3D handLeft = new Point3D(sk.Joints[JointType.HandLeft].Position); Point3D elbowRight = new Point3D(sk.Joints[JointType.ElbowRight].Position); Point3D elbowLeft = new Point3D(sk.Joints[JointType.ElbowLeft].Position); Point3D shoulder = new Point3D(sk.Joints[JointType.ShoulderCenter].Position); if (verbose) { Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("frame: " + frame); Console.WriteLine("direction: " + (rightEye.Z - leftEye.Z)); Console.WriteLine("right: " + right); Console.WriteLine("left: " + left); } if (Math.Abs(handRight.X - elbowRight.X) > 0.05 && handRight.Y > shoulder.Y) { if (rightEye.Z - leftEye.Z < -0.015) { if (AudioProvider.currentIntensity > AUDIO_LOUDNESS) { start = true; right = true; DrawingSheetAvatarViewModel.displayCustomText = "Do the same with the other arm"; if (left) { frame = 0; start = false; right = false; left = false; _complete = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } } else if (!right) { frame = 0; start = false; right = false; left = false; _lookingDir = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } if (Math.Abs(handLeft.X - elbowLeft.X) > 0.05 && handLeft.Y > shoulder.Y) { if (rightEye.Z - leftEye.Z > 0.015) { if (AudioProvider.currentIntensity > AUDIO_LOUDNESS) { start = true; left = true; DrawingSheetAvatarViewModel.displayCustomText = "Do the same with the other arm"; if (right) { frame = 0; start = false; right = false; left = false; _complete = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } } else if (!left) { frame = 0; start = false; right = false; left = false; _lookingDir = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } } catch (Exception e) //the kinect don't catch the face { //System.Windows.Forms.MessageBox.Show("the kinect don't catch the face !"); Console.Error.WriteLine(e); } }
/// <summary> /// Fires the <see cref="GestureRecognized"/> event /// </summary> protected void Fire(Body body) { GestureRecognized?.Invoke(this, new GestureEventArgs(body.TrackingId, this._gestureIdentifier)); }
public void Update(Skeleton sk) { _complete = false; _spread = false; _stretch = false; _up = false; frame++; bool angleRightOK = false; bool angleLeftOK = false; bool stretchRightOK = false; bool stretchLeftOK = false; bool up = false; Point3D handRight = new Point3D(sk.Joints[JointType.HandRight].Position); Point3D handLeft = new Point3D(sk.Joints[JointType.HandLeft].Position); Point3D elbowRight = new Point3D(sk.Joints[JointType.ElbowRight].Position); Point3D elbowLeft = new Point3D(sk.Joints[JointType.ElbowLeft].Position); Point3D shoulderRight = new Point3D(sk.Joints[JointType.ShoulderRight].Position); Point3D shoulderLeft = new Point3D(sk.Joints[JointType.ShoulderLeft].Position); Point3D head = new Point3D(sk.Joints[JointType.Head].Position); if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted) { DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Raise your arms"; } //calculation of the angle formed by the right arm double lenghtHeadShoulderRight = Math.Sqrt(Math.Pow(head.X - shoulderRight.X, 2) + Math.Pow(head.Y - shoulderRight.Y, 2) + Math.Pow(head.Z - shoulderRight.Z, 2)); double lenghtShoulderHandRight = Math.Sqrt(Math.Pow(shoulderRight.X - handRight.X, 2) + Math.Pow(shoulderRight.Y - handRight.Y, 2) + Math.Pow(shoulderRight.Z - handRight.Z, 2)); double lenghtHeadHandRight = Math.Sqrt(Math.Pow(head.X - handRight.X, 2) + Math.Pow(head.Y - handRight.Y, 2) + Math.Pow(head.Z - handRight.Z, 2)); double cosAngleRight = (Math.Pow(lenghtShoulderHandRight, 2) - (Math.Pow(lenghtHeadShoulderRight, 2) + Math.Pow(lenghtHeadHandRight, 2))) / (-2 * lenghtHeadShoulderRight * lenghtHeadHandRight); double angleRight = Math.Acos(cosAngleRight) * 180 / Math.PI; if (Math.Abs(angleRight - ANGLE) < ERROR_RATE_ANGLE) { angleRightOK = true; } //calculation of the angle formed by the left arm double lenghtHeadShoulderLeft = Math.Sqrt(Math.Pow(head.X - shoulderLeft.X, 2) + Math.Pow(head.Y - shoulderLeft.Y, 2) + Math.Pow(head.Z - shoulderLeft.Z, 2)); double lenghtShoulderHandLeft = Math.Sqrt(Math.Pow(shoulderLeft.X - handLeft.X, 2) + Math.Pow(shoulderLeft.Y - handLeft.Y, 2) + Math.Pow(shoulderLeft.Z - handLeft.Z, 2)); double lenghtHeadHandLeft = Math.Sqrt(Math.Pow(head.X - handLeft.X, 2) + Math.Pow(head.Y - handLeft.Y, 2) + Math.Pow(head.Z - handLeft.Z, 2)); double cosAngleLeft = (Math.Pow(lenghtShoulderHandLeft, 2) - (Math.Pow(lenghtHeadShoulderLeft, 2) + Math.Pow(lenghtHeadHandLeft, 2))) / (-2 * lenghtHeadShoulderLeft * lenghtHeadHandLeft); double angleLeft = Math.Acos(cosAngleLeft) * 180 / Math.PI; if (Math.Abs(angleLeft - ANGLE) < ERROR_RATE_ANGLE) { angleLeftOK = true; } //check if the arms are stretched (version 1) /*Vector3 vectorShoulderElbowRight = new Vector3((float)(elbowRight.X - shoulderRight.X), (float)(elbowRight.Y - shoulderRight.Y), (float)(elbowRight.Z - shoulderRight.Z)); * Vector3 vectorElbowHandRight = new Vector3((float)(handRight.X - elbowRight.X), (float)(handRight.Y - elbowRight.Y), (float)(handRight.Z - elbowRight.Z)); * * float crossProductX = vectorShoulderElbowRight.Y * vectorElbowHandRight.Z - vectorShoulderElbowRight.Z * vectorElbowHandRight.Y; * float crossProductY = vectorShoulderElbowRight.Z * vectorElbowHandRight.X - vectorShoulderElbowRight.X * vectorElbowHandRight.Z; * float crossProductZ = vectorShoulderElbowRight.X * vectorElbowHandRight.Y - vectorShoulderElbowRight.Y * vectorElbowHandRight.X; * * if (Math.Abs(crossProductX) < errorRateStretch && Math.Abs(crossProductY) < errorRateStretch && Math.Abs(crossProductZ) < errorRateStretch) * stretchRightOK = true; * * Vector3 vectorShoulderElbowLeft = new Vector3((float)(elbowLeft.X - shoulderLeft.X), (float)(elbowLeft.Y - shoulderLeft.Y), (float)(elbowLeft.Z - shoulderLeft.Z)); * Vector3 vectorElbowHandLeft = new Vector3((float)(handLeft.X - elbowLeft.X), (float)(handLeft.Y - elbowLeft.Y), (float)(handLeft.Z - elbowLeft.Z)); * * crossProductX = vectorShoulderElbowLeft.Y * vectorElbowHandLeft.Z - vectorShoulderElbowLeft.Z * vectorElbowHandLeft.Y; * crossProductY = vectorShoulderElbowLeft.Z * vectorElbowHandLeft.X - vectorShoulderElbowLeft.X * vectorElbowHandLeft.Z; * crossProductZ = vectorShoulderElbowLeft.X * vectorElbowHandLeft.Y - vectorShoulderElbowLeft.Y * vectorElbowHandLeft.X; * * if (Math.Abs(crossProductX) < errorRateStretch && Math.Abs(crossProductY) < errorRateStretch && Math.Abs(crossProductZ) < errorRateStretch) * stretchLeftOK = true;*/ //check if the arms are stretched (version 2) double directionVector = (elbowRight.Y - shoulderRight.Y) / (elbowRight.X - shoulderRight.X); double k = shoulderRight.Y - (shoulderRight.X * directionVector); double theoreticalYRight = handRight.X * directionVector + k; if (Math.Abs(theoreticalYRight - handRight.Y) < ERROR_RATE_STRETCH) { stretchRightOK = true; } directionVector = (elbowLeft.Y - shoulderLeft.Y) / (elbowLeft.X - shoulderLeft.X); k = shoulderLeft.Y - (shoulderLeft.X * directionVector); double theoreticalYLeft = handLeft.X * directionVector + k; if (Math.Abs(theoreticalYLeft - handLeft.Y) < ERROR_RATE_STRETCH) { stretchLeftOK = true; } //checked if the arms are up if (handLeft.Y > head.Y && handRight.Y > head.Y) { up = true; } /*if(VERBOSE) * { * Console.WriteLine("#######################"); * Console.WriteLine("angle left: " + angleLeft); * Console.WriteLine("angle right: " + angleRight); * Console.WriteLine("stretch left: " + Math.Abs(theoreticalYLeft - handLeft.Y)); * Console.WriteLine("stretch right: " + Math.Abs(theoreticalYRight - handRight.Y)); * }*/ if (up && stretchLeftOK && stretchRightOK && angleLeftOK && angleRightOK) { frame = 0; _complete = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } else if (frame > TIME) { frame = 0; if (!up) { _up = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } else if (!stretchLeftOK || !stretchRightOK) { _stretch = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } else if (!angleLeftOK || !angleRightOK) { _spread = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } } }
public void Update(Skeleton sk) { _complete = false; _slow = false; distance = Geometry.distanceSquare(new Point3D(sk.Joints[JointType.HandLeft].Position), new Point3D(sk.Joints[JointType.HandRight].Position)); if (distance < 0.01 && !start) { start = true; down = true; } if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted && _count == 0) { DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Clap " + NB_APPLAUSE.ToString() + " times"; } if (start) { if (_count != 0) { DrawingSheetAvatarViewModel.displayCustomText = _count.ToString(); } if (_count == NB_APPLAUSE) { frames = 0; _count = 0; start = false; down = false; up = false; _complete = true; DrawingSheetAvatarViewModel.displayCustomText = String.Empty; GestureRecognized?.Invoke(this, new EventArgs()); } frames++; //if(frames == 10) { frames = 0; if (down) { if (distance > 0.05) { up = true; down = false; } /*else * { * start = false; * down = false; * count = 0; * _slow = true; * GestureRecognized?.Invoke(this, new EventArgs()); * }*/ } else if (up) { if (distance < 0.01) { down = true; up = false; _count++; GestureRecognized?.Invoke(this, new EventArgs()); } /*else * { * start = false; * up = false; * count = 0; * _slow = true; * GestureRecognized?.Invoke(this, new EventArgs()); * }*/ } } } }