public bool processConstHandLeftGesture(GestureDatabase gestureDatabase)
        {
            if (gestureDatabase.getTotalSize() > 0)
            {
                if (!isConstLeftHandGestureStarted && indexOfFirstValidConstLeftGestureFrame < 0)
                {
                    bool isCurrentValidStartFrame = isFirstValidGestureFrame(GESTURE.CONST_LEFT, gestureDatabase);
                    if (!isCurrentValidStartFrame)
                    {
                        reset(GESTURE.CONST_LEFT);
                        return false;
                    }
                    isConstLeftHandGestureStarted = true;
                    indexOfFirstValidConstLeftGestureFrame = indexOfLastValidConstLeftGestureFrame = gestureDatabase.getTotalSize() - 1;
                    startTimerConstLeftHand = DateTime.Now;
                    return false;                   // is valid gesture frame , but gesture is still incomplete , so return false.
                }
            }
            else
                return false;

            // check to see if the current frame is a valid frame
            bool isCurrentFrameValid = isIntermediaryFrameValidGestureFrame(GESTURE.CONST_LEFT, gestureDatabase);
            if (!isCurrentFrameValid)
            {
                reset(GESTURE.CONST_LEFT);
                return false;
            }

            // check for nobody movement by comparing frames first and lastvalid frames
            bool isBodyDeflectionValid = isBodyLinearDeflectionsWithInBounds(GESTURE.CONST_LEFT,  gestureDatabase);
            if (!isBodyDeflectionValid)
            {
                reset(GESTURE.CONST_LEFT);
                return false;
            }

               // all conditions satisfied , now check if the gesture has completed , update the indexOfLastValidFrame and Update the time

            indexOfLastValidConstLeftGestureFrame++;
            currentTimerConstLeftHand = DateTime.Now;
            timeElapsedConstLeftHand = new TimeSpan(currentTimerConstLeftHand.Ticks - startTimerConstLeftHand.Ticks);

            if (timeElapsedConstLeftHand.Seconds >= THRESHOLD_TIME_FOR_VALID_GESTURE)
            {
                // valid gesture
                reset(GESTURE.CONST_LEFT);
                return true;
            }
            else
            {
                // gesture in progress and not complete but not an Invalid gesture
                return false;

            }
        }
Beispiel #2
0
        public bool processSwipeLeftGesture(GestureDatabase gestureDatabase)
        {
            // check for a valid start gesture , see if the hands are with in the angle range. Start the gesture if the frame is valid
            if (gestureDatabase.getTotalSize() > 0)
            {
                if (!isSwipeLeftGestureStarted && indexOfFirstValidSwipeLeftFrame < 0)
                {
                    bool isFrameValidSwipeLeftStartFrame = isFirstValidGestureFrame(GESTURE.SWIPE_LEFT, gestureDatabase);
                    if (!isFrameValidSwipeLeftStartFrame)
                    {
                        reset(GESTURE.SWIPE_LEFT);
                        return false;
                    }

                    indexOfFirstValidSwipeLeftFrame = indexOfLastValidSwipeLeftFrame = gestureDatabase.getTotalSize() - 1;
                    isSwipeLeftGestureStarted = true;
                    startSwipeLeftTime = currentSwipeLeftTime = DateTime.Now;
                    return false;
                }

            }
            else
            {
                return false;
            }

            /*
             * <condition>
             *  See if body doesnt move
             * </condition>
            */

            bool isBodyDeflectionValid = isBodyLinearDeflectionWithInBounds(GESTURE.SWIPE_LEFT, gestureDatabase);
            if (!isBodyDeflectionValid)
            {
                // Console.WriteLine("gesture : SWIPE LEFt , invalid isBodyDeflectionValid");
                reset(GESTURE.SWIPE_LEFT);
                return false;
            }

            /*
             * <condition>
             *  See if the intermediary frames are valid for the SWIPE LEFT gesture
             * </condition>
            */
            bool isIntermediaryFrameValid = isIntermediaryFrameValidGestureFrame(GESTURE.SWIPE_LEFT, gestureDatabase);
            if (!isIntermediaryFrameValid)
            {
                // Console.WriteLine("gesture : SWIPE LEFt , invalid isIntermediaryFrameValid");
                reset(GESTURE.SWIPE_LEFT);
                return false;
            }

            /*
             * <condition>
             *  See if the movement of the hand is a valid SWIPE LEFT
             * </condition>
            */

            bool isHandAngularMovementValid = isHandAngularChangeWithInBounds(GESTURE.SWIPE_LEFT, gestureDatabase);
            if (!isHandAngularMovementValid)
            {
                // Console.WriteLine("gesture : SWIPE LEFt , invalid isHandAngularMovementValid");
                reset(GESTURE.SWIPE_LEFT);
                return false;
            }

            /*
            * <condition>
            *  See if the cumulative angle is valid SWIPE LEfT Angle , Counter ClockWise , only at an interval of multiple of 30 frames
            * </condition>
               */

            if (indexOfFirstValidSwipeLeftFrame != indexOfLastValidSwipeLeftFrame && indexOfLastValidSwipeLeftFrame % 30 == 0)
            {
                bool isIntermediaryCumulativeAngleValid = isIntermediaryCumulativeAngularMotionValid(GESTURE.SWIPE_LEFT, gestureDatabase);
                if (!isIntermediaryCumulativeAngleValid)
                {
                    // Console.WriteLine("gesture : SWIPE LEFt , invalid isIntermediaryCumulativeAngleValid");
                    reset(GESTURE.SWIPE_LEFT);
                    return false;
                }
            }

            /*
             * <Update>
             *  All conditions are satified, Update time and angle and check for gesture completion or expiration
             * </Update>
            */
            // Console.WriteLine("\ngesture : SWIPE LEFT , current Angle " + currentSwipeLeftAngle);
            // Console.WriteLine("\ngesture : SWIPE LEFT , current TIme " + swipeLeftTimeSpan.Seconds);
            currentSwipeLeftAngle = updateCurrentAngle(GESTURE.SWIPE_LEFT, gestureDatabase);
            currentSwipeLeftTime = DateTime.Now;
            swipeLeftTimeSpan = new TimeSpan(currentSwipeLeftTime.Ticks - startSwipeLeftTime.Ticks);
            indexOfLastValidSwipeLeftFrame++;

            if ((currentSwipeLeftAngle <=  SWIPE_LEFT_MIN_FINISH_ANGLE - SWIPE_LEFT_MIN_START_ANGLE) &&
                swipeLeftTimeSpan.Seconds >= THRESHOLD_TIME_FOR_VALID_GESTURE)
            {
                // gesture completed
                reset(GESTURE.SWIPE_LEFT);
                return true;
            }
            else if (swipeLeftTimeSpan.Seconds >= THRESHOLD_TIME_FOR_GESTURE_TO_EXPIRE)
            {
                // time over, gesture not completed
                reset(GESTURE.SWIPE_LEFT);
                return false;
            }

            // gesture frames are valid , just that the gesture isn't complete

            return false;
        }
        private bool isBodyLinearDeflectionsWithInBounds(GESTURE gesture , GestureDatabase gestureDatabase)
        {
            if(gesture == GESTURE.CONST_LEFT)
                if (indexOfFirstValidConstLeftGestureFrame < 0)
                    return true;                        // this is the start of the new Gesture, first frame of the new gesture

            if (gesture == GESTURE.CONST_RIGHT)
                if (indexOfFirstValidConstRightGestureFrame < 0)
                    return true;                        // this is the start of the new Gesture, first frame of the new gesture
            int indexOfFirstValidGestureFrame = (gesture == GESTURE.CONST_LEFT) ? indexOfFirstValidConstLeftGestureFrame :
                                                                                  indexOfFirstValidConstRightGestureFrame;

            Skeleton lastValidSkeleton;
            AppropriateJointInfo lastAptInfo;

            Skeleton firstValidSkeleton;
            AppropriateJointInfo firstAptInfo;

            gestureDatabase.getRecord(gestureDatabase.getTotalSize() - 1, out lastValidSkeleton, out lastAptInfo);
            gestureDatabase.getRecord(indexOfFirstValidGestureFrame, out firstValidSkeleton, out firstAptInfo);

            return (isPointWithInThreshold(lastAptInfo.shoulderCenterPos, firstAptInfo.shoulderCenterPos));
        }