Ask Your Question

Get data values from depth image

asked 2014-07-10 19:26:18 -0500

Thiagopj gravatar image

I'm using a turtlebot (Create base) with a kinect. I need to save images automatically (RGB and depth images) when the turtlebot is in front of a object that is less than 1 meter away. Therefore, i need to get access to the data values of depth image, and convert the numbers to get the distance. How can i do that ? And what's the appropriate topic to get what i need ?

For sure i'll have a code running, and since i'm new to ros i still have some silly doubts: - My goal is to use the images on opencv. Is it necessary to install again or the one who come with ros hydro is enough ? - When saving depth images from /camera/depth/image topic manually, i get a .jpg completely black. Anyone knows why ? - What's the best way to get start with opencv ? How to save a image thought a C++ code and etc.


edit retag flag offensive close merge delete


My project is kind of similar with yours, but the time I see it, it is 2016 lol. I met the same problem just as you do.

Henschel.X gravatar image Henschel.X  ( 2016-03-23 02:27:11 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-11 02:00:41 -0500

Hi there,

You don't need to convert the data on the depth image topic manually. If you execute roslaunch openni_launch openni.launch you should have the topic /camera/depth/points which is a 3D Point Cloud with the depth image converted to what you want.

About OpenCV, unless you need the bleeding edge functionalities of the ultra-super-last version, the one that comes with ROS is fairly recent and should include everything you need.

Regarding the black jpg image, the data on the topic /camera/depth/image contains uint16 depths in mm, which is not a regular image that can be directly saved as jpg, you would need to convert the depth values to the range of a uchar (consequently loosing information, because uchar is only 8bits) to store it as an image.

Also, the best way to get started with opencv is to follow the tutorials and ask in all your questions about the computer vision library.

I hope this helps

edit flag offensive delete link more


Actually i got the distance in meters using this function void chatterCallback(const sensor_msgs::Image::ConstPtr& msg) { cv_bridge::CvImagePtr Dest=cv_bridge::toCvCopy(msg); ROS_INFO("Value: %f", Dest-><float>(msg->width/2,msg->height/2)); } and on function main i have: ros::Subscriber sub = n.subscribe("/camera/depth/image", 1000, chatterCallback); The output is the distance in meters between the sensor and the central pixel. Using the 'points' topic whats the difference ? I now have to transform the image received from kinect to a OpenCV image and then try to convert and save it. Any tutorial that could help with that? Thank you for the answer!

Thiagopj gravatar image Thiagopj  ( 2014-07-11 17:58:09 -0500 )edit

why you are only interested for the depth value of center point? if I am not wrong, In your image some points or object could be more closer/far, getting the center point popnt distance does not imply that every point of the image are at same distance

rasoo gravatar image rasoo  ( 2016-10-23 21:16:06 -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: 2014-07-10 19:26:18 -0500

Seen: 4,798 times

Last updated: Jul 11 '14