-2

I'm trying to create a program using Kinect where watch the user and as output of the program tells the direction where the user is walking.

I mean, if the user is walking forward, the output should be.. UP

0    <=  8 <=        // the user (8) is walking forward  (<=) to the camera (0=kinect)

If the user is walking back, the output should be DOWN. If the user is walking to the left, the output should be LEFT. And the same thing for RIGHT.

Until what I have is:

    private static  KinectSensor kinectSensor;
    static void Main(string[] args)
    {
        kinectSensor = KinectSensor.KinectSensors[0];
        kinectSensor.SkeletonStream.Enable();
        kinectSensor.Start();
        kinectSensor.SkeletonFrameReady += kinectRuntime_SkeletonFrameReady;

        while (true) { }
    }

    private static Skeleton[] data;
    static void kinectRuntime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
        {
            if (skeletonFrame != null)
            {
                if ((data == null) || (data.Length != skeletonFrame.SkeletonArrayLength))
                    data = new Skeleton[skeletonFrame.SkeletonArrayLength];
                skeletonFrame.CopySkeletonDataTo(data);

                foreach (Skeleton ske in data)
                {
                    if (ske.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        var joints = ske.Joints;

                        foreach (Joint joint in ske.Joints)
                        {
                            if (joint.JointType == JointType.HandLeft)
                            {
                                Console.WriteLine(joint.Position.X.ToString(".##"));
                                Console.WriteLine(joint.Position.Y.ToString(".##"));
                                Console.WriteLine(joint.Position.Z.ToString(".##"));
                            }
                        }
                    }
                }
            }
        }
    }

And this just tells you the position of your left hand. I don't know much about Kinect library, so I need a little bit of help to do this.

I've seen post, but I'm still don't get it how this can help me.

Bart
  • 19,692
  • 7
  • 68
  • 77
Darf Zon
  • 6,268
  • 20
  • 90
  • 149
  • 3
    That list of seven closing braces is definitely awkward; maybe convert some of the "guard" `if` statements to early returns rather than falling off the end of the function without doing anything. – sarnold Apr 17 '12 at 00:04
  • possible duplicate of [How to track and follow a person using Kinect?](http://stackoverflow.com/questions/10185043/how-to-track-and-follow-a-person-using-kinect) – Cody Gray - on strike Apr 18 '12 at 01:02

2 Answers2

3

Since all the joints have an X,Y,Z value, detecting Forward and Back (up and down) is as easy as monitoring the Z coordinate of a joint. Detecting Left and Right is as simple as monitoring the X coordinate value. Obviously you'd want a little bit of buffer room since it is hard to expect someone to move exclusively on each axis.

Spine might be a good joint to monitor since the hands will swing when walking. All you would need to do is compare the last 3 or 4 skeleton frames to see what direction the user appears to be moving in and map that to whatever direction you need.

lumberjack4
  • 2,772
  • 4
  • 30
  • 50
1

To check the movement in some direction you need to keep a history of joints for some time. For example last 16 frames from last 0,5 second. If you have that you can analyse direction of the movement comparing actual position of the joint (for example HipCenter) with history. With checking all 3 axis you can say is the user going right, left, forward, backword. Is he jumping or crouching.

To make such history you can create an list of some struct. The struct need to have a timestamp. With the timestamp you can delete entries older then 0,5 sec so you`re list won't grow to much. In every frame you take the list into loop and compare each element with actual position by comparing joint Position

Fixus
  • 4,631
  • 10
  • 38
  • 67