可以使用PCL里面现成的函数pcl::copyPointCloud()
:
#include <pcl/common/impl/io.h>
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ> ());
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud_xyzrgba (new pcl::PointCloud<pcl::PointXYZRGBA> ());
pcl::copyPointCloud(*cloud_xyz, *cloud_xyzrgba);
函数原型:
PCL_EXPORTS void copyPointCloud (const pcl::PCLPointCloud2 &cloud_in, pcl::PCLPointCloud2 &cloud_out);
或者手动转换:
cloud_xyzrgba->points.resize(cloud_xyz->size());
for (size_t i = 0; i < cloud_xyz->points.size(); i++) {
cloud_xyzrgb->points[i].x = cloud_xyz->points[i].x;
cloud_xyzrgb->points[i].y = cloud_xyz->points[i].y;
cloud_xyzrgb->points[i].z = cloud_xyz->points[i].z;
}