Reading Pointcloud from .pcd to ROS PointCloud2

  pcl, point-cloud-library, point-clouds, python, ros

I want to create a simple python script to read some .pcd files and create a sensor_msgs::PointCloud2 for each in a rosbag.

I tried using the python-pcl library, but I’m probably doing something wrong when adding the points to the data field, because when playing the rosbag and checking with RViz and echoing the topic I get no points.

pcl_data = pcl.load(metadata_dir + "/" + pcd_path)

# get data
pcl_msg = sensor_msgs.msg.PointCloud2()
pcl_msg.data = np.ndarray.tobytes(pcl_data.to_array())
pcl_msg.header.stamp = rospy.Time(t_us/10000000.0)
pcl_msg.header.frame_id = "robot_1/navcam_sensor"

# Pusblish Pointcloud2 msg
outbag.write("/robot_1/pcl_navcam", pcl_msg, rospy.Time(t_us/10000000.0))

I also tried pypc without any luck as well.

How would you do it? Maybe there is a ToROSMsg method somewhere like in the cpp version of pcl?

Thank you

Source: Python Questions

LEAVE A COMMENT