Exemplo n.º 1
0
        public void Update(Skeleton sk)
        {
//            _distance = Geometry.distanceSquare(new Point3D(sk.Joints[JointType.HandLeft].Position), new Point3D(sk.Joints[JointType.HandRight].Position));

            Point3D leftpos   = new Point3D(sk.Joints[JointType.HipLeft].Position);
            Point3D rightpos  = new Point3D(sk.Joints[JointType.HipRight].Position);
            Point3D hipcentre = new Point3D(sk.Joints[JointType.HipCenter].Position);
            Point3D shoulder  = new Point3D(sk.Joints[JointType.ShoulderCenter].Position);

            if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted)
            {
                DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Keep your hands close to the hips";
            }

            _distance = shoulder.Z - hipcentre.Z;

            leftpos.X  = leftpos.X + (leftpos.X - rightpos.X);
            leftpos.Y  = leftpos.Y + (leftpos.Y - rightpos.Y);
            leftpos.Z  = leftpos.Z + (leftpos.Z - rightpos.Z);
            rightpos.X = rightpos.X + (rightpos.X - leftpos.X);
            rightpos.Y = rightpos.Y + (rightpos.Y - leftpos.Y);
            rightpos.Z = rightpos.Z + (rightpos.Z - leftpos.Z);

            if (Geometry.distanceSquare(new Point3D(sk.Joints[JointType.HandLeft].Position), leftpos) < 0.03 &
                Geometry.distanceSquare(new Point3D(sk.Joints[JointType.HandRight].Position), rightpos) < 0.03)
            {
                if (GestureRecognized != null)
                {
                    DrawingSheetAvatarViewModel.displayCustomText = String.Empty;
                    GestureRecognized(this, new EventArgs());
                }
            }
        }
Exemplo n.º 2
0
        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());
                }
            }
        }
Exemplo n.º 3
0
        public void Update(Skeleton sk)
        {
            double errorGap;
            double errorGap2;

            _slow     = false;
            _dropped  = false;
            _complete = false;
            goodjob   = false;
            elbows    = false;
            slow      = false;

            /*
             *      You can write a gesture as a set of nested if-statements. The outer condition is the broadest and triggers the gesture recognition
             *      process. Then you have a series of nested conditions each one more specific than the previous one.
             *      If a particular condition fails, you exit with GestureRecognised and set a boolen variable to tell the avatar training where it failed
             *      The innermost condition is the correct gesture and exits with bool complete = true
             */

            if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted)
            {
                DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Welcome the crowd";
            }

            errorGap  = Math.Sqrt(Geometry.distanceSquare(new Point3D(sk.Joints[JointType.ShoulderCenter].Position), new Point3D(sk.Joints[JointType.ShoulderLeft].Position)));
            errorGap2 = 3 * errorGap / 4;
            if (Math.Abs(sk.Joints[JointType.ShoulderLeft].Position.Y - sk.Joints[JointType.ElbowLeft].Position.Y) < errorGap2 &&
                Math.Abs(sk.Joints[JointType.ElbowLeft].Position.Y - sk.Joints[JointType.HandLeft].Position.Y) < errorGap2 &&
                Math.Abs(sk.Joints[JointType.ShoulderRight].Position.Y - sk.Joints[JointType.ElbowRight].Position.Y) < errorGap2 &&
                Math.Abs(sk.Joints[JointType.ElbowRight].Position.Y - sk.Joints[JointType.HandRight].Position.Y) < errorGap2)
            {
                distance = Math.Sqrt(Geometry.distanceSquare(new Point3D(sk.Joints[JointType.HandLeft].Position), new Point3D(sk.Joints[JointType.HandRight].Position)));
                frames++;
                if (distance < errorGap)
                {
                    goodjob  = false;
                    elbows   = false;
                    slow     = false;
                    start    = true;
                    prevdist = distance;
                    //armsWideEvent(null, new LongFeedback("WELCOME START!", true));
                }

                /*else if (distance < 5 * errorGap && start)
                 * {
                 *  if ((distance - prevdist) > 0.01 * errorGap)
                 *  {
                 *      prevdist = distance;
                 *      //armsWideEvent(null, new LongFeedback("WELCOME CONTINUES!", true));
                 *  }
                 *  else
                 *  {
                 *      goodjob = false; elbows = false;
                 *      start = false;
                 *      _slow = true;
                 *      slow = true;
                 *      //armsWideEvent(null, new LongFeedback("WELCOME FAILED!", true));
                 *      if (GestureRecognized != null)
                 *      {
                 *          GestureRecognized(this, new EventArgs());
                 *      }
                 *  }
                 * }*/
                else if (frames > 180)
                {
                    frames  = 0;
                    goodjob = false;
                    elbows  = false;
                    start   = false;
                    _slow   = true;
                    slow    = true;
                    //armsWideEvent(null, new LongFeedback("WELCOME FAILED!", true));
                    if (GestureRecognized != null)
                    {
                        DrawingSheetAvatarViewModel.displayCustomText = String.Empty;
                        GestureRecognized(this, new EventArgs());
                    }
                }
                else if (distance > errorGap * 4.5 && start)
                {
                    //armsWideEvent(null, new LongFeedback("WELCOME COMPLETE!", true));
                    frames    = 0;
                    goodjob   = true;
                    _complete = true;
                    start     = false;
                    if (GestureRecognized != null)
                    {
                        DrawingSheetAvatarViewModel.displayCustomText = String.Empty;
                        GestureRecognized(this, new EventArgs());
                    }
                }
            }
            else
            {
                if (start)
                {
                    //armsWideEvent(null, new LongFeedback("WELCOME: DROPPED ELBOW!", true));
                    frames   = 0;
                    start    = false;
                    _dropped = true; elbows = true;
                    if (GestureRecognized != null)
                    {
                        DrawingSheetAvatarViewModel.displayCustomText = String.Empty;
                        GestureRecognized(this, new EventArgs());
                    }
                }
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
 public TrainingWithAvatarView()
 {
     InitializeComponent();
     instance         = this;
     this.DataContext = TrainingWithAvatarViewModel.Get();
 }
Exemplo n.º 6
0
        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());
                }
            }
        }
Exemplo n.º 7
0
        public void Update(Skeleton skeleton)
        {
            //Test if the software recognize a part of the movement on the left side
            GesturePartResult resultLEFT = _segments[_currentSegment].Update(skeleton, LEFT);
            //Test if the software recognize a part of the movement on the right side
            GesturePartResult resultRIGHT = _segments[_currentSegment].Update(skeleton, RIGHT);
            GesturePartResult result      = GesturePartResult.Failed;

            if (TrainingWithAvatarViewModel.Get().SkeletonList != null && TrainingWithAvatarViewModel.canBeInterrupted)
            {
                DrawingSheetAvatarViewModel.displayCustomText = "Your turn ! Wave your hand";
            }

            //If the user is doing the movement with his left arm
            if (resultLEFT == GesturePartResult.Succeeded)
            {
                //If he wasnt's doing it with his left arm before
                if (currentWaveSide != LEFT)
                {
                    //We reset the counters to detect the movement
                    Reset();
                    currentWaveSide = LEFT;
                }
                //We indicate that one of the part of the gesture has been recognized
                result = GesturePartResult.Succeeded;
            }
            //If the user is doing the movement with his right arm
            if (resultRIGHT == GesturePartResult.Succeeded)
            {
                //If he wasnt's doing it with his right arm before
                if (currentWaveSide != RIGHT)
                {
                    //We reset the counters to detect the movement
                    Reset();
                    currentWaveSide = RIGHT;
                }
                //We indicate that one of the part of the gesture has been recognized
                result = GesturePartResult.Succeeded;
            }

            if (result == GesturePartResult.Succeeded)
            {
                //If the movement as not been recognized entirely
                if (_currentSegment + 1 < _segments.Length)
                {
                    //We advance to the next part of the mouvement and reset the number of frame the user had to do this part of the gesture
                    _currentSegment++;
                    _frameCount = 0;
                    _frameGesture++;
                }
                else
                {
                    //If the gesture has been recognized, we throw the event
                    if (GestureRecognized != null)
                    {
                        DrawingSheetAvatarViewModel.displayCustomText = String.Empty;
                        GestureRecognized(this, new EventArgs());
                        Reset();
                    }
                }
            }
            //If the user took too much time to do the nextpart of the gesture
            else if (_frameCount == WINDOW_SIZE)
            {
                //We erset the recognition
                Reset();
            }
            else
            {
                //We keep counting the nuber of frame to do the entire movement
                if (_currentSegment != 0)
                {
                    _frameGesture++;
                }
                _frameCount++;
            }
        }
Exemplo n.º 8
0
        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());
                         * }*/
                    }
                }
            }
        }