int main() { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::io::loadPCDFile("cloud71_icp_result.pcd", *cloud); float resolution = 0.5; //体素的大小 cout << "before点云" << cloud->points.size() << endl; pcl::octree::OctreePointCloud<pcl::PointXYZ> octree(resolution); octree.setInputCloud(cloud); octree.addPointsFromInputCloud(); vector<PointT, AlignedPointT> voxel_centers; octree.getOccupiedVoxelCenters(voxel_centers); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_core(new pcl::PointCloud<pcl::PointXYZ>); cloud_core->width = voxel_centers.size(); cloud_core->height = 1; cloud_core->points.resize(cloud_core->height*cloud_core->width); for (size_t i = 0; i < voxel_centers.size() - 1; i++) { cloud_core->points[i].x = voxel_centers[i].x; cloud_core->points[i].y = voxel_centers[i].y; cloud_core->points[i].z = voxel_centers[i].z; } pcl::PCDWriter writer; writer.write("cloud71_icp_result_core2.pcd", *cloud_core); cout << voxel_centers.size() << endl; system("pause"); return 0; }
时间: 2024-04-19 14:28:22 浏览: 34
PCL点云模型文件,可以用PCL库读取学习
这段代码主要是使用PCL库对一个点云数据进行体素化处理。首先,通过`pcl::io::loadPCDFile`函数加载了一个点云文件"cloud71_icp_result.pcd",然后定义了体素的大小为0.5。接下来,创建了一个`pcl::octree::OctreePointCloud<pcl::PointXYZ>`对象,并将加载的点云设置为其输入点云,然后调用`addPointsFromInputCloud`函数将点云添加到八叉树中。然后,通过调用`getOccupiedVoxelCenters`函数获取体素化后的点云的中心点坐标,并将其存储在`voxel_centers`向量中。接着,创建了一个新的点云对象`cloud_core`,设置其宽度和高度,然后将体素化后的点云坐标赋值给它。最后,使用`pcl::PCDWriter`将体素化后的点云保存为"cloud71_icp_result_core2.pcd"文件,并输出体素化后的点云的数量。最后,通过`system("pause")`函数暂停程序的执行。
阅读全文