PCL:当我在setConditionFunction中使用std::bind 时,没有合适的转换函数



我很抱歉问这个问题,但我对C++真的很陌生。

我想在我的类函数中使用pcl::ConditionalEuclideanClustering::setConditionFunction,并使用另一个类函数作为参数。

我已经引用了链接和其他代码。但是当我使用cec.setConditionFunction (std::bind(&tube_detect::customRegionGrowing, this, _1, _2, _3));时仍然有问题:

没有合适的转换函数,从"std::_Bind<std::_Mem_fn>((const PointTypeFull &, const PointTypeFull &, 浮点("存在

这是我的代码:

#include <ros/ros.h>
#include <pcl/point_cloud.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/console/time.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/segmentation/conditional_euclidean_clustering.h>
typedef pcl::PointXYZI PointTypeIO;
typedef pcl::PointXYZINormal PointTypeFull;
class tube_detect{
public:
pcl::PointCloud<PointTypeIO>::Ptr cloud_in, cloud_out;
pcl::PointCloud<PointTypeFull>::Ptr cloud_with_normals ;
pcl::IndicesClustersPtr clusters , small_clusters, large_clusters;
pcl::search::KdTree<PointTypeIO>::Ptr search_tree;
pcl::console::TicToc tt;
// tube_detect();
void copy_load_point_cloud(pcl::PointCloud<PointTypeFull>::Ptr copy_cloud_with_normal);
void modify_intensity_indices();
void normal();
bool customRegionGrowing(const PointTypeFull& point_a, const PointTypeFull& point_b, float squared_distance);
};
void tube_detect::normal(){
// Set up a Conditional Euclidean Clustering class
std::cerr << "Segmenting to clusters...n", tt.tic ();
pcl::ConditionalEuclideanClustering<PointTypeFull> cec (true);
cec.setInputCloud (cloud_with_normals);

// **here is the error happen**
cec.setConditionFunction (std::bind(&tube_detect::customRegionGrowing, this, _1, _2, _3));

cec.setClusterTolerance (1.0);
cec.setMinClusterSize (cloud_with_normals->points.size () / 1000);
cec.setMaxClusterSize (cloud_with_normals->points.size () / 5);
cec.segment (*clusters);
cec.getRemovedClusters (small_clusters, large_clusters);
std::cerr << ">> Done: " << tt.toc () << " msn";
}
bool 
tube_detect::customRegionGrowing (const PointTypeFull& point_a, const PointTypeFull& point_b, float squared_distance)
{
Eigen::Map<const Eigen::Vector3f> point_a_normal = point_a.getNormalVector3fMap (), point_b_normal = point_b.getNormalVector3fMap ();
if (squared_distance < 1)
{
if (std::abs (point_a.intensity - point_b.intensity) < 8.0f)
return (true);
if (std::abs (point_a_normal.dot (point_b_normal)) < 0.1)
return (true);
}
else
{
if (std::abs (point_a.intensity - point_b.intensity) < 3.0f)
return (true);
}
return (false);
}

====

===============================

我正在使用PCL-1.7,它是在安装ROS-Kinetic时安装的。

setConditionFunction仅定义为:

inline void
setConditionFunction (bool (*condition_function) (const PointT&, const PointT&, float)) 
{
condition_function_ = condition_function;
}

所以,我不能使用std::bind.

顺便说一句,似乎我不能使用更高的 pcl 版本。

对于每个 ROS 发行版,根据 REP 103,我们仅正式支持 1 个 PCL 版本。

我处理了一个类似的问题。我想按变量参数external_parameter过滤,但无法通过参数列表传递它,因为pcl::ConditionalEuclideanClustering::setConditionFunction只接受定义的参数列表的对象(const auto&point_a,const auto&point_b,float squared_distance(。

解决方案是传递一个 lambda 函数,该函数通过引用捕获外部参数......

auto lambda = [&external_parameter](const auto& point_a, const auto& point_b, float squared_distance){
if(std::abs (point_a.some_value - point_b.some_value) < external_parameter)
return true;
else
return false;
};

。并将引用传递给cec.

cec.setConditionFunction(lambda);

我希望这能进一步帮助您。

最新更新