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

How to obtain depth map from stereo camera ?

asked 2015-04-05 20:04:04 -0600

lilouch gravatar image

updated 2015-04-06 23:18:48 -0600


I would like to try a visual odometry algorithm with the KITTI dataset. However the KITTI dataset, in my case, has only sequences of pictures with the left and right camera. I don't have any cloud or depth information in the dataset. (Actually yes there is also velodyne data but i'm not interested in laser for now)

Therefore, I presume that from the left and right camera, I have to obtain the depth map (correct me if I'm mistaken) ? How i can do that in ROS ? I saw that there is a node called stereo_image_proc node who can deal with stereo but I only can obtain a disparity MAP and I didn't find any topic that publishes this depth map.

EDIT: I can have the disparity image or/and the pointCloud2

Can someone help me ?

Thank you

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-04-14 20:58:02 -0600

lilouch gravatar image

updated 2015-04-15 00:31:16 -0600

I finally was able to obtain the depth map from the disparity picture thank to the disparity_image_proc nodelet. It used an OpenCV function to project disparity into 3D space.

The main issue was the the fact that image_view and stereo_image_view nodes didn't work in my ROS indigo ( ) and therefore I wasn't able to obtain a good depth map because i couldn't adjust the parameters properly in real time because I couldn't see the results directly.

Finally, I installed ROS Hydro and I could change the parameters directly with image_view. And now It works !

EDIT: by the way can you explain me how to run the script you provided ? I'm not able to make it work despite i followed the python tutorial.

edit flag offensive delete link more


How did you change the parameters in real time?. thanks

Sai Anirudh Kondaveeti gravatar image Sai Anirudh Kondaveeti  ( 2015-05-21 13:33:06 -0600 )edit
lilouch gravatar image lilouch  ( 2015-05-22 00:50:24 -0600 )edit

answered 2015-04-14 08:58:49 -0600

Miquel Massot gravatar image

Hi lilouch,

there are some steps you have to do before obtaining the depth image or the pointcloud (what do you prefer?)

  1. Publish the images as ROS topics: Write a node to do that, or use one already available. For instance this one. You'll need two instances of this same node, one for the left camera and one for the right.
  2. Run stereo_image_proc to rectify the images and calculate their disparity. This node calculates also the pointcloud. From the pointcloud you've already got the depth, but in case you need a depth image, read below:

As you may already know, depth can be calculated from disparity using Z = fB/d, where f is the focal lenght (px), B is the baseline (m) and d is the disparity (px). Z is depth in m. Both f and B are fixed terms, so your entire disparity image inverted (termwise), multiplied by a constant is your depth image.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-04-05 20:04:04 -0600

Seen: 4,248 times

Last updated: Apr 15 '15