none
How to save video (color and irDA) from the new Kinect for Windows in Visual Studio 2010? RRS feed

  • Question

  • Hello. I have a question on the new Kinect for Windows and VS 2010.

    In the "MainWindow" of the program I have the color video and IR stream from the kinect, then I would like to save these video (color and IR - only 30 seconds 640x480 in *.avi) in a specific folder (with a particular name for the two videos). Can you help me? Thanks. 

    P.S. Maybe the problem is the record of two videos in the same time.


    • Edited by Steppy89 Tuesday, April 10, 2012 9:23 AM
    Tuesday, April 10, 2012 9:22 AM

All replies

  • For each camera you a have a strem of data. Can`t you just put into an avi file and save it ?

    Just a simple thought :)

    Tuesday, April 10, 2012 9:26 AM
  • ok... I don't know how to save videos from the kinect with VS2010, for the moment I just need one (ex. Color video).
    Tuesday, April 10, 2012 9:36 AM
  • Do you know how to get the stream of rgb camera ?

    Do you know how to create a file (normal, empty file) ?

    Tuesday, April 10, 2012 10:21 AM
  • No. I don't know how to get the stream of rgb camera and I don't  know how to create a file (normal, empty file).
    Tuesday, April 10, 2012 10:47 AM
  • Hmm so you have a big problem :)

    First of all visit: http://channel9.msdn.com/Series/KinectQuickstart Here you`ll find the basics about diffrent streams. I`ve started from that and I must say that this videos are very usefull. 

    Then I recomend to visit this: http://msdn.microsoft.com/en-us/library/as2f1fez.aspx

    You`ll find here how to create a file in C#. Combine this and I think you`ll achive what you need. 

    Tuesday, April 10, 2012 10:58 AM
  • Thanks a lot. :)

    Can I tell you another problem? :)

    I have these two codes:

    1) Depth Image

    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Microsoft.Kinect;

    namespace KinectDepthApplication2
    {
        public partial class MainWindow : Window
        {
            //Instantiate the Kinect runtime. Required to initialize the device.
            //IMPORTANT NOTE: You can pass the device ID here, in case more than one Kinect device is connected.
            KinectSensor sensor = KinectSensor.KinectSensors.First();
            short[] pixelData;

            public MainWindow()
            {
                InitializeComponent();

                //Runtime initialization is handled when the window is opened. When the window
                //is closed, the runtime MUST be unitialized.
                this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
                this.Unloaded += new RoutedEventHandler(MainWindow_Unloaded);

                sensor.DepthStream.Enable();
                sensor.DepthFrameReady += new EventHandler<DepthImageFrameReadyEventArgs>(sensor_DepthFrameReady);
            }

            void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
            {
                bool receivedData = false;

                using (DepthImageFrame DFrame = e.OpenDepthImageFrame())
                {
                    if (DFrame == null)
                    {
                        // The image processing took too long. More than 2 frames behind.
                    }
                    else
                    {
                        pixelData = new short[DFrame.PixelDataLength];
                        DFrame.CopyPixelDataTo(pixelData);
                        receivedData = true;
                    }
                }

                if (receivedData)
                {
                    BitmapSource source = BitmapSource.Create(640, 480, 96, 96,
                            PixelFormats.Gray16, null, pixelData, 640 * 2);

                    depthImage.Source = source;
                }
            }

            void MainWindow_Unloaded(object sender, RoutedEventArgs e)
            {
                sensor.Stop();
            }

            void MainWindow_Loaded(object sender, RoutedEventArgs e)
            {
                //RuntimeOptions.UseDepth is used because I am obtaining depth data
                sensor.Start();
            }
        }
    }

    2) Color Image

    using System;
    using System.Windows;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using Microsoft.Kinect;

    namespace KinectVideoApplication1
    {
        public partial class MainWindow : Window
        {
            //Instantiate the Kinect runtime. Required to initialize the device.
            //IMPORTANT NOTE: You can pass the device ID here, in case more than one Kinect device is connected.
            KinectSensor sensor = KinectSensor.KinectSensors[0];
            byte[] pixelData;

            public MainWindow()
            {
                InitializeComponent();

                //Runtime initialization is handled when the window is opened. When the window
                //is closed, the runtime MUST be unitialized.
                this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
                this.Unloaded += new RoutedEventHandler(MainWindow_Unloaded);

                //Handle the content obtained from the video camera, once received.
                sensor.ColorStream.Enable();
            }

            void MainWindow_Unloaded(object sender, RoutedEventArgs e)
            {
                sensor.Stop();
            }

            void MainWindow_Loaded(object sender, RoutedEventArgs e)
            {
                sensor.Start();
                sensor.ColorFrameReady += runtime_VideoFrameReady;
            }

            void runtime_VideoFrameReady(object sender, ColorImageFrameReadyEventArgs e)
            {
                bool receivedData = false;

                using (ColorImageFrame CFrame = e.OpenColorImageFrame())
                {
                    if (CFrame == null)
                    {
                        // The image processing took too long. More than 2 frames behind.
                    }
                    else
                    {
                        pixelData = new byte[CFrame.PixelDataLength];
                        CFrame.CopyPixelDataTo(pixelData);
                        receivedData = true;
                    }
                }

                if (receivedData)
                {
                    BitmapSource source = BitmapSource.Create(640, 480, 96, 96,
                            PixelFormats.Bgr32, null, pixelData, 640 * 4);

                    videoImage.Source = source;
                }
            }
        }
    }

    The question is: how can I view the two streams in the same window? (color video on the left, IR video on the right)

    Tuesday, April 10, 2012 2:56 PM
  • Just create 1 application not 2 :)

    You need 2 containers, one for each stream. If you include WPF examples (as in the videos) you can in very simple way just add stream viewers and connect them with your Kinect. The ammount of code for that is almostu nothing. So IMO check this out cause it`s cool feature.

    If you don`t want to use the example viewers just pass to an image each stream and you`re done

    p.s. If an answer helps you it`s good to mark it as helpfull :)

    Tuesday, April 10, 2012 6:25 PM
  • Hi Steppy,

    Check out The Kinect Explorer sample. The color and the depth streams are displayed side by side in this example.

    Thanks,

    Bharat.

    Sunday, April 15, 2012 1:07 PM
  • You could use the kinect contrib sample templates to help limit the kinect code to only video feeds (rgb and depth) because they have very simple code to grab the feed and put into picture. Im working on scotts filter for version 1 kinect sdk and my goal is related to yours as I want to actually make kinect recognized as a video camera (he also has a depth feed version) but I need help from anyone with c++ experience to do this.

    If i can fix his version 1 code for the rgb camera source on kinect I can also upgrade his depth feed code which wouldn't be too hard.

    I have an post from directshow forums  where someone from wdk forums I know talked about what i would need to do to write the directshow filter. But you could just for your program save to file.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/


    • Proposed as answer by The Thinker Thursday, April 19, 2012 12:34 PM
    • Edited by The Thinker Thursday, April 19, 2012 12:35 PM
    Thursday, April 19, 2012 12:34 PM