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

Convert raw depth data from depth image to meters (Kinect v2)

asked 2016-10-13 11:17:33 -0600

patrchri gravatar image

updated 2016-10-21 07:25:09 -0600

Hello,

I am using Kinect v2 and I am trying to convert its raw values from the depth image to meters. I am subscribing to the image_depth_rect topic. Firstly, I would like to ask if I need to calibrate the depth image with the color image I get from the sensor ?

I have searched for similar issues, but all I found is info about the sensor from the previous version. I also found some stuff outside from ROS which didn't help.

Is there an equation to convert the unsigned 16bit data that I get in meters?

Currently I am using the following callback function for the depth image topic:

void kinectdepthCallback(const sensor_msgs::ImageConstPtr& msg2){

    cv_bridge::CvImagePtr cv_ptr2;
    try{
        cv_ptr2 = cv_bridge::toCvCopy(msg2, sensor_msgs::image_encodings::TYPE_16UC1); 
    }
    catch (cv_bridge::Exception& e){
        ROS_ERROR("Could not convert from '%s' to '16UC1'.", e.what());
    return;
    }
    cv::imshow("Depth Image",cv_ptr2->image);
    cv::waitKey(20);
    ROS_INFO("The object is in depth: %d",cv_ptr2->image.at<int>(x,y));


}

where (x,y) are some points of the detected object but I get wrong results.

To be more specific, I detect an orange marker but I cannot get its depth from the Kinect v2. I present the following images:

Color image with detected object:

image description

Thresholded image:

image description

Depth image is black:

image description

Terminal messages from the above code:

image description

I don't know what is wrong and I get zero depth even if the object is at approximately a 19 - 20 cm. I have tried to find the depth in bigger depths like 60 cm, but I was still getting 0 results.

Thanks for answering in advance,

Chris

edit retag flag offensive close merge delete

Comments

Dimitri Schachmann gravatar image Dimitri Schachmann  ( 2016-10-14 09:25:05 -0600 )edit

In the example he just gets the raw data from kinect. I am using a kinect v2 and I am trying to make this data into meters. Unless Kinect v2 and its tools do this automatically, which is something I don't know...

patrchri gravatar image patrchri  ( 2016-10-14 10:20:54 -0600 )edit

Hi, I have simple python code for detecting and tracking the object based on color by using webcam. My question is how can I use the same code but by using Kinect v2 (NOT webcam).

can u plz help with this, and tell me how to use Kinect v2 as webcam in linux? or share your method ?

Abdu gravatar image Abdu  ( 2017-07-17 10:19:54 -0600 )edit

You want to use Kinect v2 in linux or in ROS? This topic has to do with integrating Kinect v2 into ROS as a node and manipulating its data with cv_bridge. Take a look here for that.

patrchri gravatar image patrchri  ( 2017-07-17 12:30:15 -0600 )edit

If you want to use Kinect v2 in linux, you need to install the drivers from here and ask in another more relative forum for that. A simple googling of your issue will also help you with your problem also.

Good luck!

patrchri gravatar image patrchri  ( 2017-07-17 12:32:00 -0600 )edit

For integrating Kinect v2 into ROS, also check this.

patrchri gravatar image patrchri  ( 2017-07-17 12:34:18 -0600 )edit

Thanks for you guys, I know how to use kinect v2 with ROS, but I don't know how to use it as a webcam, because my code is in python and using webcam, but I want to modify it so it would use kinect v2 not webcam. That's why I ask Chris to pass the code, cuz its for color detection by using kinect v

Abdu gravatar image Abdu  ( 2017-07-17 14:49:31 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-11-27 15:23:45 -0600

patrchri gravatar image

updated 2016-11-27 15:30:21 -0600

Better calibration of the sensor and <ushort> casting will do the work. The raw data from the Kinect v2 are in millimeters.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-10-13 11:17:33 -0600

Seen: 2,322 times

Last updated: Nov 27 '16