Ask Your Question

Using RTABMap and Kinect, how do you get distance at a certain point?

asked 2016-04-18 12:34:50 -0500

michaelrosario gravatar image


I appreciate all the efforts and amazing work in the ROS community. In my situation, I am trying to estimate a distance to an object using RTABMap, ROS, and a Kinect 360. For my implementation, we are using ROS indigo and libfreenect .

In our system, we are able to display the field of view of the robot to a web page using roslibjs. When the user clicks on a certain (x,y) coordinate on that video stream, we want to obtain an estimated distance to the object.

Is there an API in RTABMap/ROS that can help me obtain this information easily?

It looks like the information should be available in the following topic: /camera/depth_registered/image_raw - Raw image from device. Contains uint16 depths in mm.

I'm not sure how I might extract/read the information.

I do appreciate your help and pointers.

All the best!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-04-20 07:49:17 -0500

matlabbe gravatar image


You can use cv_bridge to get the image in cv::Mat format, then you get directly the distance at the clicked pixel:

void callback(
    const sensor_msgs::ImageConstPtr& depth,
    const sensor_msgs::CameraInfoConstPtr& cameraInfo)
    cv_bridge::CvImageConstPtr ptr = cv_bridge::toCvShare(depth);

    float distance = 0.0f; // meters
    if(image.type() == CV_32FC1)
        distance = ptr-><float>(y, x);
    else // CV_16UC1
        distance = ptr-><unsigned short>(y, x)/1000.0f; // convert from mm to meters

If you want the 3D point in Camera referential, you can look at image_geometry::PinholeCameraModel class:

image_geometry::PinholeCameraModel model;
cv::Point3d ray = model.projectPixelTo3dRay(cv::Point2d(x,y));
cv::Point3d pt3d = ray * distance;


edit flag offensive delete link more


Hi. I do appreciate the answer! Thank you for your time!!!

michaelrosario gravatar image michaelrosario  ( 2016-04-20 08:38:18 -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

1 follower


Asked: 2016-04-18 12:34:50 -0500

Seen: 163 times

Last updated: Apr 20 '16