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

Need Help with Accessing the kinect Depth Image using OpenCV.

asked 2012-10-25 01:13:30 -0600

Subhasis gravatar image

updated 2012-10-25 02:32:09 -0600

Hi All,

I tried to subscribe to kinect depth and color image topics from openni_launch..(/camera/rgb/image_color and /camera/depth/image )

I converted them to cv::Mat format using below code.

cv_rgb = cv_bridge::toCvCopy(color_image, enc::BGR8); cv_depth = cv_bridge::toCvCopy(depth_image, enc::BGR8); (I am not sure about this line)

Now I want to access each pixel values of both color and depth image. I am able to access the rgb image by the below code.

for(int i=0; i<cv_rgb->image.rows; i++) {
for(int j=0; j<cv_rgb->image.cols; j++) {

       cv_rgb->image.at<cv::Vec3b>(i,j)[0] = 0;
       cv_rgb->image.at<cv::Vec3b>(i,j)[1] = 0;
      cv_rgb->image.at<cv::Vec3b>(i,j)[2] = 0;

           }
    }

I am unable to access the kinect depth image. It says me the type is 21. and Its a single channel image. Can anybody suggest me a way that I can access each pixel values of Kinect and how can this pixel values be translated in terms of real distance in mm ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-10-25 11:17:36 -0600

Tambo gravatar image

updated 2012-10-25 11:19:10 -0600

The encoding you are using for the depth stream is wrong, you should use the unsigned 16 bit representation with a single channel, instead of the 3 channels of the RGB representation.

Modify the line -cv_depth = cv_bridge::toCvCopy(depth_image, enc::BGR8);

changing the encoding (check the correct definition for 16 unsigned char) -cv_depth = cv_bridge::toCvCopy(depth_image, enc::16UC1);

In this way, you can access depth data properly. According to the topic you subscribe to, you may obtain either representation in millimeters or in meters (both of them use floats)

Good luck, Tambo

edit flag offensive delete link more

Comments

i wonder how you can align rgb and depth frames together

dmngu9 gravatar image dmngu9  ( 2015-05-28 08:58:55 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2012-10-25 01:13:30 -0600

Seen: 4,932 times

Last updated: Oct 25 '12