Ask Your Question

How can I get the metric distance from the topic "camera/depth/image_raw"?

asked 2014-04-14 02:25:03 -0600

Consider1001 gravatar image

updated 2014-04-15 16:20:08 -0600

sai gravatar image

I am learning turtlebot_simulator. I run turtlebot_gazebo. Then I subscriber the topic "camera/depth/image_raw" using Python. but How can I know the exact distance of each point from the depth image? I can print the information of the image.Like: frame_id: camera_depth_optical_frame

height 480

weight 640

encoding 32FC1

I have seen some similar problems, but have not solved my problem.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-15 15:24:28 -0600

sai gravatar image

updated 2014-04-15 16:19:03 -0600

You can know the know the distance of each point in the world from the camera centered co-ordinate frame. Just subscribe to the topic /camera/depth/points . It is a sensor_msgs::PointCloud2 topic where you have points with [x, y, z] distance from the camera centered coordinate frame.

The package depth_image_proc implements the method to convert the depth image to point cloud [x, y, z] format. Going through the internals of this package can help you in understanding more on how the image is converted to point cloud.

To completely understand and gain access to each point in the point cloud, you need to understand basics of point cloud library and point cloud format. This can be learnt from

EDIT 1 :

Here is something which can be done. First convert the 32

const std::string& enc = depth_msg->encoding;

if ("16UC1") == 0)

depth_img = cv_bridge::toCvShare(depth_msg)->image;

else if ("32FC1") == 0)

depthImageFloatTo16bit(cv_bridge::toCvShare(depth_msg)->image, depth_img);

// get raw z value (in mm)

uint16_t z_raw =<uint16_t>(v, u);

// z [meters]

z_mean = z_raw * 0.001;

Look here for better understanding :

Go through in detail and you can completely find what you are asking for.

edit flag offensive delete link more


Thank you for your answer.It really a good way to get the depth data. But others say that depth/image_raw(32FC1) contains depth data. "For using the depth image, it is important to note that is a 32-bit float for each pixel, corresponding to meters." My problem is how to get the value of each pixel?

Consider1001 gravatar imageConsider1001 ( 2014-04-15 16:05:50 -0600 )edit

Thanks a lot.

Consider1001 gravatar imageConsider1001 ( 2014-04-15 16:50:29 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-04-14 02:25:03 -0600

Seen: 1,797 times

Last updated: Apr 15 '14