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

Revision history [back]

click to hide/show revision 1
initial version

That depends on the image encoding. Check the value of "encoding" on the message being published.

If it's "32FC1" then the depth data for each pixel is a 32bit float where each value is the distance in meters from the camera. In c++ you can get the depth data from this encoding by casting to an array of floats.

//sensor_msgs::Image image;
if (image.encoding == sensor_msgs::image_encodings::TYPE_32FC1)
{
    const float * depth_array = reinterpret_cast<const float *>(&(image.data[0]));
    //depth_array[0], depth_array[1], ..., depth_aray[image.height * image.width - 1]
]