# How to compare skeleton data in SDK?

• ### 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.

Regards,

Samarth.

Thursday, March 8, 2012 4:15 AM

• 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,

How can I find angle variation?

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

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.

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 datavector1.X = ScaleVector(1024, handright.Position.X);vector1.Y = ScaleVector(800, -handright.Position.Y);

Microsoft.Research.Kinect.Nui.Vector vector4 = new Microsoft.Research.Kinect.Nui.Vector(); // to store data after  1 secondvector4.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.

-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,

-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