Kinect 2快速手柄框架 - >低fps率

时间:2015-04-01 11:11:14

标签: c# kinect frame-rate

当我使用kinect 2的示例颜色基础并计算每个图像之间的毫秒时间时,它通常约为30ms,但是当我将函数图像事件的内部代码更改为注释时,帧之间的时间是:

34,231,32,33,134,32,266,32,33,172,67,166,28,64,33,101,32,33,34,32,32,138,94,32,26

依此类推(少于20 fps)。

我的电脑使用i7(8次治疗), cpu只有6%,8GB内存..所以这不是问题。

相关代码:

public partial class MainWindow : Window, INotifyPropertyChanged
    {
        /// <summary>
        /// Active Kinect sensor
        /// </summary>
        private KinectSensor kinectSensor = null;

        /// <summary>
        /// Reader for color frames
        /// </summary>
        private ColorFrameReader colorFrameReader = null;

        /// <summary>
        /// Bitmap to display
        /// </summary>
        private WriteableBitmap colorBitmap = null;

        /// <summary>
        /// Current status text to display
        /// </summary>
        private string statusText = null;

        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            // get the kinectSensor object
            this.kinectSensor = KinectSensor.GetDefault();

            // open the reader for the color frames
            this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();

            // wire handler for frame arrival
            this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;

            // create the colorFrameDescription from the ColorFrameSource using Bgra format
            FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);

            // create the bitmap to display
            this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);

            // set IsAvailableChanged event notifier
            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            // open the sensor
            this.kinectSensor.Open();

            // set the status text
            this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;

            // use the window object as the view model in this simple example
            this.DataContext = this;

            // initialize the components (controls) of the window
            this.InitializeComponent();

            sw.Start();
        }

        Stopwatch sw = new Stopwatch();
        /// <summary>
        /// Handles the color frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
        {
            System.Console.WriteLine(sw.ElapsedMilliseconds);
            sw.Restart();
            // ColorFrame is IDisposable

            // Changed into comment here:

            /*using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
            {
                if (colorFrame != null)
                {
                    FrameDescription colorFrameDescription = colorFrame.FrameDescription;

                    using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
                    {
                        this.colorBitmap.Lock();

                        // verify data and write the new color frame data to the display bitmap
                        if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight))
                        {
                            colorFrame.CopyConvertedFrameDataToIntPtr(
                                this.colorBitmap.BackBuffer,
                                (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
                                ColorImageFormat.Bgra);

                            this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight));
                        }

                        this.colorBitmap.Unlock();
                    }
                }
            }*/
        }
    }

为什么以及如何解决它?

1 个答案:

答案 0 :(得分:0)

当我&#34;花费&#34;在这个功能上有足够的时间它完美地工作:

for (int i = 0 ; i < 1000000; i++);

我不记得我是否使用了1 mil或10 mil迭代的循环(并且它依赖于计算机),但在使用之后我几乎总是每30ms帧。

它看起来像是微软在kinect 2上的一个错误,它们的最后一个sdk版本 - 2.0(它是它们的第一个)。

注意:使用thread.sleap无法解决问题。

所以现在解决方案(但非常糟糕)是检查运行时间(如果它太快)并在需要时花费时间。