首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态数据采集fps>30

动态数据采集fps>30
EN

Stack Overflow用户
提问于 2017-03-24 12:14:51
回答 1查看 353关注 0票数 1

我试图在C#中获取和显示深度数据和计算fps的深度获取的kinect。

若要计算深度实现日期时间的fps,请执行

代码语言:javascript
复制
  if (this.sensor != null)
  {
      this.sensor.DepthFrameReady += this.DepthImageReady;
  }

  private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e)
  {
     DateTime before = DateTime.Now;
      using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
      {
          if (depthFrame != null)
          {
              depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
          }
          else
          {
              // depthFrame is null because the request did not arrive in time
          }
      }
     DateTime after = DateTime.Now;
     TimeSpan result = after.Subtract(before);
        float seconds = (float)result.TotalSeconds;
        this.Text = "Kinect (" + (1 / seconds) + "fps)";

  }

,我得到了>60 fps和难以置信的无穷大,有时

kinect给出30 fps为什么我得到无穷大,但我做错了什么呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-24 12:28:49

您必须测量每次调用函数之间的间隔,而不是函数执行所需的时间。就像这样:

代码语言:javascript
复制
static DateTime lastFrame = DateTime.Now;
private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e)
{
    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
    {
        if (depthFrame != null)
        {
            depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
        }
        else
        {
            // depthFrame is null because the request did not arrive in time
        }
    }
    var now = DateTime.Now;
    TimeSpan result = now.Subtract(lastFrame);
    lastFrame = now;
    var milliseconds = result.TotalMilliseconds;

    this.Text = "Kinect (" + (1000.0 / milliseconds) + "fps)";
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42999258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档