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

getting and reading depth values from kinect2 sensor

asked 2017-03-15 17:03:59 -0500

BHAASKARR gravatar image

updated 2017-03-15 17:37:51 -0500

Hi All,

I am very new to ROS, I installed ROS and also libfreenect2 Driver and iai_kinect2 library (are required software for the kinect v2 to interface with ROS).

Ubantu 14.04 ROS, libreenect2, Iai_kinect2

I have below data when i use 'rostopic list' command

bhaskar@D125-40806Linux:~$ rostopic list /kinect2/hd/camera_info
/kinect2/hd/image_color
/kinect2/hd/image_color/compressed
/kinect2/hd/image_color_rect
/kinect2/hd/image_color_rect/compressed
/kinect2/hd/image_depth_rect
/kinect2/hd/image_depth_rect/compressed
/kinect2/hd/image_mono
/kinect2/hd/image_mono/compressed
/kinect2/hd/image_mono_rect
/kinect2/hd/image_mono_rect/compressed
/kinect2/qhd/camera_info
/kinect2/qhd/image_color
/kinect2/qhd/image_color/compressed
/kinect2/qhd/image_color_rect
/kinect2/qhd/image_color_rect/compressed
/kinect2/qhd/image_depth_rect
/kinect2/qhd/image_depth_rect/compressed
/kinect2/qhd/image_mono
/kinect2/qhd/image_mono/compressed
/kinect2/qhd/image_mono_rect
/kinect2/qhd/image_mono_rect/compressed
/kinect2/sd/camera_info
/kinect2/sd/image_color_rect /kinect2/sd/image_color_rect/compressed
/kinect2/sd/image_depth
/kinect2/sd/image_depth/compressed
/kinect2/sd/image_depth_rect
/kinect2/sd/image_depth_rect/compressed
/kinect2/sd/image_ir
/kinect2/sd/image_ir/compressed
/kinect2/sd/image_ir_rect
/kinect2/sd/image_ir_rect/compressed
/rosout
/rosout_agg

Can you please tell what each list describes ? I would like to know which one is useful from above to get depth values of image and also how to read the those depth data ?

I used below command
rostopic echo /kinect2/sd/image_depth

I got below values

header:
seq: 1298
stamp:
secs: 1489614685
nsecs: 946450545
frame_id: kinect2_ir_optical_frame
height: 424
width: 512
encoding: 16UC1
is_bigendian: 0
step: 1024
data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 30, 244, 28, 206, 4, 0, 0, 0, 0, 57, 5, 0, 0, 27, 9, 159, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 4, 0, 0, 0, 0, 0, 0, 34, 37, 0, 0, 0, 0, 42, 9, 238, 32, 0, 0, 0, 0, 0,.................]

Can you please explain what each value represents above ?

Thanks in advance,
Bhaskar.

edit retag flag offensive close merge delete

Comments

1 Answer

Sort by ยป oldest newest most voted
4

answered 2017-03-21 04:47:06 -0500

Akif gravatar image

updated 2017-07-17 06:24:30 -0500

sd, qhd and hd are resolutions of the image. Details are given in iai_kinect2 repo.

For topic names,

_ir: infrared image

_color: color image

_depth: depth_image

additional _rect is for rectified image.

If you use depth_image_proc, with point_cloud_xyzrgb nodelet, you can convert depth images to point clouds.

Update:

For the depth values, asked in comments below, you need to check encoding. Encoding given in the question is: encoding: 16UC1 . This means 16-bits unsigned short with 1 channel. So each depth is represented with 2 bytes. To convert these bytes to depth, you should also check is_bigendian: 0 . In this question byte order is little-endian. As a result, depth = data[i] + (data[i + 1] << 8) which is also mentioned in comments below.

The point is, you need to check encoding and endianness.

edit flag offensive delete link more

Comments

Thank you @Akif for your explanation.

BHAASKARR gravatar image BHAASKARR  ( 2017-03-22 15:37:45 -0500 )edit

If i use rostopic echo /kinect2/sd/image_depth
can you help me what does each value represents here data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 177, 30, 244, 28, 206, 4, 0, 0, 0, 0, 57, 5, 0, 0, 27, 9, 159, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 4, 0, 0, 0, 0, 0, 0, 34, 37, 0, 0, 0, 0, 42,

BHAASKARR gravatar image BHAASKARR  ( 2017-03-22 15:40:10 -0500 )edit

Hi,

Did you find a way to convert the depth data to MM or any measuring unit ?

Abdu gravatar image Abdu  ( 2017-07-16 17:17:17 -0500 )edit

temp_val = depth_image->data[index] + (depth_image->data[index + 1] << 8);

      200 + 3 (shift left by 8)

      =~96 cm
BHAASKARR gravatar image BHAASKARR  ( 2017-07-17 06:08:47 -0500 )edit

Sorry for bothering you, but I am new in ROS and Kinect 2, would you please give me more details, how can i use this formula. Right now, when I run rostopic echo /kinect2/sd/image_depth I am getting random data I dont know how to make it useful

Abdu gravatar image Abdu  ( 2017-07-19 09:44:38 -0500 )edit

The data you will get will be something like this

data: [0,0,0,0,......200,3,.......114,4,0,0,0,0.....]

I hope each pair represents one pixel and by using each pair, we can calculate the distance like =200+3(shift left by 8 times) //do this calculation by converting to decimals//

BHAASKARR gravatar image BHAASKARR  ( 2017-07-19 15:27:10 -0500 )edit

=11001000 + 1100000000 =968 mm

BHAASKARR gravatar image BHAASKARR  ( 2017-07-19 15:28:02 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-03-15 17:03:59 -0500

Seen: 1,509 times

Last updated: Jul 17 '17