Ask Your Question

foben's profile - activity

2020-04-24 07:49:53 -0600 received badge  Popular Question (source)
2013-12-28 09:07:26 -0600 commented answer Storing depth video from kinect

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.

2013-12-20 06:25:52 -0600 received badge  Editor (source)
2013-12-20 06:25:17 -0600 asked a question 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!

2013-11-04 07:49:39 -0600 commented question Kinect depth image duplication problem

I have uploaded a sample image here: http://imageshack.us/f/547/5xyf.png/

As you can see, the cable is recorded multiple times in the depth image. What is maybe not so obvious is the fact that the duplication occurs only horizontally, not vertically.

2013-10-30 08:40:23 -0600 asked a question Kinect depth image duplication problem

I have built opencv with OpenNI support to grab (rgb and depth) images directly from the kinect. I am using the Kinect for windows version with the near mode feature.

I use the PrimeSense driver for the kinect.

Unfortunately, the depth images shows some errors: Some objects are duplicated in the depth image. The rgb image is fine.

I suspect that it may have to do with the near mode feature not being enabled. Is there a way to do this using opencv?

I use the following code to grab and display both the rgb and the depth image:

while(1)
{
    Mat depthImage;
    Mat bgrImage;

    capture.grab();
    capture.retrieve(depthImage, CV_CAP_OPENNI_DEPTH_MAP );
    capture.retrieve(bgrImage, CV_CAP_OPENNI_BGR_IMAGE );

    namedWindow("depth", 1);
    namedWindow("bgr", 1);

    imshow("depth", depthImage);
    imshow("bgr", bgrImage);

    if (waitKey(30) >= 0) break;
}

Any hints are greatly appreciated :)