Kinect相机冻结 [英] Kinect camera freeze

查看:110
本文介绍了Kinect相机冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用WPF为kinect开发C#.

I have started developing in c# for the kinect with WPF.

当我从Kinect for Windows Developer Toolkit启动示例程序"colorBasics"时,相机可以正常工作,但是在几秒钟后冻结.

When I start the sample program "colorBasics" from Kinect for Windows Developer Toolkit, the camera works fine, but freezes after a couple of seconds.

我复制了相关代码(因此仅复制了用于查看摄像机的代码),并且它也发生在我自己的程序中.

I copied over the relevant code ( so only the code for viewing the camera ) and it also happens in my own program.

有人知道我在做什么错吗?

Anyone know what I'm doing wrong ?

我没有任何错误.

这是代码

namespace Testapp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

    private KinectSensor sensor;

    private WriteableBitmap colorBitmap;

    private byte[] colorPixels;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        foreach (var potentialSensor in KinectSensor.KinectSensors)
        {
            if (potentialSensor.Status == KinectStatus.Connected)
            {
                this.sensor = potentialSensor;
                break;
            }
        }

        if (null != this.sensor)
        {
            // Turn on the color stream to receive color frames
            this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            // Allocate space to put the pixels we'll receive
            this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];

            // This is the bitmap we'll display on-screen
            this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

            // Set the image we display to point to the bitmap where we'll put the image data
            this.Image.Source = this.colorBitmap;

            // Add an event handler to be called whenever there is new color frame data
            this.sensor.ColorFrameReady += this.SensorColorFrameReady;

            // Start the sensor!
            try
            {
                this.sensor.Start();
            }
            catch (IOException)
            {
                this.sensor = null;
            }
        }
    }

    private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
        {
            if (colorFrame != null)
            {
                // Copy the pixel data from the image to a temporary array
                colorFrame.CopyPixelDataTo(this.colorPixels);

                // Write the pixel data into our bitmap
                this.colorBitmap.WritePixels(
                    new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                    this.colorPixels,
                    this.colorBitmap.PixelWidth * sizeof(int),
                    0);
            }
        }
    }
}
}

推荐答案

这里也有同样的问题,相机一直工作到最后才冻结并关闭电源,几秒钟后又回来了,只是重复了冻结循环.

Had same problem here, camera worked untill eventually just freezed and powered off, coming back after a few seconds only to repeat the freeze loop.

经过多次测试,我的结论是该问题是由三件事引起的:

After many tests, my conclusion is that the issue is caused by three things:

  • PC不能快速/强大地运行代码,而应该运行它.

  • PC is not fast/powerful as it should be to run your code.

Kinect太热了.即使您触摸它并且它不太热",该传感器也对过热非常敏感.

Kinect is getting too hot. Even if you touch it and it's "not so hot", the sensor is very sensitive to overheat.

Kinect受到某种方式的干扰".这是指物理上的振动或运动和/或图像中太多类似于人体的事物,因此软件正在尝试以30fps的每一帧对其进行计算,这是很多微积分,并且这一事实可能导致上面列出的另外两个问题.

The Kinect is being "disturbed" somehow. This refers to vibrations or motion physically and/or too many things in the image that resembles a human, so the soft is trying it to compute it at every frame at 30fps, this is a lot of calculus, and this fact might lead to the two other problems listed above.

这也可能导致Michal描述的延迟问题

This also also may cause the latency issue described by Michal

这篇关于Kinect相机冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆