Ask Your Question
0

Storing depth video from kinect

asked 2013-12-20 06:25:17 -0600

foben gravatar image

updated 2013-12-20 06:25:52 -0600

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-12-26 18:27:54 -0600

NikolasE gravatar image

What have you tried to write and read the image? I work with a carmine, which also uses 16UC1 for depth and I write with cv::imwrite and read via

cv::Mat depth = cv::imread(filename,CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
assert(depth.type() == CV_16UC1);
edit flag offensive delete link more

Comments

I want to write and read a video, not a single image. The code above just shows how I encode every frame. I see now how this is confusing, sorry about that.

foben gravatar imagefoben ( 2013-12-28 09:07:26 -0600 )edit

Question Tools

Stats

Asked: 2013-12-20 06:25:17 -0600

Seen: 1,979 times

Last updated: Dec 26 '13