2013-11-29 4 views
0

kinect.toolbox와 함께 kinect로 처음 시작합니다. kinect.toolbox 레코더를 kinect SDK v1.8 용 Microsoft 개발자 툴킷과 함께 제공되는 색상 기본 wpf C#와 함께 사용하려고했습니다. 그러나 녹음 시작 버튼을 클릭하면 this answer에서 설명한대로 .recorded 파일이 생성되지 않습니다. 도와 주시겠습니까? 내가 뭘 잘못하고 있는지 말해 주 시겠어요?kinect 도구 상자 레코더로 시동하는 데 문제가 있습니다.

using Kinect.Toolbox.Record; 

namespace Microsoft.Samples.Kinect.ColorBasics 
{ 
    using System; 
    using System.Globalization; 
    using System.IO; 
    using System.Windows; 
    using System.Windows.Media; 
    using System.Windows.Media.Imaging; 
    using Microsoft.Kinect; 

    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     /// <summary> 
     /// Active Kinect sensor 
     /// </summary> 
     private KinectSensor sensor; 
     Stream recordStream; 
     KinectRecorder recorder; 

     /// <summary> 
     /// Bitmap that will hold color information 
     /// </summary> 
     private WriteableBitmap colorBitmap; 

     /// <summary> 
     /// Intermediate storage for the color data received from the camera 
     /// </summary> 
     private byte[] colorPixels; 

     /// <summary> 
     /// Initializes a new instance of the MainWindow class. 
     /// </summary> 
     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     /// <summary> 
     /// Execute startup tasks 
     /// </summary> 
     /// <param name="sender">object sending the event</param> 
     /// <param name="e">event arguments</param> 
     private void WindowLoaded(object sender, RoutedEventArgs e) 
     { 
      // Look through all sensors and start the first connected one. 
      // This requires that a Kinect is connected at the time of app startup. 
      // To make your app robust against plug/unplug, 
      // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). 
      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; 
       } 
      } 

      if (null == this.sensor) 
      { 
       this.statusBarText.Text = Properties.Resources.NoKinectReady; 
      } 
     } 

     /// <summary> 
     /// Execute shutdown tasks 
     /// </summary> 
     /// <param name="sender">object sending the event</param> 
     /// <param name="e">event arguments</param> 
     private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e) 
     { 
      if (null != this.sensor) 
      { 
       this.sensor.Stop(); 
      } 
     } 

     /// <summary> 
     /// Event handler for Kinect sensor's ColorFrameReady event 
     /// </summary> 
     /// <param name="sender">object sending the event</param> 
     /// <param name="e">event arguments</param> 
     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); 
       } 
      } 
     } 

     /// <summary> 
     /// Handles the user clicking on the screenshot button 
     /// </summary> 
     /// <param name="sender">object sending the event</param> 
     /// <param name="e">event arguments</param> 
     private void ButtonScreenshotClick(object sender, RoutedEventArgs e) 
     { 
      if (null == this.sensor) 
      { 
       this.statusBarText.Text = Properties.Resources.ConnectDeviceFirst; 
       return; 
      } 

      // create a png bitmap encoder which knows how to save a .png file 
      BitmapEncoder encoder = new PngBitmapEncoder(); 

      // create frame from the writable bitmap and add to encoder 
      encoder.Frames.Add(BitmapFrame.Create(this.colorBitmap)); 

      string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat); 

      string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); 

      string path = Path.Combine(myPhotos, "KinectSnapshot-" + time + ".png"); 

      // write the new file to disk 
      try 
      { 
       using (FileStream fs = new FileStream(path, FileMode.Create)) 
       { 
        encoder.Save(fs); 
       } 

       this.statusBarText.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.ScreenshotWriteSuccess, path); 
      } 
      catch (IOException) 
      { 
       this.statusBarText.Text = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.ScreenshotWriteFailed, path); 
      } 
     } 

     private void button_Start_Recording(object sender, RoutedEventArgs e) 
     { 
      string generatedName = Guid.NewGuid().ToString(); 
      string recordStreamPathAndName = @"C:\" + generatedName + ".recorded"; 
      this.recordStream = File.Create(recordStreamPathAndName); 
      this.recorder = new KinectRecorder(KinectRecordOptions.Color | KinectRecordOptions.Skeletons, recordStream); 
      button1.IsEnabled = false; 

     } 

     private void button_Stop_Recording(object sender, RoutedEventArgs e) 
     { 
      if (recorder != null) 
      { 
       recorder.Stop(); 
       recorder = null; 
       button1.IsEnabled = true; 
      } 
     } 
    } 
} 

답변

2

나는 당신의 private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e) 방법 this.recorder.Record(colorFrame)에 대한 호출을 볼 수 없습니다 :

다음은 내 코드입니다. 이것을 추가하십시오.

+0

잘 기억한다면 this.recorder.Record() 메서드는 색상, 골격 및 심도 프레임 유형을 허용합니다. – Ewerton

+0

그래, 알았어. 비디오 녹화는 거대한 파일인데, 몇 초 동안 803 메가 비트가. 그 문제를 다루는 어떤 방법이라도? 어떻게 온라인으로 재생할 수있는 형식으로 변환 할 수 있습니까? – ivan

+0

배열 색상 프레임을 알려진 비디오 형식으로 묶으려면 세 번째 파트 도구 (나는 아무도 모른다)를 사용하는 것이 좋습니다. – Ewerton