This project is read-only.

Gesture Speed Limitation

Oct 22, 2013 at 1:36 AM
Hello everybody!

I'm testing swipe gesture detector code available on Kinect.Toolbox solution and on "Programming with the Kinect for Windows Software Development Kit" (David Catuhe) book.

But I want to detect even fasters swipes. Is it possible? If it is, how can I do?
Actually this code works only with limited speed gestures.

Thank you!

(following is the code)
namespace Kinect.Toolbox
{
public class SwipeGestureDetector : GestureDetector
{
    const float SwipeMinimalLength = 0.4f;
    const float SwipeMaximalHeight = 0.2f;
    const float KickMaximalHeight = 1.0f;
    const float KickMinimalLenght = 0.4f;
    const int SwipeMininalDuration = 250;
    const int SwipeMaximalDuration = 1500;

    public SwipeGestureDetector(int windowSize = 20)
        : base(windowSize)
    {

    }

    bool ScanPositions(Func<Vector3, Vector3, bool> heightFunction, Func<Vector3, Vector3, bool> directionFunction, Func<Vector3, Vector3, bool> lengthFunction, int minTime, int maxTime)
    {
        int start = 0;

        for (int index = 1; index < Entries.Count - 1; index++)
        {
            if (!heightFunction(Entries[0].Position, Entries[index].Position) || !directionFunction(Entries[index].Position, Entries[index + 1].Position))
            {
                start = index;
            }

            if (lengthFunction(Entries[index].Position, Entries[start].Position))
            {
                double totalMilliseconds = (Entries[index].Time - Entries[start].Time).TotalMilliseconds;
                if (totalMilliseconds >= minTime && totalMilliseconds <= maxTime)
                {
                    return true;
                }
            }
        }

        return false;
    }

    protected override void LookForGesture()
    {
        // Swipe to right
        if (ScanPositions((p1, p2) => Math.Abs(p2.Y - p1.Y) < SwipeMaximalHeight, // Height
            (p1, p2) => p2.X - p1.X > -0.01f, // Progression to right
            (p1, p2) => Math.Abs(p2.X - p1.X) > SwipeMinimalLength, // Length
            SwipeMininalDuration, SwipeMaximalDuration)) // Duration
        {
            RaiseGestureDetected("SwipeToRight");
            return;
        }

        //Swipe to left
        if (ScanPositions((p1, p2) => Math.Abs(p2.Y - p1.Y) < SwipeMaximalHeight,  // Height
            (p1, p2) => p2.X - p1.X < 0.01f, // Progression to right
            (p1, p2) => Math.Abs(p2.X - p1.X) > SwipeMinimalLength, // Length
            SwipeMininalDuration, SwipeMaximalDuration))// Duration
        {
            RaiseGestureDetected("SwipeToLeft");
            return;
        }