Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Storing depth video from kinect

Hey everyone,

I am trying to find a way to save and retrieve a video from a depth sensor (a kinect in my case) without losing any information.

The depthvideo I get is single channel with 16bit unsigned short per pixel (CV_16U). Since It is not possible to write such a video, I split the 16bits of every pixel and store two 8bit values in a standard 3 channel video with 8bits per pixel:

int rows = inputFrame.rows;
int cols = inputFrame.cols;
Mat outputFrame(rows, cols, CV_8UC3);
for (int r = 0; r < rows; r++)
{
    for(int c = 0; c < cols; c++)
    {
        unsigned short depthVal = inputFrame.at<unsigned short>(r, c);
        unsigned char val1 = depthVal >> 8;
        unsigned char val2 = depthVal & 0xff;

        outputFrame.at<Vec3b>(r, c)[0] = val1;
        outputFrame.at<Vec3b>(r, c)[1] = val2;
    }
}

To recover the frames, I combine the two values again and write them to a CV_16U image.

My problem is, that under linux, there seems to be no way to save an unencoded video, which of course destroys my 'encoding'. Under windows, when using -1 as the codec value of an ImageWriter, I can choose not to encode the video and I get Codec: 24 bits RGB (RV24). However, this does not work under Linux. When using 0 as codec value, the resulting image is Codec: Planar 4:2:0 YUV (I420). Recreating the depthvideo from these frames does not seem possible. I tried every COLOR_ constant to convert the image back to RGB, but none seems to recreate the correct image.

Is there a way on Linux to just write a video with raw rgb data? Or does anyone maybe have another idea of how to solve this problem? Any hints are greatly appreciated!

Storing depth video from kinect

Hey everyone,

I am trying to find a way to save and retrieve a video from a depth sensor (a kinect in my case) without losing any information.

The depthvideo I get is single channel with 16bit unsigned short per pixel (CV_16U). Since It is not possible to write such a video, I split the 16bits of every pixel and store two 8bit values in a standard 3 channel video with 8bits per pixel:

int rows = inputFrame.rows;
int cols = inputFrame.cols;
Mat outputFrame(rows, cols, CV_8UC3);
for (int r = 0; r < rows; r++)
{
    for(int c = 0; c < cols; c++)
    {
        unsigned short depthVal = inputFrame.at<unsigned short>(r, c);
        unsigned char val1 = depthVal >> 8;
        unsigned char val2 = depthVal & 0xff;

        outputFrame.at<Vec3b>(r, c)[0] = val1;
        outputFrame.at<Vec3b>(r, c)[1] = val2;
    }
}

To recover the frames, I combine the two values again and write them to a CV_16U image.

My problem is, that under linux, there seems to be no way to save an unencoded video, which of course destroys my 'encoding'. Under windows, when using -1 as the codec value of an ImageWriter, I can choose not to encode the video and I get Codec: 24 bits RGB (RV24). However, this does not work under Linux. When using 0 as codec value, the resulting image is Codec: Planar 4:2:0 YUV (I420). Recreating the depthvideo from these frames does not seem possible. I tried every COLOR_ constant to convert the image back to RGB, but none seems to recreate the correct image.

Is there a way on Linux to just write a video with raw rgb data? Or does anyone maybe have another idea of how to solve this problem? Any hints are greatly appreciated!