#include
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/kdtree/kdtree_flann.h>
int main(int argc, char** argv)
{
// 读取点云数据
pcl::PointCloudpcl::PointXYZ::Ptr cloud(new pcl::PointCloudpcl::PointXYZ); pcl::io::loadPCDFilepcl::PointXYZ(“cloud.pcd”, *cloud);
// 构建kd树
pcl::KdTreeFLANNpcl::PointXYZ kdtree;
kdtree.setInputCloud(cloud);
// 定义查询点C
pcl::PointXYZ C;
C.x = 1.0;
C.y = 2.0;
C.z = 3.0;
// 查找最近邻点
std::vector nearest_indices(1);
std::vector nearest_distances(1);
kdtree.nearestKSearch(C, 1, nearest_indices, nearest_distances);
// 输出最近邻点的坐标
std::cout << "Nearest neighbor found at index " << nearest_indices[0] << std::endl; std::cout << "x = " << cloud->points[nearest_indices[0]].x << std::endl;
std::cout << "y = " << cloud->points[nearest_indices[0]].y << std::endl;
std::cout << "z = " << cloud->points[nearest_indices[0]].z << std::endl;
return 0;
}
【无标题】
最新推荐文章于 2024-09-27 11:26:03 发布
该代码示例展示了如何使用PCL库读取PCD文件中的点云数据,构建KdTree,并执行最近邻搜索。程序首先加载cloud.pcd文件,然后定义一个查询点C,并通过KdTree找到该点的最近邻,最后输出最近邻点的坐标。
摘要由CSDN通过智能技术生成