Ejemplo n.º 1
0
        private bool isIntermediaryFrameValidGestureFrame(GESTURE gesture, GestureDatabase gestureDatabase)
        {
            Skeleton currentSkeleton;
            AppropriateJointInfo currentAptJointInfo;

            gestureDatabase.getLastRecord(out currentSkeleton, out currentAptJointInfo);

            switch (gesture)
            {
                case GESTURE.SWIPE_RIGHT:
                    {
                        HCI580_Geometry.Vector2D currentElbowShoulder = new HCI580_Geometry.Vector2D((currentAptJointInfo.shoulderRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                                                              (currentAptJointInfo.shoulderRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

                        HCI580_Geometry.Vector2D currentElbowHand = new HCI580_Geometry.Vector2D((currentAptJointInfo.handRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                                                          (currentAptJointInfo.handRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

                        // check if hand Y > elbow Y , angle between elbowShoulder and elbowHand negative
                        if (currentAptJointInfo.handRightPos.Y > currentAptJointInfo.elbowRightPos.Y &&
                            currentElbowShoulder.cpsign(currentElbowHand) < 0)
                        {

                            return true;

                        }
                    }
                    break;
                case GESTURE.SWIPE_LEFT:
                    {
                        HCI580_Geometry.Vector2D currentElbowShoulder = new HCI580_Geometry.Vector2D((currentAptJointInfo.shoulderRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                                                              (currentAptJointInfo.shoulderRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

                        HCI580_Geometry.Vector2D currentElbowHand = new HCI580_Geometry.Vector2D((currentAptJointInfo.handRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                                                          (currentAptJointInfo.handRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

                        // check if hand Y > elbow Y , angle between elbowShoulder and elbowHand negative
                        if (currentAptJointInfo.handRightPos.Y > currentAptJointInfo.elbowRightPos.Y &&
                            currentElbowShoulder.cpsign(currentElbowHand) < 0)
                        {
                            return true;
                        }
                    }
                    break;

            }
            return false;
        }
Ejemplo n.º 2
0
        private double updateCurrentAngle(GESTURE gesture , GestureDatabase gestureDatabase)
        {
            double diffAngle = 0.0;

            Skeleton lastSkeleton;
            AppropriateJointInfo lastAptJointInfo;

            Skeleton lastValidSkeleton;
            AppropriateJointInfo lastValidAptJointInfo;

            int indexOfLastValidGesture = (gesture == GESTURE.SWIPE_RIGHT) ?
                                           indexOfLastValidSwipeRightFrame :
                                           indexOfLastValidSwipeLeftFrame;

            // compare the current frame with the last valid swipe right frame
            gestureDatabase.getLastRecord(out lastSkeleton, out lastAptJointInfo);
            gestureDatabase.getRecord(indexOfLastValidGesture, out lastValidSkeleton, out lastValidAptJointInfo);

            HCI580_Geometry.Vector2D lastElbowShoulder = new HCI580_Geometry.Vector2D(
                                                           (lastAptJointInfo.shoulderRightPos.X - lastAptJointInfo.elbowRightPos.X),
                                                           (lastAptJointInfo.shoulderRightPos.Y - lastAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastElbowHand = new HCI580_Geometry.Vector2D(
                                                           (lastAptJointInfo.handRightPos.X - lastAptJointInfo.elbowRightPos.X),
                                                           (lastAptJointInfo.handRightPos.Y - lastAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastValidElbowShoulder = new HCI580_Geometry.Vector2D(
                                                           (lastValidAptJointInfo.shoulderRightPos.X - lastValidAptJointInfo.elbowRightPos.X),
                                                           (lastValidAptJointInfo.shoulderRightPos.Y - lastValidAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastValidElbowHand = new HCI580_Geometry.Vector2D(
                                                           (lastValidAptJointInfo.handRightPos.X - lastValidAptJointInfo.elbowRightPos.X),
                                                           (lastValidAptJointInfo.handRightPos.Y - lastValidAptJointInfo.elbowRightPos.Y));

            diffAngle = lastElbowShoulder.angleTo(lastElbowHand) - lastValidElbowShoulder.angleTo(lastValidElbowHand);

            // Console.WriteLine("diff Angle " +  diffAngle);
            diffAngle = (gesture == GESTURE.SWIPE_RIGHT) ? (diffAngle < 0 ? 0 : diffAngle) : (diffAngle > 0 ? 0 : diffAngle);

            // both the angles need to be added , as the diff angle will be negative for left swipes.
            return ((gesture == GESTURE.SWIPE_RIGHT) ? this.currentSwipeRightAngle + diffAngle : this.currentSwipeLeftAngle + diffAngle);
        }
Ejemplo n.º 3
0
        // check for too fast and opposite movements
        private bool isHandAngularChangeWithInBounds(GESTURE gesture , GestureDatabase gestureDatabase)
        {
            Skeleton lastSkeleton;
            AppropriateJointInfo lastAptJointInfo;

            Skeleton lastValidSkeleton;
            AppropriateJointInfo lastValidAptJointInfo;

            int indexOfLastValidGesture = (gesture == GESTURE.SWIPE_RIGHT) ?
                                           indexOfLastValidSwipeRightFrame :
                                           indexOfLastValidSwipeLeftFrame;

            if (indexOfLastValidGesture < 0)
            {
                return true;
            }
            // compare the current frame with the last valid swipe right frame
            gestureDatabase.getLastRecord(out lastSkeleton , out lastAptJointInfo);
            gestureDatabase.getRecord(indexOfLastValidGesture , out lastValidSkeleton , out lastValidAptJointInfo);

            HCI580_Geometry.Vector2D lastElbowShoulder = new HCI580_Geometry.Vector2D(
                                                           (lastAptJointInfo.shoulderRightPos.X - lastAptJointInfo.elbowRightPos.X) ,
                                                           (lastAptJointInfo.shoulderRightPos.Y - lastAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastElbowHand = new HCI580_Geometry.Vector2D(
                                                           (lastAptJointInfo.handRightPos.X - lastAptJointInfo.elbowRightPos.X),
                                                           (lastAptJointInfo.handRightPos.Y - lastAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastValidElbowShoulder = new HCI580_Geometry.Vector2D(
                                                           (lastValidAptJointInfo.shoulderRightPos.X - lastValidAptJointInfo.elbowRightPos.X),
                                                           (lastValidAptJointInfo.shoulderRightPos.Y - lastValidAptJointInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D lastValidElbowHand  = new HCI580_Geometry.Vector2D(
                                                           (lastValidAptJointInfo.handRightPos.X - lastValidAptJointInfo.elbowRightPos.X),
                                                           (lastValidAptJointInfo.handRightPos.Y - lastValidAptJointInfo.elbowRightPos.Y));

            if (Math.Abs(lastElbowShoulder.angleTo(lastElbowHand) - lastValidElbowShoulder.angleTo(lastValidElbowHand)) > MAX_RATE_OF_ANGLE_CHANGE)
            {
                // Console.WriteLine("angle change too fast");
                return false;       // moving too fast
            }

            // Console.WriteLine("last frame Angle " + lastElbowShoulder.angleTo(lastElbowHand) + " last Valid Frame Angle " + lastValidElbowShoulder.angleTo(lastValidElbowHand) +
            //                             " difference " + (lastElbowShoulder.angleTo(lastElbowHand) - lastValidElbowShoulder.angleTo(lastValidElbowHand)));
            switch (gesture)
            {
                case GESTURE.SWIPE_RIGHT:
                    {

                        /*
                         *  we are getting only the magnitude of the angles here, so swipe right opposite is moving from larger angle to smaller angle
                         */

                        if (lastElbowShoulder.angleTo(lastElbowHand) - lastValidElbowShoulder.angleTo(lastValidElbowHand) <= -THRESHOLD_OPPOSITE_ANGLE)
                        {
                            // Console.WriteLine("Gesture : SWIPE RIGHT , OPPOSITE MOTION ....");
                            return false;
                        }

                    }
                    break;
                case GESTURE.SWIPE_LEFT:
                    {
                        if (lastElbowShoulder.angleTo(lastElbowHand) - lastValidElbowShoulder.angleTo(lastValidElbowHand) >= THRESHOLD_OPPOSITE_ANGLE)
                        {
                            // Console.WriteLine("Gesture : SWIPE LEFT , OPPOSITE MOTION ....");
                            return false;
                        }

                    }
                    break;
            }

            return true;
        }
Ejemplo n.º 4
0
        private bool isIntermediaryCumulativeAngularMotionValid(GESTURE gesture, GestureDatabase gestureDatabase)
        {
            Skeleton currentSkeleton;
            AppropriateJointInfo currentAptInfo;
            Skeleton firstValidSkeleton;
            AppropriateJointInfo firstValidAptInfo;
            int indexOfFirstValidMotion;

            indexOfFirstValidMotion =   (gesture == GESTURE.SWIPE_RIGHT) ?
                                        indexOfFirstValidSwipeRightFrame :
                                        indexOfFirstValidSwipeLeftFrame;

            gestureDatabase.getLastRecord(out currentSkeleton, out currentAptInfo);
            gestureDatabase.getRecord(indexOfFirstValidMotion,out firstValidSkeleton , out firstValidAptInfo);

            HCI580_Geometry.Vector2D currentElbowShoulder = new HCI580_Geometry.Vector2D((currentAptInfo.shoulderRightPos.X - currentAptInfo.elbowRightPos.X),
                                                                                         (currentAptInfo.shoulderRightPos.Y - currentAptInfo.elbowRightPos.Y));
            HCI580_Geometry.Vector2D currentElbowHand =     new HCI580_Geometry.Vector2D((currentAptInfo.handRightPos.X - currentAptInfo.elbowRightPos.X),
                                                                                         (currentAptInfo.handRightPos.Y - currentAptInfo.elbowRightPos.Y));

            HCI580_Geometry.Vector2D firstElbowShoulder = new HCI580_Geometry.Vector2D((firstValidAptInfo.shoulderRightPos.X - firstValidAptInfo.elbowRightPos.X),
                                                                                        (firstValidAptInfo.shoulderRightPos.Y - firstValidAptInfo.elbowRightPos.Y));
            HCI580_Geometry.Vector2D firstElbowHand = new HCI580_Geometry.Vector2D((firstValidAptInfo.handRightPos.X - firstValidAptInfo.elbowRightPos.X),
                                                                                         (firstValidAptInfo.handRightPos.Y - firstValidAptInfo.elbowRightPos.Y));

            double diffAngle =  currentElbowShoulder.angleTo(currentElbowHand) - firstElbowShoulder.angleTo(firstElbowHand);
            // Console.WriteLine("cumulative  diff " + diffAngle);
            return (gesture == GESTURE.SWIPE_RIGHT) ? (diffAngle > 0 ? true : false) : (diffAngle < 0 ? true : false);
        }
Ejemplo n.º 5
0
        private bool isFirstValidGestureFrame(GESTURE gesture , GestureDatabase gestureDatabase)
        {
            Skeleton skeleton;
            AppropriateJointInfo aptJointInfo;

            gestureDatabase.getLastRecord(out skeleton ,out aptJointInfo);

            switch(gesture)
            {
                case GESTURE.SWIPE_RIGHT:
                    {
                        HCI580_Geometry.Vector2D elbowShoulder = new HCI580_Geometry.Vector2D((aptJointInfo.shoulderRightPos.X - aptJointInfo.elbowRightPos.X),
                                                                                              (aptJointInfo.shoulderRightPos.Y - aptJointInfo.elbowRightPos.Y));

                        HCI580_Geometry.Vector2D elbowHand = new HCI580_Geometry.Vector2D((aptJointInfo.handRightPos.X - aptJointInfo.elbowRightPos.X),
                                                                                          (aptJointInfo.handRightPos.Y - aptJointInfo.elbowRightPos.Y));

                        // check if hand Y > elbow Y , hand X < elbow X and angle between elbowShoulder and elbowHand negative
                        if(aptJointInfo.handRightPos.Y > aptJointInfo.elbowRightPos.Y &&
                           aptJointInfo.handRightPos.X < aptJointInfo.elbowRightPos.X &&
                           elbowShoulder.cpsign(elbowHand) < 0)
                        {
                            return true;
                        }
                    }
                    break;

                case GESTURE.SWIPE_LEFT:
                    {
                        HCI580_Geometry.Vector2D elbowShoulder = new HCI580_Geometry.Vector2D((aptJointInfo.shoulderRightPos.X - aptJointInfo.elbowRightPos.X),
                                                                                              (aptJointInfo.shoulderRightPos.Y - aptJointInfo.elbowRightPos.Y));

                        HCI580_Geometry.Vector2D elbowHand = new HCI580_Geometry.Vector2D((aptJointInfo.handRightPos.X - aptJointInfo.elbowRightPos.X),
                                                                                          (aptJointInfo.handRightPos.Y - aptJointInfo.elbowRightPos.Y));

                        // check if hand Y > elbow Y , hand X < elbow X and angle between elbowShoulder and elbowHand negative
                        if(aptJointInfo.handRightPos.Y > aptJointInfo.elbowRightPos.Y &&
                           aptJointInfo.handRightPos.X > aptJointInfo.elbowRightPos.X &&
                           elbowShoulder.cpsign(elbowHand) < 0)
                        {
                            return true;
                        }
                    }
                    break;

            }
            return false;
        }
Ejemplo n.º 6
0
        /*
         * doc: The function takes the first valid gesture frame ,depending upon what the gesture is, and currently added
         *      and compares the shouldercenter position , which is representative of the body , accross these frames to
         *      check for out of range body movements
         */
        private bool isBodyLinearDeflectionWithInBounds(GESTURE gesture ,  GestureDatabase gestureDatabase)
        {
            Skeleton firstValidSkeleton;
            AppropriateJointInfo firstValidAptInfo;
            Skeleton currentSkeleton;
            AppropriateJointInfo currentAptInfo;

            int indexOfFirstValidGesture = (gesture == GESTURE.SWIPE_LEFT) ?
                                            indexOfFirstValidSwipeLeftFrame :
                                            indexOfFirstValidSwipeRightFrame;

            if(indexOfFirstValidGesture < 0)
                return true;

            gestureDatabase.getLastRecord(out currentSkeleton, out currentAptInfo);                           // last added frame
            gestureDatabase.getRecord(indexOfFirstValidGesture , out firstValidSkeleton , out firstValidAptInfo);       // first valid frame

            // difference between joint positions of shouldercenter in currently added and first valid gesture frame
            return isJointDelectionValid(currentAptInfo.shoulderCenterPos, firstValidAptInfo.shoulderCenterPos);
        }
        private bool isIntermediaryFrameValidGestureFrame(GESTURE gesture, GestureDatabase gestureDatabase)
        {
            Skeleton currentSkeleton;
            AppropriateJointInfo currentAptJointInfo;

            gestureDatabase.getLastRecord(out currentSkeleton, out currentAptJointInfo);

            Vector2D currentElbowShoulder = new Vector2D((currentAptJointInfo.shoulderRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                                     (currentAptJointInfo.shoulderRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

            Vector2D currentElbowHand = new Vector2D((currentAptJointInfo.handRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                         (currentAptJointInfo.handRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

            double angle = currentElbowShoulder.angleTo(currentElbowHand);

            switch (gesture)
            {
                case GESTURE.CONST_LEFT:
                    {

                        if (currentAptJointInfo.shoulderCenterPos.Y > currentAptJointInfo.handRightPos.Y &&
                           currentAptJointInfo.shoulderCenterPos.Y > currentAptJointInfo.elbowRightPos.Y &&
                           currentAptJointInfo.handRightPos.X < currentAptJointInfo.elbowRightPos.X &&
                           currentElbowShoulder.cpsign(currentElbowHand) > 0 &&
                           angle >= CONST_LEFT_GESTURE_MIN_THETA - THRESHOLD_ANGLE_DEFLECTION &&
                           angle <= CONST_LEFT_GESTURE_MAX_THETA + THRESHOLD_ANGLE_DEFLECTION)
                        {
                            return true;
                        }

                    }
                    break;

                case GESTURE.CONST_RIGHT:
                    {
                        if (
                          currentAptJointInfo.shoulderCenterPos.Y > currentAptJointInfo.elbowRightPos.Y &&
                          currentAptJointInfo.elbowRightPos.Y > currentAptJointInfo.handRightPos.Y &&
                          currentAptJointInfo.handRightPos.X > currentAptJointInfo.elbowRightPos.X &&
                          currentElbowShoulder.cpsign(currentElbowHand) < 0 &&
                          angle >= CONST_RIGHT_GESTURE_MIN_THETA - THRESHOLD_ANGLE_DEFLECTION &&
                          angle <= CONST_RIGHT_GESTURE_MAX_THETA + THRESHOLD_ANGLE_DEFLECTION)
                        {
                            return true;
                        }
                    }
                    break;
            }

            return false;
        }
        private bool isIntermediaryCumulativeAngleDeflectionValid(GESTURE gesture ,  GestureDatabase gestureDatabase)
        {
            Skeleton firstValidSkeleton;
            AppropriateJointInfo firstValidAptJointInfo;
            Skeleton currentSkeleton;
            AppropriateJointInfo currentAptJointInfo;

            int indexOfFirstValidGestureFrame = (gesture == GESTURE.CONST_LEFT) ?
                                                 indexOfFirstValidConstLeftGestureFrame :
                                                 indexOfFirstValidConstRightGestureFrame;

            gestureDatabase.getLastRecord(out currentSkeleton , out currentAptJointInfo);
            gestureDatabase.getRecord(indexOfFirstValidGestureFrame, out firstValidSkeleton , out firstValidAptJointInfo);

            Vector2D currentElbowShoulder = new Vector2D((currentAptJointInfo.shoulderRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                         (currentAptJointInfo.shoulderRightPos.Y - currentAptJointInfo.elbowRightPos.Y));
            Vector2D currentElbowHand = new Vector2D((currentAptJointInfo.handRightPos.X - currentAptJointInfo.elbowRightPos.X),
                                                         (currentAptJointInfo.handRightPos.Y - currentAptJointInfo.elbowRightPos.Y));

            Vector2D firstElbowShoulder = new Vector2D((firstValidAptJointInfo.shoulderRightPos.X - firstValidAptJointInfo.elbowRightPos.X),
                                                         (firstValidAptJointInfo.shoulderRightPos.Y - firstValidAptJointInfo.elbowRightPos.Y));
            Vector2D firstElbowHand = new Vector2D((firstValidAptJointInfo.handRightPos.X - firstValidAptJointInfo.elbowRightPos.X),
                                                         (firstValidAptJointInfo.handRightPos.Y - firstValidAptJointInfo.elbowRightPos.Y));

            double angularDeflection = Math.Abs(currentElbowShoulder.angleTo(currentElbowHand) - firstElbowShoulder.angleTo(firstElbowHand));

            if (angularDeflection <= THRESHOLD_ANGLE_DEFLECTION)
                return true;

            return false;
        }
        private bool isHandAngleDeflectionWithInBounds(GESTURE gesture, GestureDatabase gestureDatabase)
        {
            Skeleton skeleton;
            AppropriateJointInfo aptJoint;

            switch (gesture)
            {
                case GESTURE.CONST_LEFT:
                    {
                        gestureDatabase.getLastRecord(out skeleton, out aptJoint);
                        Vector2D elbowShoulder = new Vector2D(aptJoint.shoulderRightPos.X - aptJoint.elbowRightPos.X, aptJoint.shoulderRightPos.Y - aptJoint.elbowRightPos.Y);
                        Vector2D elbowHand = new Vector2D(aptJoint.handRightPos.X - aptJoint.elbowRightPos.X, aptJoint.handRightPos.Y - aptJoint.elbowRightPos.Y);

                        if (elbowShoulder.cpsign(elbowHand) > 0 &&
                            elbowShoulder.angleTo(elbowHand) >= CONST_LEFT_GESTURE_MIN_THETA - THRESHOLD_ANGLE_DEFLECTION &&
                            elbowShoulder.angleTo(elbowHand) <= CONST_LEFT_GESTURE_MAX_THETA + THRESHOLD_ANGLE_DEFLECTION)
                        {
                            return true;
                        }
                        break;
                    }
                case GESTURE.CONST_RIGHT:
                    {
                        gestureDatabase.getLastRecord(out skeleton, out aptJoint);
                        Vector2D elbowShoulder = new Vector2D(aptJoint.shoulderRightPos.X - aptJoint.elbowRightPos.X, aptJoint.shoulderRightPos.Y - aptJoint.elbowRightPos.Y);
                        Vector2D elbowHand = new Vector2D(aptJoint.handRightPos.X - aptJoint.elbowRightPos.X, aptJoint.handRightPos.Y - aptJoint.elbowRightPos.Y);

                        if (elbowShoulder.cpsign(elbowHand) < 0 &&
                            elbowShoulder.angleTo(elbowHand) >= CONST_RIGHT_GESTURE_MIN_THETA - THRESHOLD_ANGLE_DEFLECTION &&
                            elbowShoulder.angleTo(elbowHand) <= CONST_RIGHT_GESTURE_MAX_THETA + THRESHOLD_ANGLE_DEFLECTION)
                        {
                            return true;
                        }
                        break;
                    }
            }
            return false;
        }