如何让Kinect仅在特定时间触发所有帧准备事件 [英] How to have Kinect fire all frames ready event only at certain times

查看:80
本文介绍了如何让Kinect仅在特定时间触发所有帧准备事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的wpf应用程序中,我正在记录来自Kinect的数据,但仅限于应用程序的某些点。所有帧就绪事件sensor_ready是收集数据并将其记录到文件中的位置。但是Kinect始终会记录数据,并且它确实会降低所有成本。所以当我不想记录数据的时候,我想我可以关掉这个事件,当我这样做的时候就把它关掉。


我正在使用KinectSensorChooser(变量名为sensorChooser) ,当我在我的代码中输入它时:


sensorChooser.Kinect.AllFramesReady + = sensor_ready;


我得到空引用错误。我可以在KinectStatusChanged事件中订阅该事件,因为我可以输入:


args.NewSensor.Kinect.AllFramesReady + = sensor_ready;


args来自事件论点。但是我不能在代码中的任何其他地方写它,因为args参数是该事件的局部变量。


所以我不知道如何启动和停止事件,所以我也试过这个:我的代码中有一个布尔变量,当我想要从Kinect记录数据时,它设置为true。因此,每当从Kinect收到一个帧时,事件总是运行,但是然后I
在事件处理程序代码中检查该变量是否为真。如果是代码运行,并且没有任何反应,则事件会一直被触发,并且其中的代码不会运行。但由于某种原因,这也不起作用。我认为
也许是因为我设置了布尔错误所以它始终是真的并且总是记录但是我一遍又一遍地检查它并且我认为这不是问题。这个想法应该有用吗? 


你认为我应该尝试其他任何想法/建议吗?


在此之前我做了什么工作,但导致我的程序疯狂地慢和滞后是:每次我想开始和停止记录时启动和停止sensorchooser(使用sensorChooser.start()和sensorChooser.Stop())。但就像我说
我这样做时,应用程序甚至无法使用,所以我需要一个更好的解决方案。


任何输入都表示赞赏。谢谢


解决方案

您在代码中的哪个位置尝试取消订阅/订阅事件?由于sensorChooser正在管理KinectSensor,在您订阅sensorReady事件之前,您必须等待其StatusChanged属性触发,在
之前,然后它是 未知该属性的值。如果您停止或移除传感器,您必须依赖该机制来了解何时可以信任该对象已设置。


为什么不检查是否(se​​nsorChooser) .Kinect!= null)?另外,我们提供api来启用和各自的流。


http://social.msdn.microsoft.com/Forums/en-US/3ca9c548-2c1b-4bc5-934f- fb8ea2f941fd /如何对暂时禁用最Kinect的传感器的相机


Hi,

In my wpf application I'm recording data from the Kinect, but only during certain points of the application. The all frames ready event sensor_ready is where the data is collected and recorded to a file. But the Kinect records data always, and it's really slowing everything down. So I thought I could just turn off the event when I don't want data recorded, on turn it back on when I do.

I'm using the KinectSensorChooser(variable named sensorChooser), and when I type this in my code:

sensorChooser.Kinect.AllFramesReady += sensor_ready;

I get the null reference error. I can subscribe to the event in the KinectStatusChanged event because I can type this:

args.NewSensor.Kinect.AllFramesReady += sensor_ready;

The args come from the event arguments. But I can't write it like this anywhere else in the code because the args arguments are a local variable to that event.

So I don't know how to start and stop the event, so I also tried this: I have a boolean variable in my code that is set to true when I want data recorded from the Kinect. So the event is always run whenever a frame is received from the Kinect, but then I have a check inside the event handler code that checks if the variable is true. If it is the code is run, and otherwise nothing happens, the event just keeps getting fired and the code inside it is not run. But for some reason this doesn't work either. I think maybe it's that I'm setting the boolean wrong so it's always true and always recording but I've checked it over and over and I don't think that's the problem. Should this idea work? 

Do you have any other ideas/suggestions you think I should try?

What I was doing before that does work, but causes my program to go insanely slow and laggy is: start and stop the sensorchooser every time that I want to start and stop recording (using sensorChooser.start() and sensorChooser.Stop()). But like I said when I do this the application is not even usuable so I need a better solution.

Any input is appreciated. Thank you

解决方案

Where in your code are you trying to unsubscribe/subscribe to the event? Since the sensorChooser is managing the KinectSensor, before you can subscribe to the sensorReady event, you have to wait for its StatusChanged property to trigger, before then it is unknown what value this property has. In the event that you stop or remove the sensor, you have to rely on that mechanism to know when you can trust the object is set.

Why are you not checking to see if(sensorChooser.Kinect != null)? Additionally, we provide an api to enable and the respective streams.

http://social.msdn.microsoft.com/Forums/en-US/3ca9c548-2c1b-4bc5-934f-fb8ea2f941fd/how-to-temporarily-disable-the-kinect-sensor-cameras


这篇关于如何让Kinect仅在特定时间触发所有帧准备事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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