本文介绍了使用DateTime和Stopwatch来计算速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好, 

我已经停留了好几天才能计算出行动的速度,所以我会尝试更多地解释我的问题。

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

我必须申请一个允许用kinect检测跌倒的方法。  

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

此approche将3个3Box维度作为输入,从骨架关节的坐标构建。

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

这些维度为:

W = | xMin - xMax |;

W = |xMin - xMax|;

H = | yMin - yMax |;

H = |yMin - yMax|;

D = | zMin - zMax |;

D = |zMin - zMax|;

xMin,xMax,yMin,yMax,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();

//计算Box的3个维度和对角线WD

//calculate the 3 dimensions of the Box and the diagonal WD

double W = System.Math.Abs​​( xMin - xMax);
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; double H = System.Math.Abs​​(yMin - yMax);
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; double D = System.Math.Abs​​(zMin - zMax);
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; double WD = System.Math.Sqrt(Math.Pow(W0,2)+ Math.Pow(D0,2));

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));

问题是我必须计算箱子尺寸vH和vWD的速度。

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

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

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

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

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

我试图使用  DateTime.UtcNow和 秒表来计算时间花费

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;

但我不知道如何在第一个获得H值时间和一秒钟我也不确定这种方法是否会给我真正的结果。

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 

DKF

推荐答案

ImageFrame属性

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

只要你跟踪每帧对象,您只需要减去时间戳来确定增量T.请记住,深度和颜色之间的时间戳值可能不完全相同。使用AllFrameReady回调或轮询,他们
应该非常接近。使用单独的回调函数,差异将是不确定的。 无论您使用哪个框架来确定对象检测/位置,都要使用相同的时间戳值。

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.


这篇关于使用DateTime和Stopwatch来计算速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:51