how to save color video and depth map in Kinect
-
Wednesday, October 19, 2011 11:53 AM
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
All Replies
-
Wednesday, October 19, 2011 1:10 PM
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
- Marked As Answer by Eddy Escardo-Raffo [MSFT]Microsoft Employee, Owner Friday, October 21, 2011 1:45 AM
-
Wednesday, October 19, 2011 2:47 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
- Marked As Answer by bekirve Wednesday, October 19, 2011 2:47 PM
- Unmarked As Answer by Eddy Escardo-Raffo [MSFT]Microsoft Employee, Owner Friday, October 21, 2011 1:45 AM
-
Wednesday, October 19, 2011 3:54 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!
-
Tuesday, October 25, 2011 8:46 AM
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
-
Thursday, November 10, 2011 9:04 PM
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.
-
Sunday, April 08, 2012 10:56 AM
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/

