将KinectSensor和/或流传递给线程.. [英] Passing KinectSensor and or streams to threads ..
问题描述
Hey All,
我正在处理我的业余爱好项目,并希望了解如何将KinectSensor传递给多个线程。
Am working on a hobby project of mine and wanted to find out how to pass KinectSensor to multiple threads.
示例尝试下面的内容
Example trying something like below
class Program
{
static AutoResetEvent autoEvent;
static void Main(string[] args)
{
autoEvent = new AutoResetEvent(false);
// Initialize Kinect Sensor and handle all kinds of connect/disconnect scenarios.
Initialize init = new Initialize();
KinectSensor sensor = init.InitializeKinectSensor();
SpeechControl sc = new SpeechControl();
Console.WriteLine("main thread starting worker thread...");
//Now here want to pass sensor to speech control
Thread sct = new Thread(sc.SpeechControlMain(sensor));
sct.Start();
// Now want to pass same sensor to another thread doing gesture recognition
GestrureControl gc = new GestureControl(); Thread gct = new Thread(gc.GestureControlMain(sensor));
gct.start();
}
}
如果我们希望不同的线程处理来自kinect的流数据的不同方面,这将是正确的方法传感器?如果有人能指出我正确的方向/示例代码,将不胜感激。
would this be the right approach if we wanted different threads to be processing different aspects of the stream data from the kinect sensor ? Would be grateful if anyone could point me in the right direction/sample code.
推荐答案
最好让一个线程拥有传感器并调度您将获得要处理数据的其他线程的数据。对于托管环境,您可以传递对KinectSensor的引用,但需要做更多工作以确保您为这些事件订阅/取消订阅
。
It is better to have one thread the owns the sensor and dispatch the data you get to other threads that are going to process the data. For a managed environment, you can pass a reference to the KinectSensor, but more work will be needed to ensure you subscribe/unsubscribe to those events.
查看Kinect Explorer示例,了解如何完成此任务。
Have a look at the Kinect Explorer sample to give you some ideas on how you can accomplish this task.
这篇关于将KinectSensor和/或流传递给线程..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!