Examples

Detect Persons

The following code block shows an example of how to recognize new persons in the visus of the Kinect.

class Tester
{
    static int personCount = 0;

    static void Main(string[] args)
    {
        Device d = new Device();
        d.NewPerson += NewPerson;
        d.Start();

        Console.ReadLine();
    }

    static void NewPerson(object src, NewPersonEventArgs e)
    {
        Console.WriteLine(++personCount);
    }
}

Detect Gestures

You can register for gestures on persons. A GestureChecker instance in the Person holds care about recognizing the completion of the gesture by its Conditions.

static void NewPerson(object src, NewPersonEventArgs e)
{
    e.Person.OnWave += delegate(object sender, GestureEventArgs args) {
        Console.WriteLine("Person {0} waved.", e.Person.ID);
    };
}

Create Your Own Gestures

Extend a GestureChecker and a Condition. Then instantiate YourGestureChecker in your Person extension YourPerson.

class JumpGestureChecker : GestureChecker
{
    // Gesture exceeds on timeout (not necessary for this simple gesture)
    protected const int CONDITION_TIMEOUT = 2500;

    public JumpGestureChecker(Person p)
        : base(new List<Condition> {

            // List of conditions to be fullfilled in order
            new JumpCondition(p)

        }, CONDITION_TIMEOUT) { }
}

class JumpCondition : Condition
{
    // Helper class for detecting movements over time.
    // All its tasks could be achieved manually over p.GetLastSkeleton(i).GetPosition(t)), etc.
    private Checker _checker;

    public JumpCondition(Person p)
        :base(p)
    {
        _checker = new Checker(p);
    }

    // Here is the main thing. The framework executes this function periodically. Here you can check
    // if the skeletons meets the current part of your gesture. If it does you fire success, if it doesn't
    // you fire fail, if it's neither fail nor success you do nothing. You can chain more complex checks
    // manually here, but you should consider to split it up to seperate conditions.
    protected override void check(object sender, NewSkeletonEventArgs e)
    {
        // Get a list of directions to which the persons hip is moving
        List<Direction> hipDirections = _checker.GetAbsoluteMovement(JointType.HipCenter);
        // Get the hips speed
        double hipSpeed = _checker.GetAbsoluteVelocity(JointType.HipCenter);

        // Check if the hip is moving upwards at a certain speed
        if (hipDirections.Contains(Direction.upward) && hipSpeed > 0.005)
        {
            fireSucceeded(this, null);
        }
    }
}

public class YourPerson extends Person
{
    public Person(Device d)
    {
        JumpGestureChecker jump= new JumpGestureChecker(this);
        jump.Successful += delegate(object o, GestureEventArgs ev)
        {
            if (OnJump != null)
            {
                this.OnJump(this, ev);
            }
        };
    }
}

Last edited Dec 9, 2013 at 12:03 PM by schmijos, version 3

Comments

No comments yet.