一、在point_type.hpp中添加自定义的特征
struct MySignature20
{
float histogram[20];
static int descriptorSize() { return 20; }
friend std::ostream& operator << (std::ostream& os, const MySignature20& p);
};
二、在point_representation.h中添加如下代码,以使pcl中的FLANN能够识别自定义的descriptor
template <>
class DefaultPointRepresentation <MySignature20> : public PointRepresentation <MySignature20>
{
public:
DefaultPointRepresentation()
{
nr_dimensions_ = 20;
trivial_ = false;
}
virtual void
copyToFloatArray(const MySignature20& p, float* out) const
{
for (int i = 0; i < nr_dimensions_; ++i)
out[i] = p.histogram[i];
}
};
三、正确KdTreeFLANN类寻找最邻近描述符
(1)为了包含模块化算法
方法一:
解决方案:属性》预处理器》添加:PCL_NO_PRECOMPILE
方法二:源码中添加
#define PCL_NO_PRECOMPILE
(2)应用示例
//PHFH
pcl::FPFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh;
fpfh.setInputCloud(cloud);
fpfh.setInputNormals(cloud_normals);
pcl::search::KdTree<PointXYZ>::Ptr tree1(new pcl::search::KdTree<pcl::PointXYZ>);
fpfh.setSearchMethod(tree1);
fpfh.setRadiusSearch(0.6);
pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs(new pcl::PointCloud<pcl::FPFHSignature33>());
fpfh.compute(*fpfhs);
pcl::PointCloud<pcl::MySignature20>::Ptr myfpfh(new pcl::PointCloud<pcl::MySignature20>());
pcl::MySignature20 pi;
for (size_t i = 0; i < fpfhs->size(); i++)
{
for (size_t j = 0; j < 20; j++)
{
pi.histogram[j] = fpfhs->points[i].histogram[j];
}
myfpfh->push_back(pi);
}
pcl::KdTreeFLANN<pcl::MySignature20> kd_tree;
kd_tree.setInputCloud(myfpfh);
pi = myfpfh->points[100];
int k = 10;
std::vector<int> pt_idx_search(k);
std::vector<float> pt_sqr_dis(k);
kd_tree.nearestKSearch(pi, k, pt_idx_search, pt_sqr_dis);