Created
March 18, 2020 13:49
-
-
Save yuki-inaho/71ffa03a7cb7811b8c6bb3f0a9b54e8d to your computer and use it in GitHub Desktop.
PointCloud2_to_PCD.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ros_numpy | |
| import rospy | |
| from sensor_msgs.msg import PointCloud2 | |
| import open3d as o3d | |
| class PointCloud2Converter: | |
| def __init__(self): | |
| self.pc_npy = None | |
| self.sub_pc = rospy.Subscriber('/aspara_detector/ground_point_cloud', PointCloud2, self.callback_pcl) | |
| self.pcd = o3d.geometry.PointCloud() | |
| def callback_pcl(self, pc2_msg): | |
| rospy.loginfo("PointCloud acquired") | |
| self.pc_npy = ros_numpy.point_cloud2.pointcloud2_to_xyz_array(pc2_msg) | |
| self.pcd.points = o3d.utility.Vector3dVector(self.pc_npy) | |
| o3d.io.write_point_cloud("points.pcd", self.pcd) | |
| def run(self): | |
| rate = rospy.Rate(10) | |
| while not rospy.is_shutdown(): | |
| rate.sleep() | |
| if __name__ == "__main__": | |
| rospy.init_node("ui", anonymous=True) | |
| conv = PointCloud2Converter() | |
| conv.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment