Ask Your Question

piontcloud to depth image codification

asked 2016-06-06 12:56:46 -0500

apalomer gravatar image

updated 2016-06-06 12:57:50 -0500


I have a depth image in a cv::Mat(height,widht,CV_64F) where each pixel is either 0 if it has no 3D or the distance to produce a 3D point allong the optical ray through that pixel. This distance is encoded between a minimum and maximum distance in the range [0..255]. I know how to convert cv::Mat to sensor_msgs/Image using cv_bridge. However I have not found how to properly codify the information in my cv::Mat image so I can visualize its 3D in rviz. Could you tell me how to convert it? I have been reading and the only information I found was this but I it has not been helpful to me.

Thank you.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2016-06-06 22:23:20 -0500

ahendrix gravatar image

You should convert your depth image from scaled values to meters (as 32-bit float), as described in REP- 0118, and publish this as a sensor_msgs/Float .

Then run the depth_image_proc/point_cloud_xyz node from depth_image_proc, and remap its image_rect topic to the topic where you are publishing your depth image. This will publish sensor_msgs/PointCloud2 messages on the points topic.

You can then view these messages with the PointCloud2 display type in rviz. (make sure your fixed frame in rviz matches the frame_id)

edit flag offensive delete link more

answered 2016-06-06 16:30:48 -0500

updated 2016-06-07 06:57:22 -0500

If you need to generate a sensor_msg/Image:

From what you say in your question you should use the sensor_msgs::image_encodings::TYPE_64FC1.

However in your question also looks like you are using a matrix of byte (instead of a matrix of float) so then you would have to use the type sensor_msgs::image_encodings::TYPE_8UC1.

In any case you can check more of the possible types in:

#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>

cv_bridge::CvImage out_msg;
out_msg.header   = in_msg->header; // Same timestamp and tf frame as input image
out_msg.encoding = sensor_msgs::image_encodings::TYPE_64FC1; // Or whatever
out_msg.image    = sal_float_image; // Your cv::Mat


If you need to generate the point cloud:

You have to use the node: point_cloud_xyz that takes as input a depth image and provides as output a point cloud.

edit flag offensive delete link more


Sorry, I don't see how to use this. Shall I launch this to convert my image or I have to check the code where it does the codification?

apalomer gravatar image apalomer  ( 2016-06-06 17:45:54 -0500 )edit

You have to use the node: point_cloud_xyz that takes as input a depth image and provides as output a point cloud.. ahendrix explained it in more detail

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2016-06-07 02:42:08 -0500 )edit

answered 2016-06-07 03:20:44 -0500

apalomer gravatar image

Sorry for the miss understanding. This is not what I want to do. When you are using a depth sensor such as Kinect, you can visualize the depth image directly in rviz as a 3D cloud. I need it this way because I have to feed this depth image to a 3rd party node to detect objects in it (object recognition kitchen). My question is regarding the depth image encoding. Now I have a cv::Mat with CV_64F in each position representing either no range information (0) or a value between 1 and 255 to represent the depth value in a min max scale. My question is how to convert this cv::Mat to a sensor_msgs::Image so that it is properly interpreted for both the 3rd party node and rviz. Using cv_bridge one of the parameters to convert the cv::Mat to a sensor_msgs::Image is sensor_msgs::image_encoding, which one of this shall I use? I am not interested in publishing the 3D point cloud because there is already a 3D cloud, the same that I used to produce the depth image.

Thank you.

edit flag offensive delete link more


My answer still applies: convert your depth image to meters before publishing it. rivz can't visualize depth images directly, so you'll need to convert back to a point cloud (using standard tools) to visualize.

ahendrix gravatar image ahendrix  ( 2016-06-07 12:57:41 -0500 )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



Asked: 2016-06-06 12:56:46 -0500

Seen: 447 times

Last updated: Jun 07 '16