# How to obtain depth map from stereo camera?

Hello,

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

Originally posted by lilouch on ROS Answers with karma: 93 on 2015-04-05

Post score: 2

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.

Originally posted by Miquel Massot with karma: 1471 on 2015-04-14

This answer was NOT ACCEPTED on the original site

Post score: 1

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 (https://github.com/ros-perception/image_pipeline/issues/117) 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.

Originally posted by lilouch with karma: 93 on 2015-04-14

This answer was ACCEPTED on the original site

Post score: 1