PCL_FPFH特征提取及直方图显示

#include 
#include  
#include  
#include  
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include   

#define vtkRenderingCore_AUTOINIT 3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2) 
VTK_MODULE_INIT(vtkRenderingOpenGL);

int main()
{
	pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
	if (pcl::io::loadPCDFile("test_pcd.pcd", *cloud) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1  
	{
		PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在时,返回错误,终止程序。  
		return (-1);
	}

	pcl::PointCloud::Ptr cloud_fillter(new pcl::PointCloud);
	pcl::PassThrough pass;
	pass.setInputCloud(cloud);
	pass.setFilterFieldName("z");
	pass.setFilterLimits(0.0, 1.0);
	pass.filter(*cloud_fillter);

	pcl::PointCloud::Ptr cloud_filltered(new pcl::PointCloud);
	pcl::VoxelGrid sor;
	sor.setInputCloud(cloud_fillter);
	sor.setLeafSize(0.01f, 0.01f, 0.01f);
	sor.filter(*cloud_filltered);

	/*pcl::PointCloud::Ptr cloud_outerfillter(new pcl::PointCloud);
	pcl::RadiusOutlierRemoval outrem;
	outrem.setInputCloud(cloud_filltered);
	outrem.setRadiusSearch(0.8);
	outrem.setMinNeighborsInRadius(5);
	outrem.filter(*cloud_outerfillter);*/

	pcl::PointCloud::Ptr normals(new pcl::PointCloud());
	pcl::NormalEstimation ne;
	ne.setInputCloud(cloud_filltered);
	ne.setSearchSurface(cloud);
	pcl::search::KdTree::Ptr tree(new pcl::search::KdTree());
	ne.setSearchMethod(tree);
	pcl::PointCloud::Ptr cloud_normals(new pcl::PointCloud);
	ne.setRadiusSearch(0.03);
	ne.compute(*cloud_normals);

	pcl::FPFHEstimation fpfh;
	fpfh.setInputCloud(cloud_filltered);
	fpfh.setInputNormals(cloud_normals);
	pcl::search::KdTree::Ptr tree_1(new pcl::search::KdTree);
	fpfh.setSearchMethod(tree_1);
	pcl::PointCloud::Ptr fpfhs(new pcl::PointCloud());
	fpfh.setRadiusSearch(0.05);
	fpfh.compute(*fpfhs);


	boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));

	pcl::visualization::PCLPlotter plotter;
	plotter.addFeatureHistogram(*fpfhs,"fpfh",100);

	int v1(0);
	viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
	viewer->setBackgroundColor(0, 0, 0, v1);
	viewer->addPointCloud(cloud, "sample cloud1", v1);


	int v2(0);
	viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);	
	viewer->addPointCloud(cloud_filltered, "sample cloud2", v2);
	viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
	viewer->addPointCloudNormals(cloud_filltered, cloud_normals, 10, 0.2, "normals", v2);


	viewer->initCameraParameters();


	while (!viewer->wasStopped())
	{
		plotter.plot();
		viewer->spinOnce(100);
		boost::this_thread::sleep(boost::posix_time::microseconds(100000));
	}


	return 0;
}


关于这部分的原理可以看http://pointclouds.org/documentation/tutorials/fpfh_estimation.php#fpfh-estimation,这个PCL官网解释的还是很清楚的,其实我们只要知道这个特征的目的就好了,它是3D特征描述符的一种,所以它就类似于二维图像中的sift特征一样,可以用来做点云的识别,后期的VFH特征其实也是基于这个的。


PCL_FPFH特征提取及直方图显示_第1张图片

你可能感兴趣的:(PCL,PCL)