Ask Your Question

Need Help with Accessing the kinect Depth Image using OpenCV.

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

Subhasis gravatar image

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

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-><cv::Vec3b>(i,j)[0] = 0;
       cv_rgb-><cv::Vec3b>(i,j)[1] = 0;
      cv_rgb-><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

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

Tambo gravatar image

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

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


i wonder how you can align rgb and depth frames together

dmngu9 gravatar image dmngu9  ( 2015-05-28 08:58:55 -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



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

Seen: 4,500 times

Last updated: Oct 25 '12