在使用PCL点云库时,常因为不同的点云数据存储方式不同,而导致在PCL点云库时带来一些麻烦。今天对常见在PCL库的一些点云数据类型之间的转换方式进行历出,方便大家参考。
常见ROS msg
, PCLPointCloud2
, PointXYZ
三种数据类型之间的转换如下:
1.ROS msg to PCLPointCloud2
const sensor_msgs::PointCloud2ConstPtr& cloud_msg
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl_conversions::toPCL(*cloud_msg, *cloud);
2.PCLPointCloud2 to ROS msg
sensor_msgs::PointCloud2 output;
pcl::PCLPointCloud2 cloud_filtered;
pcl_conversions::moveFromPCL(cloud_filtered, output);
3.PointXYZ to PCLPointCloud2
pcl::PointCloud<pcl::PointXYZ> local_map;
pcl::PCLPointCloud2* local_map_pc2_ptr = new pcl::PCLPointCloud2;
pcl::toPCLPointCloud2(local_map, *local_map_pc2_ptr);
4.PCLPointCloud2 to PointXYZ
pcl::PCLPointCloud2 local_map_pc2;
pcl::fromPCLPointCloud2(local_map_pc2, local_map);
5.ROS msg to PointXYZ
sensor_msgs::PointCloud2 output;
pcl::PointCloud<pcl::PointXYZ> icp_cloud_;
pcl::fromROSMsg(output, icp_cloud_);
6.PointXYZ to ROS msg
pcl::toROSMsg(local_map,output);
7.
pointer to const pointer
特别的,有时需要将指针转为常量指针
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
还有PCD格式与其他的点云文件格式的转换后期更新!