我试图在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为什么我得到无穷大,但我做错了什么呢?
发布于 2017-03-24 12:28:49
您必须测量每次调用函数之间的间隔,而不是函数执行所需的时间。就像这样:
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)";
}https://stackoverflow.com/questions/42999258
复制相似问题