首页 文章

比秒表更准确的计时器?

提问于
浏览
0

我正在尝试使用秒表开始和停止记录Kinect的位置:

//process x and y coordinates
   public void calculateJoints(Skeleton skeleton)
    {          
        Joint rightHand = skeleton.Joints[JointType.HandRight];
        Joint leftHand = skeleton.Joints[JointType.HandRight];
        rightX = rightHand.Position.X;
        rightY = rightHand.Position.Y;         

    }

//start the stopwatch (tried to use a greater time between positions 1 and 5 vs 1 and 2
  public void processJointsAndRepeat(Skeleton skeleton)
  {
        startTime();
        while (numPositions < 5)
        {   
             calculateJoints(skeleton);
             numPositions++;
        }
        stopTime();
        double tempTime = calculateTimeElapsed();
  }

   //calculate time in milliseconds
   private double calculateTimeElapsed()
    {
        long milliseconds = stopWatch.ElapsedMilliseconds;
        return (double)milliseconds;
    }

但是每当我尝试将时间值作为键放入x,y和time值时,它会为重复键引发错误 . 当我检索tempTime的值时,它只显示0 .

这是我的代码的问题,还是我需要更精确的秒表?

我意识到获得30 fps的时间很难,所以如果你有任何其他建议,那就太好了!我基本上只是想计算点之间的平均速度来调整音频文件的播放速度 . 谢谢!

1 回答

  • 1

    秒表是在常规Windows盒子上使用higerst分辨率的计时器包装 . 通过使用Stopwatch.ElapsedTicksStopwatch.Frequency,您可以使用较少的花哨功能来获得比MS分辨率更高的功能 .

    请注意,您的问题可能与计时器无关,而是与您未显示的其他一些代码有关...

相关问题