0
$\begingroup$

Rosanswers logo

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


Originally posted by patrchri on ROS Answers with karma: 354 on 2016-10-13

Post score: 0


Original comments

Comment by Dimitri Schachmann on 2016-10-14:
does this help: http://answers.ros.org/question/160611/how-can-i-get-depth-data-from-kinect/ ?

Comment by patrchri on 2016-10-14:
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...

Comment by Abdu on 2017-07-17:
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 ?

Comment by patrchri on 2017-07-17:
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.

Comment by patrchri on 2017-07-17:
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!

Comment by patrchri on 2017-07-17:
For integrating Kinect v2 into ROS, also check this.

Comment by Abdu on 2017-07-17:
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

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by patrchri with karma: 354 on 2016-11-27

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.