eric-wieser/ros_numpy

confuse readme about trasform numpy to pointcloud2

lianghongzhuo opened this issue · 0 comments

When I try to transform numpy to pointcloud2, the example on readme file is confusing me:

data = np.zeros(100, dtype=[
  ('x', np.float32),
  ('y', np.float32),
  ('vectors', np.float32, (3,))
])
data['x'] = np.arange(100)
data['y'] = data['x']*2
data['vectors'] = np.arange(100)[:,np.newaxis]

msg = ros_numpy.msgify(PointCloud2, data)

In this example, "x" filed and "y" filed has a size 100, and filed "vectors" has a size 100*3
This makes me thinking that filed "vectors" should put the points I want to transform to ros msg, and "x" filed and "y" filed is the indices of it on the depth image.
This is wrong.
I took some time to realize it. So, to avoid confusion to other users, I propose to update the readme file example as follows:

points = np.random.rand(100,3)  
data = np.zeros(100, dtype=[
  ('x', np.float32),
  ('y', np.float32),
  ('z', np.float32),
])
data['x'] = points[:, 0]
data['y'] = points[:, 1]
data['z'] = points[:, 2]
msg = ros_numpy.msgify(PointCloud2, data)