Ask Your Question

How to access the depth data in meter (float) from /camera/depth_registrered/image as published by openni_launch

asked 2012-03-26 11:43:38 -0600

f_r gravatar image

updated 2014-04-20 14:05:06 -0600

ngrennan gravatar image

I am using Kinect combined with ROS for accessing depth data.

/camera/depth_registrered/image is supposed to output depth as float in meters (

When echoing this topic it does not at all looks like floats. But rather like 8-bit integers as defined by

How do I access the depth value in meters (as a float). How do I do this casting?

More specifically, can someone write some pseudo code that would go into the callback function for /camera/depth_registrered/image. I would like this code to output the depth in meters (float) for the pixel in the middle (the 640*480/2-th pixel).

Thanks in advance!

edit retag flag offensive close merge delete


So opencv seems to be one choise. But just out of curiousity, why doesnt it work to do for instance: float f = *(&(msg->data[0]) + sizeof(float) * 640 * 480 / 2)).... When doing this I seem to receive depth values, these are however in the range from 50 to a couple of hundreds and not certainly in m

f_r gravatar imagef_r ( 2012-03-26 14:02:28 -0600 )edit

msg->data contains serialized floats as uint8. To unserialize you have to construct your float using several uint8 fields, not just one. Your code still does an implicit char to float conversion. You would have to use some kind of reinterpret_cast<float*>(msg->data...), but better rely on cv_bridge.

Stephan gravatar imageStephan ( 2012-03-26 23:50:17 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2012-03-26 12:04:10 -0600

rostopic echoing an image is not going to give you easily intelligible information, as the data doesn't get deserialized as is it actually does when using CvBridge. Try subscribing to the image in code, then converting it to an OpenCV type using CvBridge, and see if it looks more like what you expect.

edit flag offensive delete link more

answered 2012-03-27 08:36:25 -0600

f_r gravatar image

Thanks for the answers. OpenCV and casting are good options.

The easiest solution is however to simply subscribe to /camera/depth_registrered/image_raw and then get this float value as: float middlepoint = (float)msg->data[640*480/2] * 0.001f;

This also results in 1/4th of the communication which is useful if doing this over a network.

The reason I got confused is because OpenNI's "raw data" is in millimeters and OpenKinect's raw data is 11-bit values certainly not in millimeters.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools



Asked: 2012-03-26 11:43:38 -0600

Seen: 660 times

Last updated: Mar 27 '12