PCL-描述子-FPFH
FPFH描述子建立
1.原始点云
变量声明,为了对场景和模型做匹配,设计了1,2两个变量。
pcl::PointCloud<PointType> cloud1, cloud2;
pcl::PointCloud<NormalType> cloud1_normals, cloud2_normals;
pcl::PointCloud<PointType> cloud1_keypoints, cloud2_keypoints;
pcl::PointCloud<pcl::FPFHSignature33> cloud1_fpfh, cloud2_fpfh;
2.提取关键点
体素和均匀采样速度较快
void compute_filters_voxel_grid(float leaf_size)
{
pcl::VoxelGrid<PointType> voxel_grid;
voxel_grid.setLeafSize(leaf_size, leaf_size, leaf_size);
voxel_grid.setInputCloud(cloud1.makeShared());
voxel_grid.filter(cloud1_keypoints);
voxel_grid.setInputCloud(cloud2.makeShared());
voxel_grid.filter(cloud2_keypoints);
}
void compute_filters_uniform_sample(float leaf_size)
{
pcl::UniformSampling<PointType> filter;
filter.setRadiusSearch(leaf_size);
filter.setInputCloud(cloud1.makeShared());
filter.filter(cloud1_keypoints);
filter.setInputCloud(cloud2.makeShared());
filter.filter(cloud2_keypoints);
}
3.法线建立
对关键点提取法线
template <typename T>
void compute_normals(float radius, T cloud1, T cloud2)
{
// Estimate the normals.
pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> normalEstimation;
normalEstimation.setRadiusSearch(radius);
normalEstimation.setNumberOfThreads(12);
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);
normalEstimation.setSearchMethod(kdtree);
normalEstimation.setInputCloud(cloud1.makeShared());
normalEstimation.compute(cloud1_normals);
normalEstimation.setInputCloud(cloud2.makeShared());
normalEstimation.compute(cloud2_normals);
}
4.FPFH描述子建立
void calculate_FPFH(float radius)
{
pcl::FPFHEstimationOMP<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh;
fpfh.setRadiusSearch(radius);
fpfh.setNumberOfThreads(12);
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);
fpfh.setSearchMethod(kdtree);
fpfh.setInputCloud(cloud1_keypoints.makeShared());
//fpfh.setSearchSurface(cloud1.makeShared());
fpfh.setInputNormals(cloud1_normals.makeShared());
fpfh.compute(cloud1_fpfh);
fpfh.setInputCloud(cloud2_keypoints.makeShared());
//fpfh.setSearchSurface(cloud2.makeShared());
fpfh.setInputNormals(cloud2_normals.makeShared());
fpfh.compute(cloud2_fpfh);
}
如上是FPFH描述子核心代码,如需其他代码,可留言。