kinect数据获取fps>30
kinect data acquiring fps>30
我正在尝试 Get and Display Depth Data in C# 并计算 kinect 深度采集的 fps。
To calculate fps for depth implemented a datetime
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 为什么我会变得无穷大,我在做什么错?
您必须测量每次函数调用之间的时间间隔,而不是函数执行所需的时间。像这样:
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)";
}
我正在尝试 Get and Display Depth Data in C# 并计算 kinect 深度采集的 fps。
To calculate fps for depth implemented a datetime
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 为什么我会变得无穷大,我在做什么错?
您必须测量每次函数调用之间的时间间隔,而不是函数执行所需的时间。像这样:
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)";
}