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

cv_bridge: reading distance from /camera/depth/image_raw

asked 2015-05-23 12:17:00 -0600

Hi, I'm running an turtlebot simulation on gazebo. roslaunch turtlebot_gazebo myrobot.launch

I subscribed to the topic /camera/depth/image_rawto get the distance information using code

def get_distance(img):
       #calculate x and y
       cv_image = bridge.imgmsg_to_cv2(img, "passingthrough")
       print cv_image[x,y]


according to the document,

depth/image_raw (sensor_msgs/Image)

Raw image from device. Contains uint16 depths in mm.

But I keep geting float numbers between 0 and 5.

Then I tried several other converting types besides "passthrough"

32FC1 gave me a complex number.

32SC1 gave me a large negative number.

16UC1 usually gave me 0.

16SC1 and 8UC1 gave me contant 5.

none of them makes sense, can anyone give me some idea? Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-06-25 01:35:07 -0600

askkvn gravatar image

My answer with complete code (c++) :

Code funtionality:

  • Subscribed to /camera/depth/image_raw rostopic,
  • Convert ROS image to OpenCV image
  • Get image dimension
  • Get global max and min value,
  • Get depth value at specific point,
edit flag offensive delete link more

answered 2015-05-23 18:26:48 -0600

I tried to mark the distance point on rviz by tf.

The result shows the distance value is correct, and in meter instead of mm.

It means the definition of kinect's measurement result in turtlebot_gazebo's simulation is different from what said in openni document.

edit flag offensive delete link more

Question Tools



Asked: 2015-05-23 12:17:00 -0600

Seen: 1,630 times

Last updated: Jun 25 '21