# using DateTime and Stopwatch to calculate velocity ? • ### Question

• Hello,

i'm stuck for days to calculate the velocity of a mouvement so i'll try to more explain my problem.

i have to applicate an approache which allows to detect falls with kinect.

this approche takes as input 3 dimensions of a 3Box, built from the coordinates of skeleton joints.

these dimensions are:

W = |xMin - xMax|;

H = |yMin - yMax|;

D = |zMin - zMax|;

with xMin, xMax, yMin, yMax, zMin, zMax the minimum and the maximum of coordinates in all the tracked joints.

At this point, this is not the problem.. i already calculated all these values:

```        List<Joint> JointList = new List<Joint>();
List<double> JCx = new List<double>();
List<double> JCy = new List<double>();
List<double> JCz = new List<double>();

// define the min and max of coordinates as the filed of view of kinect
private double xMin = 2.2;
private double xMax = -2.2;
private int framecounter = 0;
private double yMin = 1.6;
private double yMax = -1.6;
private double zMin = 4;
private double zMax = 0;

if (first == null) // if no skeleton
{
txtP.Text = "No One";
return;
}

else
{
txtP.Text = "Yes";
skeletonDetected = true;

/// define all joints

Joint SC = first.Joints[JointType.ShoulderCenter];
Joint SL = first.Joints[JointType.ShoulderLeft];
Joint SR = first.Joints[JointType.ShoulderRight];
Joint EL = first.Joints[JointType.ElbowLeft];
Joint ER = first.Joints[JointType.ElbowRight];
Joint WL = first.Joints[JointType.WristLeft];
Joint WR = first.Joints[JointType.WristRight];
Joint HandL = first.Joints[JointType.HandLeft];
Joint HandR = first.Joints[JointType.HandRight];
Joint Spine = first.Joints[JointType.Spine];
Joint HipC = first.Joints[JointType.HipCenter];
Joint HipL = first.Joints[JointType.HipLeft];
Joint HipR = first.Joints[JointType.HipRight];
Joint KL = first.Joints[JointType.KneeLeft];
Joint KR = first.Joints[JointType.KneeRight];
Joint AnkL = first.Joints[JointType.AnkleLeft];
Joint AnkR = first.Joints[JointType.AnkleRight];
Joint FL = first.Joints[JointType.FootLeft];
Joint FR = first.Joints[JointType.FootRight];

// calculate x, y and z coordinates for each joint and
// put it into 3 different lists

foreach (Joint j in JointList)
{
if (j.TrackingState == JointTrackingState.Tracked)

jx = j.Position.X;
jy = j.Position.Y;
jz = j.Position.Z;

foreach (double f in JCx)
{

if (f < xMin)
xMin = f;
else if (f > xMax)
xMax = f;
}

foreach (double f in JCy)
{

if (f < yMin)
yMin = f;
else if (f > yMax)
yMax = f;
}

foreach (double f in JCz)
{

if (f < zMin)
zMin = f;
else if (f > zMax)
zMax = f;

}

}
txtminx.Text = xMin.ToString();
txtmaxx.Text = xMax.ToString();
txtminy.Text = yMin.ToString();
txtmaxy.Text = yMax.ToString();
txtminz.Text = zMin.ToString();
txtmaxz.Text = zMax.ToString();                 //calculate the 3 dimensions of the Box and the diagonal WD                double W = System.Math.Abs(xMin - xMax);                double H = System.Math.Abs(yMin - yMax);                double D = System.Math.Abs(zMin - zMax);                double WD = System.Math.Sqrt(Math.Pow(W0, 2) + Math.Pow(D0, 2));```

The problem is when i have to calculate the velocity of the box dimensions vH and vWD .

vH = (Hi - H0) /(Ti- T0);

vWD = (WDi- WD0) /(Ti-T0);

i tried to use DateTime.UtcNow and Stopwatch to calculate the time spend

```DateTime T0 = DateTime.UtcNow;
Stopwatch _stopwatch = Stopwatch.StartNew();
DateTime Ti = DateTime.UtcNow;```

but i don't know how to get H value in a first time and in a second also  i'm not sure if this methode will give me real result.

Can anyone help me ?

DKF

Monday, July 29, 2013 11:22 AM

### All replies

• I wouldn't bother with a timer, since your application will get ~30fps and every Depth/Color/Skeleton - ImageFrame, already has a timestamp.

ImageFrame Properties
http://msdn.microsoft.com/en-us/library/microsoft.kinect.imageframe_properties.aspx

As long as you are tracking the object per frame, you just need to subtract the timestamps to determine the delta T. Keep in mind, the timestamp value between Depth and Color may not be exactly the same. Using AllFrameReady callback or polling, they should be very close. Using separate callback functions, the difference would be non-deterministic. Whichever frame you use for determining the object detection/location, use the same timestamp value for it.

Carmine Sirignano - MSFT

Monday, July 29, 2013 6:22 PM