0

我被困了几天来计算运动的速度,所以我会尝试更多地解释我的问题。

我必须应用一种允许使用 kinect SDK 和 VS c# 检测跌倒的方法。

此方法将 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 = (WDi-WD0) /(Ti-T0);

我尝试使用 DateTime.UtcNow 和 Stopwatch 来计算花费的时间

   DateTime T0 = DateTime.UtcNow;

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

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

谁能帮我 ?

提前致谢

4

1 回答 1

0

我在应用程序中做了类似的事情。我在应用程序启动时启动了秒表:

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;
于 2013-07-29T14:49:21.640 回答