2013-07-29 24 views
0

我被困在幾天來計算一個打破的速度,所以我會嘗試更多地解釋我的問題。使用DateTime和秒錶來計算kinect sdk的速度

我必須應用一個允許使用kinect SDK和VS c#來檢測下降的方法。

這個方案以輸入骨骼關節座標構建的3Box三維爲輸入。

這些尺寸是:

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

//計算方塊和對角線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)); 

的3個維度的問題是,當我要計算框尺寸VH和血友病的速度。 (H 1 -H 0)/(T 1 -T 0);其中,V H =(H 1 -H 0)/(T 1 -T 0)。 vWD =(WDi-WD0)/(Ti-T0);其中,VWD =(WDi-WD0)/(Ti-T0)。

我試圖用DateTime.UtcNow和秒錶計算時間花費

​​

,但我不知道如何在第一時間內得到H值爲,並在第二也是我不知道如果這種方法會給我真正的結果。

任何人都可以幫助我嗎?

在此先感謝

回答

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; 
+0

謝謝您的回答弗洛朗, 有人說,只要我」每幀跟蹤對象,我只需要減去時間戳,以確定使用AllFrameReady回調或輪詢的增量T. 我有點困惑什麼使用。 我想我會嘗試兩種解決方案,並告訴你它是否有效。 – user2599324

+0

你能告訴我你是如何定義lastTime的嗎? – user2599324

+0

我更新了我的評論。應該管用。 –