0
$\begingroup$

Rosanswers logo

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!


Originally posted by f_r on ROS Answers with karma: 23 on 2012-03-26

Post score: 0


Original comments

Comment by f_r on 2012-03-26:
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

Comment by Stephan on 2012-03-26:
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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Dan Lazewatsky with karma: 9115 on 2012-03-26

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.