pcl::EuclideanClusterExtraction 未能提取第一个簇

问题描述 投票:0回答:1

我正在尝试从点云中提取第一个簇。这是我的代码

输入

cluster_pcd_ptr
tolerance

身体

pcl::search::KdTree<pcl::PointXYZ>::Ptr cluster_tree(
    new pcl::search::KdTree<pcl::PointXYZ>);
cluster_tree->setInputCloud(cluster_pcd_ptr);

std::vector<pcl::PointIndices> cluster_indices;
pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;
ec.setClusterTolerance(tolerance);
ec.setSearchMethod(cluster_tree);
ec.setInputCloud(cluster_pcd_ptr);
ec.extract(cluster_indices);

pcl::PointIndices::Ptr patch_indices_ptr(new pcl::PointIndices);
patch_indices_ptr->header = cluster_indices[0].header;
patch_indices_ptr->indices = cluster_indices[0].indices;

pcl::ExtractIndices<pcl::PointXYZ> patch_extract;
patch_extract.setInputCloud(cluster_pcd_ptr);
patch_extract.setIndices(patch_indices_ptr);
pcl::PointCloud<pcl::PointXYZ>::Ptr patch_pcd_ptr(new pcl::PointCloud<pcl::PointXYZ>);
patch_extract.filter(*patch_pcd_ptr);

但我总是在

patch_extract.filter(*patch_pcd_ptr)
处遇到访问冲突读取位置错误。那么我的代码有什么问题吗?

c++ point-cloud-library pcl
1个回答
0
投票

我不认为你的代码有问题。我已经测试了你的代码,它运行正常。您可以添加判断来判断'patch_indices_ptr'的大小或'cluster_pcd_ptr'的大小是否为零。

© www.soinside.com 2019 - 2024. All rights reserved.