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

what is the distance unit of /camera/depth/image_raw

asked 2015-05-18 13:49:03 -0500

Anis gravatar image


I have generated a bag file using an Turtlebot Kinect camera with openni and it contains the topic /camera/depth/image_raw. I subscribed to this topic and got the depth image correctly and I converted it to an openCV image in its callback as follows: depthImage_ptr=cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_32FC1); using the 32FC1 encoding.

The problem is that when I print the depth of any cell, for example ROS_INFO("depth = %.2f",depthImage_ptr-><float>(Point2f(200,300)));

I get values that are too large to be considered in meters. Here is an example of output My question is what is the unit of this depth? If it is meter, then the values I got are misleading? I browsed a lot of pages in ROS wiki and all mention that the unit of the depth when printed as float is in meter, and when printed as uint16 is millimeter. But as I mentioned, the values are too large. If it is in centimeters, then the values would be more logic.

What can be wrong with my settings? I am really blocked and I would appreciate to have any pointer on this.

Thank you Anis

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-18 18:53:18 -0500

According to the openni_camera wiki page, /camera/depth/image_raw "contains uint16 depths in mm."

edit flag offensive delete link more


Hi Dan, thanks for your answer. I subscribed topic'/camera/depth/image_raw' and print its value at certain pixel but I got a complex number... Does the distance equal to its modulus or I made something wrong?

lanyusea gravatar image lanyusea  ( 2015-05-23 06:08:27 -0500 )edit

my code:

   def get_distance(img):
       cv_image = bridge.imgmsg_to_cv2(img, "32FC1")
       print cv_image[10,10]


result: [ 2.75039315+2.75118136j] ...

lanyusea gravatar image lanyusea  ( 2015-05-23 06:09:36 -0500 )edit

What happens if you don't specify an encoding (defaulting to "passthrough")?

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2015-05-23 06:51:07 -0500 )edit

@Dan Lazewatsky "passthrough" works, the result will be an integer. Does it mean python has already decoded the image once? I just tried cpp,and I need to decode with sensor_msgs::image_encodings::TYPE_32FC1.

lanyusea gravatar image lanyusea  ( 2015-05-23 06:59:38 -0500 )edit

passthrough uses the encoding specified in the message. If you use another encoding, it will use opencv Mat.convertTo. If that doesn't do what you want, you'll have to do the conversion yourself.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2015-05-23 07:53:03 -0500 )edit

thanks for your reply.

lanyusea gravatar image lanyusea  ( 2015-05-23 08:13:42 -0500 )edit

one more question: the data I got (both cpp and python) are not integer. It is a floating number like 0.711012. It should be uint16 as mentioned, but what I got is a float number. I didn't use a real kinect, I was running a simulation from turtlebot_gazebo. Is that the reason why I got a float?

lanyusea gravatar image lanyusea  ( 2015-05-23 08:34:36 -0500 )edit

Question Tools


Asked: 2015-05-18 13:49:03 -0500

Seen: 3,796 times

Last updated: May 18 '15