C++ 使用 PCL 库动态创建 PointIndices 容器:聚类循环示例
#include\x20<pcl/point_cloud.h> #include\x20<pcl/point_types.h> #include\x20<pcl/segmentation/extract_clusters.h>
int\x20main() { \x20\x20//\x20创建点云数据 \x20\x20pcl::PointCloudpcl::PointXYZ::Ptr\x20cloud(new\x20pcl::PointCloudpcl::PointXYZ); \x20\x20//\x20设置点云数据
\x20\x20//\x20创建聚类对象 \x20\x20pcl::EuclideanClusterExtractionpcl::PointXYZ\x20ec; \x20\x20ec.setInputCloud(cloud); \x20\x20//\x20设置聚类参数
\x20\x20//\x20定义容器,用于存储聚类结果 \x20\x20std::vectorpcl::PointIndices\x20cluster_indices;
\x20\x20//\x20循环创建pcl::PointIndices容器 \x20\x20for\x20(int\x20i\x20=\x200;\x20i\x20<\x20num_iterations;\x20++i) \x20\x20{ \x20\x20\x20\x20//\x20聚类 \x20\x20\x20\x20ec.extract(cluster_indices);
\x20\x20\x20\x20//\x20输出聚类结果 \x20\x20\x20\x20for\x20(const\x20auto&\x20indices\x20:\x20cluster_indices) \x20\x20\x20\x20{ \x20\x20\x20\x20\x20\x20std::cout\x20<<\x20"Cluster\x20with\x20"\x20<<\x20indices.indices.size()\x20<<\x20"\x20points"\x20<<\x20std::endl; \x20\x20\x20\x20} \x20\x20}
\x20\x20return\x200; }
原文地址: https://www.cveoy.top/t/topic/pSqb 著作权归作者所有。请勿转载和采集!