https://adamshan.blog.csdn.net/article/details/82901295跑点云地面分割的代码ROS功能包编译不通过,请问什么问题?
/home/vickytwan/pcd_ws/src/pcl_test/src/pcl_test_core.cpp: In member function ‘void PclTestCore::clip_above(double, pcl::PointCloud<pcl::PointXYZI>::Ptr, pcl::PointCloud<pcl::PointXYZI>::Ptr)’:
/home/vickytwan/pcd_ws/src/pcl_test/src/pcl_test_core.cpp:34:69: error: no matching function for call to ‘pcl::ExtractIndices::setIndices(boost::detail::sp_if_not_array<pcl::PointIndices>::type)’
34 | cliper.setIndices(boost::make_shared<pcl::PointIndices>(indices));
|
根据错误提示,问题出现在 pcl::ExtractIndices 的 setIndices 方法上。具体来说,pcl::ExtractIndices 在 setIndices 方法中要求传入的参数必须是 pcl::PointIndices 类型,但是实际上传入的是 boost::shared_ptrpcl::PointIndices 类型。这个问题可能是由于 PCL 版本更新或者参数类型定义的变化导致的。
解决方法可以尝试修改 pcl_test_core.cpp 中 clip_above 函数的第一行代码,将其修改为如下内容:
void PclTestCore::clip_above(double clip_height, pcl::PointCloud<pcl::PointXYZI>::Ptr input_cloud, pcl::PointCloud<pcl::PointXYZI>::Ptr clipped_cloud)
{
// Create the filtering object
pcl::ExtractIndices<pcl::PointXYZI> cliper;
pcl::PointIndices::Ptr indices(new pcl::PointIndices());
for (int i = 0; i < input_cloud->points.size(); i++)
{
if (input_cloud->points[i].z <= clip_height)
{
clipped_cloud->points.push_back(input_cloud->points[i]);
}
else
{
indices->indices.push_back(i);
}
}
cliper.setInputCloud(input_cloud);
cliper.setIndices(indices);
cliper.setNegative(true);
cliper.filter(*clipped_cloud);
}
这里通过创建一个指向 pcl::PointIndices 对象的指针来避免 setIndices 方法的类型问题。同时,对于 setNegative 方法的调用,应该传入 true 而不是 false,以保证保留点云中高于截止高度的点。修改完成后,重新编译运行,看看是否能够成功。
根据代码中的错误提示来看,问题出现在 pcl::ExtractIndices 类中的 setIndices() 方法调用上,错误信息指出没有匹配的函数。
根据 pcl 的官方文档,在 pcl::ExtractIndices 类中有多个名为 setIndices() 的方法,不同的 setIndices() 方法接受不同类型的参数。在这个代码中,setIndices() 方法需要一个 pcl::PointIndices 类型的参数,但是代码中使用了一个 boost::shared_ptrpcl::PointIndices 类型的参数。因此编译器无法找到匹配的函数,导致编译错误。
为了解决这个问题,需要将 boost::shared_ptrpcl::PointIndices 类型的参数转换为 pcl::PointIndices 类型的参数。可以使用 * 运算符解引用 boost::shared_ptr,将其转换为指向实际对象的指针,然后再将指针传递给 setIndices() 方法。修改后的代码如下:
void PclTestCore::clip_above(double clip_height, pcl::PointCloud<pcl::PointXYZI>::Ptr input_cloud, pcl::PointCloud<pcl::PointXYZI>::Ptr output_cloud) {
pcl::PointIndices indices;
for (int i = 0; i < input_cloud->size(); i++) {
if (input_cloud->points[i].z > clip_height) {
indices.indices.push_back(i);
}
}
pcl::ExtractIndices<pcl::PointXYZI> cliper;
cliper.setInputCloud(input_cloud);
cliper.setIndices(&indices); // 将指针传递给 setIndices() 方法
cliper.setNegative(true);
cliper.filter(*output_cloud);
}
这样就可以正确编译代码了。