简体   繁体   English

将一个Kinect与两个窗口一起使用

[英]Using one kinect with two windows

I am a very newbie on WPF, C#, and Kinect. 我在WPF,C#,和Kinect 非常新手。 But I've found out how to initialize the kinect, and show two windows. 但是我发现了如何初始化kinect,并显示两个窗口。 My application is a toy one, have a full screen app with a button, when the user clicks, it should open a new window. 我的应用程序是一个玩具,有一个带有按钮的全屏应用程序,当用户单击时,它应该打开一个新窗口。

I've tried but two things won't work: 我已经尝试过,但是有两件事是行不通的:

  • when the new window open the kinect user view won't show any body 当新窗口打开时,kinect用户视图将不显示任何正文
  • when closing the window (going back to the main) the app crashes 当关闭窗口(返回主窗口)时,应用崩溃

The prototype window XAML is like this: 原型窗口XAML如下所示:

<Window ...>
   <k:KinectRegion Name="region_">
      <Grid>
         <k:KinectUserView .../>
      </Grid>
   </k:KinectRegion>
</Window>

On the C# side, I have a prototype class like this: 在C#端,我有一个像这样的原型类:

public partial class MainWindow : Window
{
   public KinectSensor sensor_ = KinectSensor.GetDefault();

   public MainWindow()
   {
      //...
      KinectRegion.SetKinectRegion(this, region_);
      this.sensor_.Open();
   }
}

The secondary page (with identical constructor as above) has a button that calls a function that basically says sensor_.Close() and this.Close() . 辅助页面(具有与上面相同的构造函数)具有一个按钮,该按钮调用一个基本上说sensor_.Close()this.Close()的函数。

Can I use a single kinect with multiple windows? 我可以在多个窗口中使用单个kinect吗? In case not (please tell me I can!) how can I proceed in having two "views"? 如果不能(请告诉我可以!),我该如何进行两次“观看”? Pages AFAIK reading on the web, requite NavigationWindow , and VS complains I cannot add the kinect region to that. 在网上阅读AFAIK的页面,返回NavigationWindow以及VS抱怨我无法向其中添加kinect区域。

Thanks! 谢谢!

It turns out you don't need to close the sensor . 事实证明,您不需要关闭传感器 In order to make more windows work with one sensor: 为了使更多的窗口可以使用一个传感器:

  • pass the KinectSensor initialized in the main one to the "child" window 将在主窗口中初始化的KinectSensor传递到“子”窗口
  • initialize the child's region 初始化孩子的区域

You just need to this.Close() without ever opening again the stream or closing it. 您只需要this.Close()而无需再次打开或关闭流。 The Kinect user view works flawlessly. Kinect用户视图可以完美地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM