Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Kinect SDK中调用方法?_C#_Kinect_Kinect Sdk - Fatal编程技术网

C# 如何在Kinect SDK中调用方法?

C# 如何在Kinect SDK中调用方法?,c#,kinect,kinect-sdk,C#,Kinect,Kinect Sdk,我有一个程序检查Kinect是否连接到计算机。然而,我真的不知道我是否需要调用一个方法(我假设是这样)以及在哪里?我附上了从Kinect入门书中获得的代码。谢谢 using System; using System.Windows; using System.Windows.Controls; using Microsoft.Kinect; namespace test { public partial class MainWindow : Window { p

我有一个程序检查Kinect是否连接到计算机。然而,我真的不知道我是否需要调用一个方法(我假设是这样)以及在哪里?我附上了从Kinect入门书中获得的代码。谢谢

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Kinect;

namespace test
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

    KinectSensor kinectSensor;
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        try
        {
            KinectSensor.KinectSensors.StatusChanged += Kinects_StatusChanged;
            foreach (KinectSensor kinect in KinectSensor.KinectSensors)
            {
                if (kinect.Status == KinectStatus.Connected)
                {
                    kinectSensor = kinect;
                    MessageBox.Show("Connected");
                    break;
                }
            }
            if (KinectSensor.KinectSensors.Count == 0)
                MessageBox.Show("No Kinect Found");
            else
                Initialize();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    void Kinects_StatusChanged(object sender, StatusChangedEventArgs e)
    {
        switch (e.Status)
        {
            case KinectStatus.Connected:
                if (kinectSensor == null)
                {
                    kinectSensor = e.Sensor;
                    Initialize();
                }
                break;
            case KinectStatus.Disconnected:
                if (kinectSensor == e.Sensor)
                {
                    Clean();
                    MessageBox.Show("Kinect was disconnected");
                }
                break;
            case KinectStatus.NotReady:
                break;
            case KinectStatus.NotPowered:
                if (kinectSensor == e.Sensor)
                {
                    Clean();
                    MessageBox.Show("Kinect is not powered anymore.");
                }
                break;
            default:
                MessageBox.Show("Unhandled Status: " + e.Status);
                break;
        }
    }

    private void Initialize()
    {
        if (kinectSensor == null)
            return;
        kinectSensor.Start();
    }

    private void Clean()
    {
        if (kinectSensor != null)
        {
            kinectSensor.Stop();
            kinectSensor = null;
        }
    }

}
}下载。这里有多个关于如何做多种事情的例子,这将帮助您开始并帮助您了解如何与Kinect对话

连接到Kinect后,需要对其进行设置,然后订阅事件回调。您将得到一个如下所示的函数:

private void InitializeKinectServices(KinectSensorManager kinectSensorManager, KinectSensor sensor)
{
    // configure the color stream
    kinectSensorManager.ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;
    kinectSensorManager.ColorStreamEnabled = true;

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

    kinectSensorManager.TransformSmoothParameters =
        new TransformSmoothParameters
        {
            // as the smoothing value is increased responsiveness to the raw data
            // decreases; therefore, increased smoothing leads to increased latency.
            Smoothing = 0.5f,
            // higher value corrects toward the raw data more quickly,
            // a lower value corrects more slowly and appears smoother.
            Correction = 0.5f,
            // number of frames to predict into the future.
            Prediction = 0.5f,
            // determines how aggressively to remove jitter from the raw data.
            JitterRadius = 0.05f,
            // maximum radius (in meters) that filtered positions can deviate from raw data.
            MaxDeviationRadius = 0.04f
        };

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

    // initialize the gesture recognizer
    _gestureController = new GestureController();
    _gestureController.GestureRecognized += OnGestureRecognized;

    kinectSensorManager.KinectSensorEnabled = true;

    if (!kinectSensorManager.KinectSensorAppConflict)
    {
      // additional init
    }
}
这是我的通用设置函数,它基于开发人员工具包中的示例。您将无法将其插入到代码中,它将起作用。通过查看工具箱中的示例,您将了解这种情况在哪里发生,以及如何最好地管理它

KinectExplorer
示例是一个很好的整体项目。它还将使您清楚地了解上述功能是如何工作的(它具有相同的功能)