How to get distance from depth-map in Kinect?

asked 2013-12-08 09:57:11 -0600

Subhamoy gravatar image

Hi, I am new to OpenKinect/Libfreenect, but I have some experience in OpenCV. I have followed the C++ example to display RGB and depth images. There are some additional calculations performed in the example, such as obtaining some gamma values, which are not being used for anything, and I do not understand why. To see the type of information the depth image contains, I print the 3 channel values of the centre pixel of the frames, and I get something like this:

[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]
[3.67116e-270, 3.67116e-270, 3.67116e-270]

I assume this is the 11bit format of depth, which is default if no depth mode is specified. When I try to set the depth like this:

// freenectDevice is an instance of the class that inherits from Freenect::FreenectDevice
freenectDevice.setDepthFormat(FREENECT_DEPTH_REGISTERED);

This should align the depth to the RGB image and return depth values in millimetre, or so I understood from the documentation. It compiles, but exits with this error when I try to run it:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Cannot start depth callback
Aborted (core dumped)

It seems that the example is quite old. What would be a good C++ approach of getting aligned distance in a physical unit? I have read the documentation on depth camera already, but somehow I cannot see the connection between that and the example.

edit retag flag offensive close merge delete