How to access the depth data in meter (float) from /camera/depth_registrered/image as published by openni_launch
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!
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
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.