基于PFH特征匹配的测试函数如下:
void algoritmpfh()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr target(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr ptr1(new pcl::PointCloud<pcl::PointXYZ>);
//pcl::io::loadPCDFile("table_scene_mug_stereo_textured.pcd", *target);
pcl::io::loadPCDFile("0000.pcd", *target);
//pcl::PointXYZ min_coordinate, max_coordinate;
//ofstream fout("results.txt", ios::app);
pcl::VoxelGrid<pcl::PointXYZ> sor;
sor.setInputCloud(target);
sor.setLeafSize(15, 15, 15);
sor.filter(*ptr1);
pcl::io::savePCDFileBinary("0001.pcd",*ptr1);
//pcl::getMinMax3D(*ptr1, min_coordinate, max_coordinate);
// Create the normal estimation class, and pass the input dataset to it
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud(ptr1);
// Create an empty kdtree representation, and pass it to the normal estimation object.
// Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
ne.setSearchMethod(tree);
// Output datasets
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
// Use all neighbors in a sphere of radius 3cm
ne.setRadiusSearch(50);
// Compute the features
ne.compute(*cloud_normals);
// Create the PFH estimation class, and pass the input dataset+normals to it
pcl::PFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::PFHSignature125> pfh;
pfh.setInputCloud(ptr1);
pfh.setInputNormals(cloud_normals);
// alternatively, if cloud is of tpe PointNormal, do pfh.setInputNormals (cloud);
// Create an empty kdtree representation, and pass it to the PFH estimation object.
// Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
//pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
//pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree (new pcl::KdTreeFLANN<pcl::PointXYZ> ()); -- older call for PCL 1.5-
pfh.setSearchMethod(tree);
// Output datasets
pcl::PointCloud<pcl::PFHSignature125>::Ptr pfhs(new pcl::PointCloud<pcl::PFHSignature125>());
// Use all neighbors in a sphere of radius 5cm
// IMPORTANT: the radius used here has to be larger than the radius used to estimate the surface normals!!!
pfh.setRadiusSearch(0.05);
// Compute the features
pfh.compute(*pfhs);
// cloud_normals->points.size () should have the same size as the input cloud->points.size ()*
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
viewer.reset(new pcl::visualization::PCLVisualizer("viewer", true));
//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handle(ptr1, 0, 255, 0);
//viewer->addPointCloud(ptr1, handle, "cloud");
viewer->addPointCloudNormals<pcl::PointXYZ, pcl::Normal>(ptr1, cloud_normals);
//viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");
viewer->resetCamera();
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
}
system("pause");
}