我正在尝试Get and Display Depth Data in C#并为kinect计算深度采集的fps。
计算实施日期时间的深度的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,但为什么我无限,我做错了什么?
答案 0 :(得分:3)
您必须测量每次调用函数之间的间隔,而不是函数执行所需的时间。像这样:
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)";
}