"#include <pcl/point_cloud.h>\n#include <pcl/point_types.h>\n#include <pcl/filters/extract_indices.h>\n\ntypedef pcl::PointXYZRGB PointT;\ntypedef pcl::PointCloud PointCloudT;\n\nint main()\n{\n pcl::PointCloudpcl::PointXYZRGB::Ptr cloud3(new pcl::PointCloudpcl::PointXYZRGB);\n std::vector<pcl::PointCloudpcl::PointXYZRGB::Ptr> yezi;\n pcl::PointCloudpcl::PointXYZRGB::Ptr jinggan(new pcl::PointCloudpcl::PointXYZRGB);\n\n // 假设cloud3和yezi已经被填充为点云数据\n\n // 将yezi中的点云合并为一个大点云\n pcl::PointCloudpcl::PointXYZRGB::Ptr merged(new pcl::PointCloudpcl::PointXYZRGB);\n for (const auto& cloud : yezi)\n {\n *merged += *cloud;\n }\n\n // 定义一个点云索引容器\n pcl::PointIndices::Ptr indices(new pcl::PointIndices);\n\n // 遍历cloud3中的点,找到不在merged中的点的索引\n for (int i = 0; i < cloud3->size(); ++i)\n {\n const auto& point = cloud3->points[i];\n if (!pcl::isFinite(point)) continue; // 跳过无效点\n\n // 判断点是否在merged中\n bool found = false;\n for (int j = 0; j < merged->size(); ++j)\n {\n const auto& mergedPoint = merged->points[j];\n if (pcl::isSamePoint(point, mergedPoint)) // 判断点是否相同\n {\n found = true;\n break;\n }\n }\n\n // 如果点不在merged中,则将索引添加到indices中\n if (!found)\n {\n indices->indices.push_back(i);\n }\n }\n\n // 根据索引提取不同点云\n pcl::ExtractIndicespcl::PointXYZRGB extract;\n extract.setInputCloud(cloud3);\n extract.setIndices(indices);\n extract.setNegative(false); // 保留indices中的点\n extract.filter(*jinggan);\n\n return 0;\n}\n"上述代码会遍历cloud3中的每个点,与yezi中的点进行比较,如果不在yezi中,则将其索引添加到indices中。然后,使用pcl::ExtractIndicescloud3中的这些索引对应的点提取到jinggan中。最后,jinggan中将包含cloud3中与yezi不同的点。"

PCL库提取两个点云不同点:C++代码示例

原文地址: https://www.cveoy.top/t/topic/pTTe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录