0

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;
        }
    }

}

}

4

1 に答える 1

1

Kinect for Windows 開発者ツールキット をダウンロードします。そこには、複数のことを行う方法に関する複数の例があり、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例は、全体を見渡すのに適したプロジェクトです。また、上記の機能がどのように機能するかを明確に理解できます (機能は同じです)。

于 2012-12-04T16:10:00.593 に答える