我被困了好几天才能计算出行动的速度,所以我会试着更多地解释我的问题。
我必须应用一个允许使用kinect SDK和VS c#检测跌倒的方法。
这个approche将3Box的3个维度作为输入,从骨架关节的坐标建立。
这些维度是:
W = | xMin - xMax |;
H = | yMin - yMax |;
D = | zMin - zMax |;
xMin,xMax,yMin,yMax,zMin,zMax是所有被跟踪关节中坐标的最小值和最大值。
此时,这不是问题..我已经计算了所有这些值:
List<Joint> JointList = new List<Joint>();
List<double> JCx = new List<double>();
List<double> JCy = new List<double>();
List<double> JCz = new List<double>();
//将坐标的最小值和最大值定义为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);
//计算每个关节的x,y和z坐标 //把它放到3个不同的列表中
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
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的速度时。
vH =(Hi-H0)/(Ti-T0);
vWD =(WD-WD0)/(Ti-T0);
我尝试使用DateTime.UtcNow和Stopwatch来计算时间花费
DateTime T0 = DateTime.UtcNow;
Stopwatch _stopwatch = Stopwatch.StartNew();
DateTime Ti = DateTime.UtcNow;
但我不知道如何在第一次获得H值,而且我也不知道这种方法是否会给我真正的结果。
任何人都可以帮助我吗?
提前致谢
答案 0 :(得分:0)
我在一个应用程序中做了类似的事情。 我在应用程序启动时启动了一个StopWatch:
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
int msNow;
int msPast;
int dif;
TimeSpan currentTime;
TimeSpan lastTime = new TimeSpan(0);
public GaitAnalyzer()
{
stopWatch.Start();
}
然后你必须做这样的事情:
currentTime = stopWatch.Elapsed;
msNow = currentTime.Seconds * 1000 + currentTime.Milliseconds;
if(lastTime.Ticks != 0)
{
msPast = lastTime.Seconds * 1000 + lastTime.Milliseconds;
dif = msNow - msPast;
}
lastTime = currentTime;