C#WPF-VS中的Kinect和Leap运动数据检索
目标:同时从Leap Motion和Kinect检索数据以进行计算 问题:我可以从kinect和leap运动中获取数据。然而,当跳跃运动读取我手指的坐标时,相机/kinect读数冻结,直到我将手从跳跃运动传感器上移开C#WPF-VS中的Kinect和Leap运动数据检索,c#,wpf,visual-studio-2012,C#,Wpf,Visual Studio 2012,目标:同时从Leap Motion和Kinect检索数据以进行计算 问题:我可以从kinect和leap运动中获取数据。然而,当跳跃运动读取我手指的坐标时,相机/kinect读数冻结,直到我将手从跳跃运动传感器上移开 可能的解决方案:我在想,如果我把它们都放在一个单独的线程上,我应该能够不中断地从两个传感器获取数据。我尝试过很多方法,但都没有成功,有什么想法吗 代码:这是我一直在使用的代码 MainWindow.Xaml.cs Class in WPF Visual Studio namesp
可能的解决方案:我在想,如果我把它们都放在一个单独的线程上,我应该能够不中断地从两个传感器获取数据。我尝试过很多方法,但都没有成功,有什么想法吗 代码:这是我一直在使用的代码
MainWindow.Xaml.cs Class in WPF Visual Studio
namespace KinectLeap
{
public partial class MainWindow
{
/// <summary>
/// Default CTOR
/// </summary>
public MainWindow()
{
MainWindow1 kinect = new MainWindow1(this);
MainWindow2 leapMot = new MainWindow2(this);
// Initialize Components
//InitializeComponent();
kinect.DoWork();
leapMot.DoWork();
//MonitorSample thread = new MonitorSample(this);
//thread.MonitorSampleM();
//Task.Factory.StartNew(kinect.Initialize);
// Initialize Leap Motion
//Task.WaitAll();
//Task.Factory.StartNew(leapMot.InitializeLM);
//Task.WaitAll();
}
public void UpdateKT(Object[] data)
{
}
public void UpdateLM(String[] data)
{
}
}
}
LeapMotion Class to access data from the Leap Motion Sensor
namespace LeapMotion
{
public partial class MainWindow2 : Window, ILeapEventDelegate
{
MainWindow update;
private Controller controller = new Controller();
private LeapEventListener listener;
private Boolean isClosing = false;
/// <summary>
/// Default CTOR
/// </summary>
public MainWindow2(MainWindow thread)
{
update = thread;
//Initialize();
// Initialize Leap Motion
//InitializeLM();
}
public MainWindow2()
{
// TODO: Complete member initialization
}
#region Leap Motion code
// Volatile is used as hint to the compiler that this data
// member will be accessed by multiple threads.
private delegate void NoArgDelegate();
private delegate void OneArgDelegate(String[] arg);
String[] data = new String[8];
public void DoWork()
{
this.controller = new Controller();
this.listener = new LeapEventListener(this);
controller.AddListener(listener);
}
delegate void LeapEventDelegate(string EventName);
public void LeapEventNotification(string EventName)
{
if (this.CheckAccess())
{
switch (EventName)
{
case "onInit":
Debug.WriteLine("Init");
break;
case "onConnect":
this.connectHandler();
break;
case "onFrame":
if (!this.isClosing)
{
this.newFrameHandler(this.controller.Frame());
//Task.Factory.StartNew(() => this.newFrameHandler(this.controller.Frame()));
//Task.WaitAll();
}
break;
case "onDisconnect":
this.onDisconnect();
break;
}
}
else
{
//this.onDisconnect();
Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification), new object[] { EventName });
}
}
void onDisconnect()
{
// this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
// (ThreadStart)delegate()
// {
// Update Leap Motion UI
data[0] = "No hand tracked";
data[1] = "No hand tracked";
data[2] = "No hand tracked";
data[3] = "No hand tracked";
data[4] = "No hand tracked";
data[5] = "No hand tracked";
data[6] = "No hand tracked";
data[7] = "No hand tracked";
update.UpdateLM(data);
// }
// );
}
void connectHandler()
{
this.controller.SetPolicy(Controller.PolicyFlag.POLICY_IMAGES);
this.controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
this.controller.Config.SetFloat("Gesture.Swipe.MinLength", 100.0f);
}
void newFrameHandler(Leap.Frame frame)
{
}
void MainWindow_Closing(object sender, EventArgs e)
{
this.isClosing = true;
this.controller.RemoveListener(this.listener);
this.controller.Dispose();
}
}
#endregion
}
Kinect Class to access data from the Kinect sensor
namespace Kinect
{
public partial class MainWindow1 : Window
{
MainWindow update;
/// <summary>
/// Instance of Kinect sensor
/// </summary>
private KinectSensor _kinect;
/// <summary>
/// Body reader
/// </summary>
public BodyFrameReader _bodyReader;
/// <summary>
/// Collection of all tracked bodies
/// </summary>
public Body[] _bodies;
/// <summary>
/// Requested face features
/// </summary>
private const FaceFrameFeatures _faceFrameFeatures = FaceFrameFeatures.BoundingBoxInInfraredSpace
| FaceFrameFeatures.PointsInInfraredSpace
| FaceFrameFeatures.MouthMoved
| FaceFrameFeatures.MouthOpen
| FaceFrameFeatures.LeftEyeClosed
| FaceFrameFeatures.RightEyeClosed
| FaceFrameFeatures.LookingAway
| FaceFrameFeatures.Happy
| FaceFrameFeatures.FaceEngagement
| FaceFrameFeatures.Glasses;
/// <summary>
/// Face Source
/// </summary>
private FaceFrameSource _faceSource;
/// <summary>
/// Face Reader
/// </summary>
private FaceFrameReader _faceReader;
object[] kdata = new Object[8];
public delegate void NextPrimeDelegate();
/// <summary>
/// Default CTOR
/// </summary>
public MainWindow1(MainWindow thread)
{
update = thread;
//Initialize();
// Initialize Leap Motion
//InitializeLM();
}
public MainWindow1()
{
// TODO: Complete member initialization
}
public void DoWork()
{
// Initialize Components
//update.InitializeComponent();
//this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
// (ThreadStart)delegate()
// {
update.InitializeComponent();
// }
// );
// Initialize Kinect
InitializeKinect();
}
#region CAMERA
#endregion CAMERA
#region Kinect Code
/// <summary>
/// Initialize Kinect
/// </summary>
private void InitializeKinect()
{
//this if statement makes sure that this method is running in a thread
//separate from the main thread.
/*if (Dispatcher.Thread == System.Threading.Thread.CurrentThread)
{
System.Threading.ThreadStart threadStart = new System.Threading.ThreadStart(InitializeKinect);
System.Threading.Thread newThread = new System.Threading.Thread(threadStart);
newThread.Start();
return;
}*/
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
kdata[0] = new Object();
// Get Kinect sensor
_kinect = KinectSensor.GetDefault();
if (_kinect == null) return;
// Initialize Camera
InitializeCamera();
// Initialize body tracking
InitializeBodyTracking();
//Task.Factory.StartNew(_kinect.Open);
//Task.WaitAll();
_kinect.Open();
// Start receiving
//_kinect.Open();
}
#endregion
}
}
WPF Visual Studio中的MainWindow.Xaml.cs类
名称空间KinectLeap
{
公共部分类主窗口
{
///
///默认选择器
///
公共主窗口()
{
MainWindow1 kinect=新的MainWindow1(此);
MainWindow2 leapMot=新的MainWindow2(此);
//初始化组件
//初始化组件();
kinect.DoWork();
leapMot.DoWork();
//MonitorSample线程=新的MonitorSample(此);
//thread.MonitorSampleM();
//Task.Factory.StartNew(kinect.Initialize);
//初始化跳跃运动
//Task.WaitAll();
//Task.Factory.StartNew(leapMot.InitializeLM);
//Task.WaitAll();
}
public void UpdateKT(对象[]数据)
{
}
public void UpdateLM(字符串[]数据)
{
}
}
}
LeapMotion类访问Leap Motion传感器的数据
名称空间跳跃运动
{
公共部分类主窗口2:窗口,ILeapEventDelegate
{
主窗口更新;
专用控制器=新控制器();
私人监听;
私有布尔值isClosing=false;
///
///默认选择器
///
公共主窗口2(主窗口线程)
{
更新=线程;
//初始化();
//初始化跳跃运动
//InitializeLM();
}
公共主窗口2()
{
//TODO:完成成员初始化
}
#区域跳跃运动码
//Volatile用于向编译器提示此数据
//成员将由多个线程访问。
私有委托void NoArgDelegate();
私有委托void OneArgDelegate(字符串[]arg);
字符串[]数据=新字符串[8];
公共工作
{
this.controller=新控制器();
this.listener=新的LeapEventListener(this);
controller.AddListener(监听器);
}
委托无效LeapEventDelegate(字符串EventName);
公共void LeapEventNotification(字符串EventName)
{
if(this.CheckAccess())
{
开关(EventName)
{
案例“onInit”:
Debug.WriteLine(“Init”);
打破
案例“onConnect”:
这个.connectHandler();
打破
案例“onFrame”:
如果(!this.isClosing)
{
this.newFrameHandler(this.controller.Frame());
//Task.Factory.StartNew(()=>this.newFrameHandler(this.controller.Frame());
//Task.WaitAll();
}
打破
案例“onDisconnect”:
this.onDisconnect();
打破
}
}
其他的
{
//this.onDisconnect();
Invoke(新的LeapEventDelegate(LeapEventNotification),新对象[]{EventName});
}
}
void onDisconnect()
{
//this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
//(ThreadStart)委托()
// {
//更新跳跃动作界面
数据[0]=“无手动跟踪”;
数据[1]=“无手动跟踪”;
数据[2]=“无手动跟踪”;
数据[3]=“无手动跟踪”;
数据[4]=“无手动跟踪”;
数据[5]=“无手动跟踪”;
数据[6]=“无手动跟踪”;
数据[7]=“无手动跟踪”;
update.UpdateLM(数据);
// }
// );
}
void connectHandler()
{
this.controller.SetPolicy(controller.PolicyFlag.POLICY_映像);
this.controller.enableShipt(手势.GestureType.TYPE\u滑动);
this.controller.Config.SetFloat(“signature.Swipe.MinLength”,100.0f);
}
void newFrameHandler(Leap.Frame)
{
}
无效主窗口关闭(对象发送器、事件参数)
{
this.isClosing=true;
this.controller.RemovelListener(this.listener);
this.controller.Dispose();
}
}
#端区
}
用于访问来自Kinect传感器的数据的Kinect类
命名空间Kinect
{
公共部分类MainWindow1:窗口
{
主窗口更新;
///
///Kinect传感器实例
///
专用kinect传感器_kinect;
///
///身体读取器
///
公共BodyFrameReader\u bodyReader;
///
///收集所有被追踪的尸体
///
公共机构[]_机构;
///
///请求的面部特征
///
private const FaceFrameFeatures\u FaceFrameFeatures=FaceFrameFeatures.BoundingBoxInInfraredSpace