在SDK1.5中使用KinectColorViewer [英] Using KinectColorViewer in SDK1.5

查看:79
本文介绍了在SDK1.5中使用KinectColorViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用Kinect for Windows(sdk 1.5)的项目中使用KinectColorViewer.在kinect资源管理器示例中,KinectColorViewer组件具有绑定的KinectSensorManager组件.在xaml文件中,我们有:

I am trying to use a KinectColorViewer in a project using Kinect for windows (sdk 1.5). In the kinect explorer example, the KinectColorViewer componant had a KinectSensorManager component that is binded. In the xaml file we have:

<kt:KinectColorViewer x:Name="ColorViewer" KinectSensorManager="{Binding KinectSensorManager}" CollectFrameRate="True" RetainImageOnSensorChange="True" />

在其他项目中复制相同的概念时,我遇到很多麻烦.我使用了Microsoft.Kinect.Toolkit的KinectSensorChooser,KinectSensorChooserUI和Mirosoft.Sampels.Kinect.wpfviewers KinectColorViewer.尝试将colorViewer的KinectSensorManager绑定到UI元素,然后进行操作.

I have a lot of trouble reproduccing the same concept in other projects. I have used the Microsoft.Kinect.Toolkit's KinectSensorChooser, KinectSensorChooserUI and the Mirosoft.Sampels.Kinect.wpfviewers KinectColorViewer. Tried to bind the KinectSensorManager of The colorViewer to the UI element and follows.

<my:KinectColorViewer Width="200" Height="200" HorizontalAlignment="Left" Margin="198,12,0,0" Name="kinectColorViewer1" VerticalAlignment="Top" KinectSensorManager="{Binding ElementName=kinectSensorChooserUI1, Path=KinectSensorChooser.Kinect}" />

两次尝试均未成功.有没有人使用新的SDK使用ColorViwer,DepthViwer和SkeletonViewer?认为我们会很棒...

both attempts were unsuccesfull. Has anyone used the ColorViwer, DepthViwer and SkeletonViewer using the new SDK? Figuring that our would be great...

要绑定KinectSensorManager,我在后端添加了以下代码:

To bind the KinectSensorManager, I added the following code to the back end:

public partial class MainWindow : Window
{
  public KinectSensorManager KinectSensorManager { get; set;}
  private void WindowLoaded(object sender, RoutedEventArgs e)
{
  KinectSensorManager = new KinectSensorManager();

  KinectSensorManager.KinectSensorChanged += new EventHandler<KinectSensorManagerEventArgs<KinectSensor>>(KinectSensorManager_KinectSensorChanged);

        // Look through all sensors and start the first connected one.
        // This requires that a Kinect is connected at the time of app startup.
        foreach (var potentialSensor in KinectSensor.KinectSensors)
        {
            if (potentialSensor.Status == KinectStatus.Connected)
            {
                this.sensor = potentialSensor;
                break;
            }
        }

        if (null != this.sensor)
        {
            // Turn on the skeleton stream to receive skeleton frames

            this.sensor.SkeletonStream.Enable();
            this.sensor.DepthStream.Enable();
            this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
            this.sensor.AllFramesReady += new System.EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady);
            this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

            // Start the sensor!
            try
            {
                this.sensor.Start();
            }
            catch (IOException)
            {
                this.sensor = null;
            }

            var kinectSensorBinding = new Binding("KinectSensor") { Source = this.sensor };
            BindingOperations.SetBinding(this.KinectSensorManager, KinectSensorManager.KinectSensorProperty, kinectSensorBinding);

        }

        if (null == this.sensor)
        {
            this.statusBarText.Text = Properties.Resources.NoKinectReady;
        }

    }

和Xaml文件:

<kt:KinectColorViewer Width="191" Height="83" Grid.Column="3" KinectSensorManager="{Binding KinectSensorManager}" HorizontalAlignment="Left" Margin="17,236,0,0" Name="kinectColorViewer1" VerticalAlignment="Top" />

但是我仍然看不到任何颜色流.

but I still dont get any color stream.

推荐答案

您的绑定语句不正确. "KinectSensorChooser.Kinect"是对KinectSensorChooser选择的硬件(即Kinect)的引用-不是KinectSensorManager.

You binding statement is incorrect. "KinectSensorChooser.Kinect" is a reference to hardware (i.e., the Kinect) selected by the KinectSensorChooser -- it is not the KinectSensorManager.

您应该按照示例所示的方式绑定到KinectSensorManager.您要尝试做一些特别的事情,使您以不同的方式绑定它吗?

You should be binding to the KinectSensorManager in the same way the examples show you. Is there something special you are trying to do that would lead you to bind it differently?

您的主班应该从这样的事情开始:

Your main class should start out something like this:

// automatically finds a Kinect for you
private readonly KinectSensorChooser sensorChooser = new KinectSensorChooser();

// the bindable sensor property
public KinectSensorManager KinectSensorManager { get; private set; }

public MainViewModel()
{
    if (IsInDesignMode) {
        // load design mode only content
    }
    else
    {
        // initialize the Kinect sensor manager
        KinectSensorManager = new KinectSensorManager();
        KinectSensorManager.KinectSensorChanged += this.KinectSensorChanged;

        // locate an available sensor
        sensorChooser.Start();

        // bind chooser's sensor value to the local sensor manager
        var kinectSensorBinding =
            new Binding("Kinect") { Source = this.sensorChooser };
        BindingOperations.SetBinding(
            this.KinectSensorManager,
            KinectSensorManager.KinectSensorProperty,
            kinectSensorBinding);
    }
}

#region Kinect Discovery & Setup

private void KinectSensorChanged(object sender,
    KinectSensorManagerEventArgs<KinectSensor> args)
{
    if (null != args.OldValue)  
        UninitializeKinectServices(args.OldValue);

    if (null != args.NewValue)
        InitializeKinectServices(KinectSensorManager, args.NewValue);
}

// Kinect enabled apps should customize which Kinect services it initializes here.
private void InitializeKinectServices(
    KinectSensorManager kinectSensorManager, 
    KinectSensor sensor)
{
    // Application should enable all streams first.

    // configure the color stream
    kinectSensorManager.ColorFormat = 
        ColorImageFormat.RgbResolution640x480Fps30;
    kinectSensorManager.ColorStreamEnabled = true;

    // configure the depth stream
    kinectSensorManager.DepthStreamEnabled = true;

    kinectSensorManager.TransformSmoothParameters = 
        new TransformSmoothParameters
        {
            Smoothing = 0.5f,
            Correction = 0.5f,
            Prediction = 0.5f,
            JitterRadius = 0.05f,
            MaxDeviationRadius = 0.04f
        };

    // configure the skeleton stream
    sensor.SkeletonFrameReady += OnSkeletonFrameReady;
    kinectSensorManager.SkeletonStreamEnabled = true;
}

// Kinect enabled apps should uninitialize all Kinect services that were initialized in InitializeKinectServices() here.
private void UninitializeKinectServices(KinectSensor sensor)
{
    sensor.SkeletonFrameReady -= this.OnSkeletonFrameReady;
}

#endregion Kinect Discovery & Setup

然后您可以从View绑定到管理器,如示例所示.

You can then bind to the manager from your View as shown by the examples.

您还需要通过将以下内容放入构造函数来设置DataContext: DataContext = this;

You make need to also set the DataContext, by putting the following into the constructor: DataContext = this;

这篇关于在SDK1.5中使用KinectColorViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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