none
How to compare skeleton data in SDK? RRS feed

  • Question

  • Dear All,

    I want to compare two skeleton data in SDK using C#. How can I do that?

    For example I want to compare current handright position and position after 1 sec.

    Please help.

    Eagerly waiting for reply.

    Regards,

    Samarth.


    Thursday, March 8, 2012 4:15 AM

Answers

  • Are you using the event callback model or pull mode? If you are using the event model you could try something like this:

    // local variables:
    timer;
    checkState; // possible states save, wait, compare
    
    void SomeInitializeFunction()
    ...
        setup timer with 1 second interval
        checkState = save
    ...
    
    
    callback Tick() function
        checkState = compare
        timeout.Stop
    
    // inside callback
    KinectCallbackFunction()
    ...
    if (checkState == wait)
    {
        // do nothing
        return;
    }
    else if (checkState == save)
    {
        // set the new flag
        checkState = wait;
        timer.Start
        // save data for later
    }
    else if (checkState == compare)
    {
        // compare the data
        checkState = save; //next time around grab a new frame
    } 
    ...
    }

    Tuesday, March 13, 2012 10:20 PM

All replies

  • Hi Samarth,

    If your intention is to find user raising hand (from attention pose),  you can find angle variations between (shoulder-hand) w.r.t. (shoulder-hip) coordinates, within your specified time frame.

    Hope this helps !!!

    Thanks,

    Bharat.

    Thursday, March 8, 2012 12:32 PM
  • Hi Bharat,

    Thanks for your reply.

    How can I find angle variation?

    I referred http://social.msdn.microsoft.com/Forums/en-US/kinectsdknuiapi/thread/8516bab7-c28b-4834-82c9-b3ef911cd1f7

    But how to compare two position after 1 sec? Also share some links for "How to find angle variation?".

    Please help.

    Regards,

    Samarth.


    -Samarth

    Thursday, March 8, 2012 1:54 PM
  • Hi Shah Samarth,

    • You can achieve your requirement in many ways. One of them is angle calculation using simple Math formula as shown. Pass the joint cooridnates of your interest.
     double angleRads = Math.Atan2(y1 - y2, x1 - x2) - Math.Atan2(y1 - y3, x1 - x3);

    Also you can frame 3d vectors with the skeletal joints and find positional differences.

    Simplest, you can use  Z factor to differentiate the positions.

    But how to compare two position after 1 sec?

    • You can set a timer and check the variations with certain criteria to be met.
    • The NUI_SkeletonFrame event runs continously and monitors the skeletal variations. So instead of going with some time lapse differentiation methods, you can implement your action logic in this event.

    Also please check

    http://social.msdn.microsoft.com/Forums/en-US/kinectsdknuiapi/thread/7c51b568-8c93-4555-ba64-71658c7595f8

    http://social.msdn.microsoft.com/Forums/br/kinectsdknuiapi/thread/29cffae6-2147-4303-8739-bb633d961c28

    http://social.msdn.microsoft.com/Forums/nl/kinectsdknuiapi/thread/4a428391-82df-445a-a867-557f284bd4b1

    Hope this helps !!!

    Thanks,

    Bharat.

    Thursday, March 8, 2012 2:51 PM
  • Hi Bharat,

    Thanks. I gain some knowledge from the links. But I am still having problem with "time".

    Basically I created 

    Microsoft.Research.Kinect.Nui.Vector vector1 = new Microsoft.Research.Kinect.Nui.Vector(); // to store current data

    vector1.X = ScaleVector(1024, handright.Position.X);
    vector1.Y = ScaleVector(800, -handright.Position.Y);

    Thread.Sleep(1000); Microsoft.Research.Kinect.Nui.Vector vector4 = new Microsoft.Research.Kinect.Nui.Vector(); // to store data after 1 second

    vector4.X = ScaleVector(1024, handright.Position.X);
    vector4.Y = ScaleVector(800, -handright.Position.Y);

    But seems the thread becomes unresponsive after its execution.

    Data in both vector1 and vector4 are same. Ideally data in vector4 should be position after 1 sec but it is not the case.

    Please help.


    -Samarth http://shahsamarth.wordpress.com

    Thursday, March 8, 2012 4:25 PM
  • Where are you calling this code? Unless you are using the pull model, you should not be calling Sleep() on a callback on the UI thread. The idea is to take a snapshot of the data at one data point, and let things continue until your selected interval elapses and take another sampling of data.

    Friday, March 9, 2012 1:02 AM
  • Where are you calling this code? Unless you are using the pull model, you should not be calling Sleep() on a callback on the UI thread. The idea is to take a snapshot of the data at one data point, and let things continue until your selected interval elapses and take another sampling of data.

    Hi Carmine Si,

    Can you please share your views how can I do that?


    -Samarth http://shahsamarth.wordpress.com

    Friday, March 9, 2012 3:23 PM
  • Are you using the event callback model or pull mode? If you are using the event model you could try something like this:

    // local variables:
    timer;
    checkState; // possible states save, wait, compare
    
    void SomeInitializeFunction()
    ...
        setup timer with 1 second interval
        checkState = save
    ...
    
    
    callback Tick() function
        checkState = compare
        timeout.Stop
    
    // inside callback
    KinectCallbackFunction()
    ...
    if (checkState == wait)
    {
        // do nothing
        return;
    }
    else if (checkState == save)
    {
        // set the new flag
        checkState = wait;
        timer.Start
        // save data for later
    }
    else if (checkState == compare)
    {
        // compare the data
        checkState = save; //next time around grab a new frame
    } 
    ...
    }

    Tuesday, March 13, 2012 10:20 PM