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

Getting an (x, y) -> depth map in Python from a Kinect? [closed]

asked 2011-05-27 02:50:28 -0600

Pi Robot gravatar image

updated 2016-10-24 09:03:33 -0600

ngrennan gravatar image

I'm going around in circles trying to solve what I think is a simple problem: using Python (not C++), I would like to get the depth values corresponding to the points in the RGB image returned from the Kinect at a given (x, y) coordinate. I am subscribing to /camera/rgb/image_color and using cv_bridge and OpenCV's face detector to get the bounding box around a face. I then want to get the depth values for each point (or a subsample of points) in that box. So I need to be able to pick (x, y) coordinates (which I know) from within the box and get back the depth values for those points.

I tried subscribing to /camera/depth/image which is a 32FC1 image type and I thought this was going to work but I ran into "index out of range" errors when accessing points that should have been within the proper width and height boundaries of the image.

Although I realize there are no Python bindings for PCL )-:, I found this nice utility on this forum so I'm wondering if I should be using point clouds rather than images to get the depth values?

Any ideas?

Thanks
patrick

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Wim
close date 2011-08-02 11:37:19

Comments

"I tried subscribing to /camera/depth/image which is a 32FC1 image type ... but I ran into "index out of range" errors" - that's weird. In c++ this works.
Felix Endres gravatar image Felix Endres  ( 2011-05-27 03:25:43 -0600 )edit
Thanks Felix--see my answer below. BTW, do you get a black border (all 0's) around your depth image? It looks to be about 5 pixels on a 160x120 image.
Pi Robot gravatar image Pi Robot  ( 2011-05-27 06:28:43 -0600 )edit
No, I get mostly NaNs at the border. But it's not like a rectangular frame, because of the lens distortion.
Felix Endres gravatar image Felix Endres  ( 2011-05-27 23:44:49 -0600 )edit
OK, when I look more closely on a higher resolution image I can see it is not perfectly rectangular. Also it looks like my script was converting NaNs to 0's.
Pi Robot gravatar image Pi Robot  ( 2011-05-28 01:22:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-05-27 06:27:53 -0600

Pi Robot gravatar image

Thanks to Felix's comment, I went back to the /camera/depth/image approach and finally realized I was swapping rows and columns in one of the statements which is why I was getting "index out of range errors". So repeat after me: an image that has m X n pixels has n X m rows and columns. :-)

--patrick

edit flag offensive delete link more

Comments

hello I want to subscribe to rgb and depth image simultaneously and publish it to multiple topics using one node in cvbrige, plz plz can u provide me ur code, I m in trouble

ros gravatar image ros  ( 2013-06-12 08:27:37 -0600 )edit

Question Tools

Stats

Asked: 2011-05-27 02:50:28 -0600

Seen: 3,465 times

Last updated: May 27 '11