0

WPF を使用した kinect の c# での開発を開始しました。

Kinect for Windows Developer Toolkit からサンプル プログラム「colorBasics」を起動すると、カメラは正常に動作しますが、数秒後にフリーズします。

関連するコードをコピーしました(カメラを表示するためのコードのみ)。それは自分のプログラムでも発生します。

私が間違っていることを知っている人はいますか?

エラーは発生しません。

ここにコードがあります

namespace Testapp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

    private KinectSensor sensor;

    private WriteableBitmap colorBitmap;

    private byte[] colorPixels;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        foreach (var potentialSensor in KinectSensor.KinectSensors)
        {
            if (potentialSensor.Status == KinectStatus.Connected)
            {
                this.sensor = potentialSensor;
                break;
            }
        }

        if (null != this.sensor)
        {
            // Turn on the color stream to receive color frames
            this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            // Allocate space to put the pixels we'll receive
            this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];

            // This is the bitmap we'll display on-screen
            this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

            // Set the image we display to point to the bitmap where we'll put the image data
            this.Image.Source = this.colorBitmap;

            // Add an event handler to be called whenever there is new color frame data
            this.sensor.ColorFrameReady += this.SensorColorFrameReady;

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

    private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
        {
            if (colorFrame != null)
            {
                // Copy the pixel data from the image to a temporary array
                colorFrame.CopyPixelDataTo(this.colorPixels);

                // Write the pixel data into our bitmap
                this.colorBitmap.WritePixels(
                    new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                    this.colorPixels,
                    this.colorBitmap.PixelWidth * sizeof(int),
                    0);
            }
        }
    }
}
}
4

2 に答える 2

0

USB ケーブルに何らかの延長を使用していますか、それともマシンに直接接続されていますか? センサーとマシンの間の遅延が長すぎると、あなたが説明していることを見てきました。その場合、Kinect USB ケーブルが延長コードに差し込まれていることが原因でした。

于 2013-01-21T03:10:42.980 に答える
0

ここでも同じ問題があり、カメラは最終的にフリーズして電源が切れるまで機能し、数秒後に戻ってきてフリーズループを繰り返しました。

多くのテストを行った結果、問題の原因は次の 3 つであるという結論に達しました。

  • PC は、コードを実行する必要があるため、高速でも強力でもありません。

  • Kinect が熱くなりすぎています。触って「それほど熱くはない」場合でも、センサーは過熱に非常に敏感です。

  • Kinect が何らかの形で「妨害」されています。これは、物理的な振動や動き、および/または人間に似た画像内のあまりにも多くのものを指すため、ソフトウェアは 30 fps ですべてのフレームでそれを計算しようとします。これは多くの計算であり、この事実は、上記の他の2つの問題。

これにより、Michal が説明した遅延の問題も発生する可能性があります

于 2015-01-29T11:18:25.150 に答える