Problems reading PointCloud2 message
Hello everyone, I'm trying to find an object by color and then get the distance to it. However I'm having trouble reading the PointCloud2 message.
I can see through RVIZ that the topic is sending the right cloud, however when I try to read it through my code I am having some issues:
- The x,y,z are sometimes negative
- The rgb values are almost zero (6.82247660989e-39 for example).
My code for getting the RGB values of the cloud:
generator = pc2.read_points(cloud, field_names = ['rgb'], skip_nans = True)
matrix = np.empty(shape = (cloud.height, cloud.width), dtype=float)
for i, element in enumerate(generator):
print element[0] // for debugging reasons, prints a near-zero float
np.put(matrix, [[i / cloud.width, i % cloud.width]], [element[0]])
Note that the variable cloud is the PointCloud2 message recieved from the topic, and pc2 is the namespace PointCloud2.
What am I doing wrong, and how can I get a matrix to use with OpenCV2?
I'm using ROS Indigo, running through Gazebo. Thanks in advance