ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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 -0500

f_r gravatar image

updated 2016-10-24 09:01:17 -0500

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 (http://www.ros.org/wiki/openni_launch).

When echoing this topic it does not at all looks like floats. But rather like 8-bit integers as defined by http://www.ros.org/doc/api/sensor_msgs/html/msg/Image.html.

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

Comments

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 image f_r  ( 2012-03-26 14:02:28 -0500 )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 image Stephan  ( 2012-03-26 23:50:17 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

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

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
0

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

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

Question Tools

2 followers

Stats

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

Seen: 2,009 times

Last updated: Mar 27 '12