Kinect Region第一次没有检测到用户 [英] Kinect Region not detecting user after the first time

查看:105
本文介绍了Kinect Region第一次没有检测到用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf应用程序,在主窗口中进行舞蹈游戏,当它完成后,第二个窗口打开,用户被问到那里的问题。有一个kinect区域,他们通过使用推动选择运动来回答。第一轮
问题有效(通常,有时它没有),然后应用程序返回到主窗口。当它下次打开第二个窗口时,kinect区域不再检测到用户手。 (它已经检测到奇怪的时间,它只是非常罕见)

I have a wpf application, where a dance game takes place in the main window, and when it's finished a second window opens and the user is asked question there. There is a kinect region and they answer by using the push to select motion. The first round of questions works (usually, sometimes it doesn't), then the application goes back to the main window. When it opens the second window the next time, the kinect region doesn't detect the users hand anymore. (It has detected it the odd time, it's just very rare)

我的班级中有以下代码:(sensorChooserUi是xaml中的kinectsensorchooserUi)

I have the following code in my class: (sensorChooserUi is the kinectsensorchooserUi in the xaml)

private void StartKinect()

        {

            sensorChooser = new KinectSensorChooser();

            sensorChooser.KinectChanged + = SensorChooserOnKinectChanged;

            sensorChooserUi.KinectSensorChooser = sensorChooser;

            sensorChooser.Start();

            sensorChooser.Kinect.Start();

        }


        private void SensorChooserOnKinectChanged(object sender,KinectChangedEventArgs args)

        {

            bool error = false;

            if(args.OldSensor!= null)

            {

               试试
                {

                    args.OldSensor.DepthStream.Range = DepthRange.Default;

                    args.OldSensor.SkeletonStream.EnableTrackingInNearRange = false;

                    args.OldSensor.DepthStream.Disable();

                    args.OldSensor.SkeletonStream.Disable();

                }¥b $ b                catch(InvalidOperationException)

                {

                   错误= true;

                }¥b $ b            }


            if(args.NewSensor!= null)

            {

               试试
                {

                    args.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);

                    args.NewSensor.SkeletonStream.Enable();

                }¥b $ b                catch(InvalidOperationException)

                {

                   错误= true;

                }¥b $ b            }¥b $ b            if(!error)

                kinectRegion.KinectSensor = args.NewSensor;

        }

private void StartKinect()
        {
            sensorChooser = new KinectSensorChooser();
            sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
            sensorChooserUi.KinectSensorChooser = sensorChooser;
            sensorChooser.Start();
            sensorChooser.Kinect.Start();
        }

        private void SensorChooserOnKinectChanged(object sender, KinectChangedEventArgs args)
        {
            bool error = false;
            if (args.OldSensor != null)
            {
                try
                {
                    args.OldSensor.DepthStream.Range = DepthRange.Default;
                    args.OldSensor.SkeletonStream.EnableTrackingInNearRange = false;
                    args.OldSensor.DepthStream.Disable();
                    args.OldSensor.SkeletonStream.Disable();
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
            }

            if (args.NewSensor != null)
            {
                try
                {
                    args.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                    args.NewSensor.SkeletonStream.Enable();
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
            }
            if (!error)
                kinectRegion.KinectSensor = args.NewSensor;
        }

用户按下按钮返回主窗口后,我有以下内容:

After the user pushes the button to go back to the main window I have the following:

            sensorChooser.Kinect.Stop();

            this.Close();

            sensorChooser.Kinect.Stop();
            this.Close();

该类中还有其他代码,这只是与Kinect相关的所有代码。

There's other code in the class, this is just all the code related to the Kinect.

我希望有人可能知道为什么它不起作用。特别是因为它有时会这样(我已经测试了很多,并且我说它每10次中有1次起作用)

I'm hoping somebody might have an idea for why it doesn't work. Especially because it sometimes does (I've tested it a lot, and I'd say it works 1 out of every 10 times)







推荐答案

如果您使用多个窗口并在这些窗口之间导航,您可能会遇到垃圾收集器如何运行的问题。如果在一个窗口上实例化sensorChooser并卸载它,那么当该对象被删除时是不确定的。如果您
正在创建新实例,那么您将面临关闭一个窗口与KinectSensor何时可用于新窗口之间事件的风险。

If you are using multiple windows and navigating between those, you may have an issue with how the Garbage Collector is running. If you instantiate the sensorChooser on one window and unload that, when that object gets removed is non-deterministic. If you are creating new instances, then you run the risk of how the events between closing one window and when the KinectSensor is available for the new Window.

您不应该在您的应用程序中导航时必须停止传感器。应在所有页面上使用相同的KinectSensor / Chooser实例。可以在"交互图库"示例中找到此示例。这是Windows for WPF开发之间
类/对象共享的高级主题..

You shouldn't have to stop the sensor when navigating in your application. The same instance of the KinectSensor/Chooser should be used on all pages. Example of this can be found in the Interaction Gallery sample. This is more of an advanced topic for class/object sharing between Windows for WPF development..


这篇关于Kinect Region第一次没有检测到用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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