none
how to save color video and depth map in Kinect RRS feed

  • Question

  • Hello,

    I am very new in Kinect coding, so I am stucked at a very basic problem, I want to save color video and dept map, I guess that for this to be done, I must modify skeletal viewer example.

    I would appreciate very much, if you give me an answer as detailed as possible

    Thank you

    Wednesday, October 19, 2011 11:53 AM

Answers

  •  

    Do you want to save the single images?

     

    If so, use the following code snippet:

     

            private void SaveImage(BitmapSource image)
            {
                System.IO.FileStream stream = new System.IO.FileStream(@"C:\YOUR_FOLDER_HERE.jpg", System.IO.FileMode.Create);
                JpegBitmapEncoder encoder = new JpegBitmapEncoder();
    
                encoder.FlipHorizontal = true;
                encoder.FlipVertical = false;
                encoder.QualityLevel = 30;
                encoder.Frames.Add(BitmapFrame.Create(image));
                encoder.Save(stream);
                stream.Close();
            }
    

     

    Call this method after you created your image in the eventhandlers (e.g.)

            /// <summary>
            /// Eventhandler, triggered when new color frame is available
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void nui_ColorFrameReady(object sender, ImageFrameReadyEventArgs e)
            {
                // 32-bit per pixel, RGBA image
                PlanarImage Image = e.ImageFrame.Image;
                BitmapSource image  = BitmapSource.Create(
                    Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
                video.Source = image;
                SaveImage(image);
            }
    


    Cheers

    Wednesday, October 19, 2011 1:10 PM

All replies

  •  

    Do you want to save the single images?

     

    If so, use the following code snippet:

     

            private void SaveImage(BitmapSource image)
            {
                System.IO.FileStream stream = new System.IO.FileStream(@"C:\YOUR_FOLDER_HERE.jpg", System.IO.FileMode.Create);
                JpegBitmapEncoder encoder = new JpegBitmapEncoder();
    
                encoder.FlipHorizontal = true;
                encoder.FlipVertical = false;
                encoder.QualityLevel = 30;
                encoder.Frames.Add(BitmapFrame.Create(image));
                encoder.Save(stream);
                stream.Close();
            }
    

     

    Call this method after you created your image in the eventhandlers (e.g.)

            /// <summary>
            /// Eventhandler, triggered when new color frame is available
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void nui_ColorFrameReady(object sender, ImageFrameReadyEventArgs e)
            {
                // 32-bit per pixel, RGBA image
                PlanarImage Image = e.ImageFrame.Image;
                BitmapSource image  = BitmapSource.Create(
                    Image.Width, Image.Height, 96, 96, PixelFormats.Bgr32, null, Image.Bits, Image.Width * Image.BytesPerPixel);
                video.Source = image;
                SaveImage(image);
            }
    


    Cheers

    Wednesday, October 19, 2011 1:10 PM
  • Thank you for your answer,

     

    When I did what you said, it gives an error which says the access to C:\YOUR_FOLDER_HERE.jpg is denied

    Wednesday, October 19, 2011 2:47 PM
  • Dude, you have to change your path.

    I called it YOUR_FOLDER_HERE that you take a valid folder here.

     

    Check for a HDD or USB Stick where you have the rights to write files.

    Maybe in your case you dont have a HDD or USB with the label C.

    Or go into a folder of your hdd were you have write rights!

     

    I hope you understand, that your problem is the path, were the file should be created!

    So maybe you have to change the line

    System.IO.FileStream stream = new System.IO.FileStream(@"C:\YOUR_FOLDER_HERE.jpg", System.IO.FileMode.Create);

    to

    System.IO.FileStream stream = new System.IO.FileStream(@"D:\myfirstimage.jpg", System.IO.FileMode.Create);

    or

    System.IO.FileStream stream = new System.IO.FileStream("D:\myfirstimage.jpg", System.IO.FileMode.Create);

     

    Check it out. If you cant find a solution check google for: " System.IO.FileStream C Sharp"

     

    Cheers!

     

     

     

    Wednesday, October 19, 2011 3:54 PM
  • You are right, the problem was in path, Thank you for your help,

    I also want to save depth map, probably I must change the method nui_DepthFrameReady, I would try to do same steps we did while saving color image.

    But, it is highly probable that I may be stumped, so I would need your help,

    Also I want to save these color images and depth maps as video, I would appreciate very much if you tell a solution to this problem.

    Thank you again

     

     

    Tuesday, October 25, 2011 8:46 AM
  • Hi,

    Code above is very helpful. But i am looking for something can record the video (not single image). Is there any way to do that? Can you guys please help me with it? I am using skeletonviewer sample program.

     

    Also is there any way to superimpose(overlay) vga view on skeleton view (or the other way) ?

     

    Your help will be highly appreciated.

     

    Thanks.

    Thursday, November 10, 2011 9:04 PM
  • You can use the kinect toolbox to record the depth data and skeleton data but i am not so sure that you can record the color view with it.

    http://kinecttoolbox.codeplex.com/

    Sunday, April 8, 2012 10:56 AM
  • Dude, you have to change your path.

    I called it YOUR_FOLDER_HERE that you take a valid folder here.

     

    Check for a HDD or USB Stick where you have the rights to write files.

    Maybe in your case you dont have a HDD or USB with the label C.

    Or go into a folder of your hdd were you have write rights!

     

    I hope you understand, that your problem is the path, were the file should be created!

    So maybe you have to change the line

    System.IO.FileStream stream = new System.IO.FileStream(@"C:\YOUR_FOLDER_HERE.jpg", System.IO.FileMode.Create);

    to

    System.IO.FileStream stream = new System.IO.FileStream(@"D:\myfirstimage.jpg", System.IO.FileMode.Create);

    or

    System.IO.FileStream stream = new System.IO.FileStream("D:\myfirstimage.jpg", System.IO.FileMode.Create);

     

    Check it out. If you cant find a solution check google for: " System.IO.FileStream C Sharp"

     

    Cheers!

    Hi. Is there a way that i can save the color and the depth image at the same time. I am looking for an application that has an ability to capture these two images.

    Thanks.

    Vener

     

     


    Friday, January 17, 2014 1:52 AM
  • Yes, you can record and replay color data frames with the KinectToolbox.

    If you would rather record a real video you will have to encode it yourself from the recorded color frames.

    --
    Roland Smeenk 

    Sunday, January 19, 2014 11:16 PM