【问题标题】:kinect data acquiring fps>30kinect数据采集fps>30
【发布时间】:2017-03-24 21:23:43
【问题描述】:

我试图 Get and Display Depth Data in C# 并计算 fps 以获取 kinect 的深度。

为了计算深度的 fps 实现了一个日期时间

  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,但为什么我会变得无穷大,我在做什么错?

【问题讨论】:

  • 由于 AlexDev 给了你一个解决方案,我已经删除了你的问题的答案 “查看你的代码之前和之后的 DateTime 变量都设置为 DateTime.Now - 所以区别秒将为 0。无穷大是除以零的结果。"

标签: c# kinect frame-rate


【解决方案1】:

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

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)";
}

【讨论】:

  • @PaulF TotalSeconds 是双精度数。 msdn.microsoft.com/en-us/library/…。我已根据您的评论编辑了答案,我想我会留下它,因为它可能更准确。
  • 是的 - 我的错误你是对的 - 我正在查看 Seconds 属性,它是一个 int。
  • @AlexDev 在这里使用 double 或 var 会有很大的不同吗?
  • 一点也不。由于 TotalMilliseconds 返回双精度,var milliseconds 将毫秒定义为双精度。
  • @AlexDev 你能帮我理解什么是框架吗?采集(kinect)+ 处理(更改 RGB 值)+ 显示 = 1 帧或处理 + 投影 = 1 帧?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-20
  • 2012-07-15
  • 2019-05-03
  • 2012-02-12
相关资源
最近更新 更多