Using KinectColorViewer in SDK1.5

痞子三分冷 提交于 2019-12-04 19:16:04

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.

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!