2013-01-17 157 views
0

我已經開始在c#中爲WPF開發kinect。Kinect相機凍結

當我從Windows開發工具包的Kinect啓動示例程序「colorBasics」時,相機工作正常,但在幾秒鐘後凍結。

我複製了相關的代碼(所以只有查看相機的代碼),它也發生在我自己的程序中。

任何人都知道我在做什麼錯了?

我沒有收到任何錯誤。

這裏是您在使用任何類型的擴展名與USB電纜的代碼

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); 
      } 
     } 
    } 
} 
} 
+0

描述的延遲問題,什麼是你的系統規格?您是否在使用Kinect for Windows或Xbox?你的USB控制器是什麼? –

+0

我使用的是windows的kinect,可以這樣做嗎? – Arcade

+0

它不應該是原因。你的系統規格是什麼?你插入什麼類型的USB控制器?這些可能會導致這個問題。 –

回答

0

,或者直接插入機器?當傳感器和機器之間的延遲時間過長時,我已經看到了你所描述的情況。在這種情況下,它是由Kinect USB電纜插入延長線引起的。

+0

它直接插入。但在第二次重新啓動後,它似乎不會再發生。它很奇怪,因爲我不希望在應用程序被實時使用時發生這種情況。 – Arcade

+0

好吧,所以我想我們剩下的是一個消除的過程。由於其他人可以運行該示例,因此這對我來說可能是某些硬件的問題。這是一種痛苦,但是您能夠:a)嘗試使用您的機器和不同的Kinect傳感器b)使用不同的機器嘗試使用相同的傳感器? –

0

這裏有同樣的問題,相機工作,直到最終只是凍結和關機,幾秒鐘後回來,只重複凍結循環。

多次測試後,我的結論是,這個問題是由三個因素引起:

  • PC並不快/強大,因爲它應該是運行代碼。

  • Kinect太熱了。即使你觸摸它,但它「不太熱」,傳感器對過熱非常敏感。

  • Kinect以某種方式「受到干擾」。這是指圖像中的物理和/或太多物體中的振動或運動類似於人,所以軟正在試圖在每幀30fps處計算它,這是很多微積分,並且這可能導致上面列出的兩個其他問題。

這也可能導致由米哈爾