Rosanswers logo

I have subscribed to /camera/depth/points to get the PointCloud2 data from kinect. When I try to print the PointCloud2 data alone leaving out the headers, height and width etc i get a pool of garbage values. How do i print the 'data' field alone.? I am able to get the output without any garbage if i print the entire msg.

Here is my code.

#!/usr/bin/env python
import roslib
import rospy
from sensor_msgs.msg import PointCloud2

def callback(msg):
    print len((data.data))
    print msg.data

def kinect_depth():
    rospy.init_node('kinect_depth', anonymous=True)
    global listener 
    listener = rospy.Subscriber("/camera/depth/points", PointCloud2, callback)

if __name__=='__main__':

Thanks in advance.

Originally posted by gaussian on ROS Answers with karma: 88 on 2015-02-01

Post score: 0


1 Answer 1


Rosanswers logo

The PointCloud2 is packed into a format that is not automatically unpacked. sensor_msgs/point_cloud2.py can help you unpack the data (though it is a bit slow).

Alternatively, if you just want depth, and not x,y,z points, you could subscribe to the depth image and use cv_bridge to get the data.

Originally posted by Dan Lazewatsky with karma: 9115 on 2015-02-01

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by gaussian on 2015-02-01:
Thanks for your reply. I will look into it. I want the x,y,z data without converting the pointcloud2 into .pcd file. Is it possible to get that?

Comment by Dan Lazewatsky on 2015-02-01:
Yes, that's what the functions in point_cloud2.py do.

Comment by gaussian on 2015-02-02:
@Dan Lazewatsky If I use the latter method of converting the depthimage into grayscale image, how can I convert that into depth in some unit. As the grayscale value in the image are relative to largest depth. Am i right? Is there any const conversion factor between grayscale value and deptin in 'm'?

Comment by Dan Lazewatsky on 2015-02-02:
Using openni_camera at least, depth images contain uint16 depths in mm.


Your Answer

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