一段时间后,Kinect没有触发MultiSourceFrameArrived事件 [英] Kinect is not firing MultiSourceFrameArrived event after some time

查看:156
本文介绍了一段时间后,Kinect没有触发MultiSourceFrameArrived事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用Kinect v2和EmguCV。我正在对获取的帧执行一些图像处理任务。我注意到经过一段时间(1-2分钟)后,Kinect没有触发MultiSourceFrameArrived事件。

I am using Kinect v2 with EmguCV in my application. I am performing some image processing task on the acquired frame. I noticed that after some time (1-2 minutes) the Kinect is not firing MultiSourceFrameArrived event.

下面是代码的片段 -

Below is the snippet of the code-

public partial class KinectForm : Form
{
    KinectSensor kinect;
    MultiSourceFrameReader reader;
    CoordinateMapper coordinateMapper;

    public KinectForm()
    {
        kinect = KinectSensor.GetDefault();// Get the connected kinect Sensor
        coordinateMapper = this.kinect.CoordinateMapper;
        reader = kinect.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth);
        kinect.Open();// Start reading the data from kinect
        InitializeComponent();
    }

    private void FrameArrivedDisplayMode(object sender, MultiSourceFrameArrivedEventArgs e)
    {
        var reference = e.FrameReference.AcquireFrame(); // Get a reference to the arrived frame
        ColorFrame colorFrame = reference.ColorFrameReference.AcquireFrame(); // Access color frame
        DepthFrame depthFrame = reference.DepthFrameReference.AcquireFrame(); // Access depth frame
        if (colorFrame != null && depthFrame != null)// Do not proceed, if any frame is expired
        {
            RenderColorPixels(colorFrame);
            RenderDepthPixels(depthFrame);

            // Lots of image processing is being performed here

            if (colorFrame != null) colorFrame.Dispose();
            if (depthFrame != null) depthFrame.Dispose();
        }
    }

    private void KinectForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (this.reader != null)
        {
            this.reader.Dispose();
            this.reader = null;
        }
        if (this.kinect != null)
        {
            this.kinect.Close();
            this.kinect = null;
        }
    }

    private void displayModeRadioButton_CheckedChanged(object sender, EventArgs e)
    {
        if (displayModeRadioButton.Checked)
            reader.MultiSourceFrameArrived += FrameArrivedDisplayMode;
        else
            reader.MultiSourceFrameArrived -= FrameArrivedDisplayMode;
    }
}

上面的代码工作得比较早,但后来我在数据上添加了更多处理,事件发生了一段时间后根本没有被解雇。

The above code was working earlier, but later on once I added more processing on the data, the event was not fired at all after some point of time.

我每次都处理这个框架。为什么会这样?如何解决这个问题?

I am disposing the frame every time. Why this is happening? How to fix this problem?

-

谢谢

推荐答案

" //需要多长时间?这里正在进行大量的图像处理"?
由于在处理帧之前会发生这种情况,因此从获取到释放时的任何延迟都会增加运行时认为可以保留帧的时间。如果您的图像处理需要很长时间,那么您需要复制数据并创建自己的线程进行处理,这是一个符号
。这也应该独立于回调,以允许UI线程响应其他事件。

How long is it taking to "// Lots of image processing is being performed here"? Since that is happening before you dispose of the frames, any delay from when you acquire to release add to the amount of time the runtime deems that you can hold onto the frame for. If your image processing is taking a long time, then that is a sign you need to copy the data and create your own thread for processing. This should be independent of the callback as well, to allow the UI thread to be responsive to other events.


这篇关于一段时间后,Kinect没有触发MultiSourceFrameArrived事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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