using DateTime and Stopwatch to calculate velocity ? RRS feed

  • 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; Skeleton first = GetFirstSkeleton(allFramesReadyEventArgs); if (first == null) // if no skeleton { txtP.Text = "No One"; return; } else { txtP.Text = "Yes"; skeletonDetected = true; /// define all joints Joint Head = first.Joints[JointType.Head]; JointList.Add(Head); Joint SC = first.Joints[JointType.ShoulderCenter]; JointList.Add(SC); Joint SL = first.Joints[JointType.ShoulderLeft]; JointList.Add(SL); Joint SR = first.Joints[JointType.ShoulderRight]; JointList.Add(SR); Joint EL = first.Joints[JointType.ElbowLeft]; JointList.Add(EL); Joint ER = first.Joints[JointType.ElbowRight]; JointList.Add(ER); Joint WL = first.Joints[JointType.WristLeft]; JointList.Add(WL); Joint WR = first.Joints[JointType.WristRight]; JointList.Add(WR); Joint HandL = first.Joints[JointType.HandLeft]; JointList.Add(HandL); Joint HandR = first.Joints[JointType.HandRight]; JointList.Add(HandR); Joint Spine = first.Joints[JointType.Spine]; JointList.Add(Spine); Joint HipC = first.Joints[JointType.HipCenter]; JointList.Add(HipC); Joint HipL = first.Joints[JointType.HipLeft]; JointList.Add(HipL); Joint HipR = first.Joints[JointType.HipRight]; JointList.Add(HipR); Joint KL = first.Joints[JointType.KneeLeft]; JointList.Add(KL); Joint KR = first.Joints[JointType.KneeRight]; JointList.Add(KR); Joint AnkL = first.Joints[JointType.AnkleLeft]; JointList.Add(AnkL); Joint AnkR = first.Joints[JointType.AnkleRight]; JointList.Add(AnkR); Joint FL = first.Joints[JointType.FootLeft]; JointList.Add(FL); Joint FR = first.Joints[JointType.FootRight]; JointList.Add(FR); // 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; JCx.Add(jx); jy = j.Position.Y; JCy.Add(jy); jz = j.Position.Z; JCz.Add(jz); 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 ?

    Thanks in advance 


    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

    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