PCL学习:点云特征-VFH示例

代码说明:

对输入数据集中的所有点估计一组VFH特征值;

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(vfh_feature)
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(vfh_feature vfh_feature.cpp)
target_link_libraries(vfh_feature ${PCL_LIBRARIES})

vfh_feature.cpp

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

using namespace std;
using namespace pcl::visualization;
using namespace pcl::console;

int
main (int argc, char * argv [])
{
	if(argc<2)
	{
		std::cout<<".exe source.pcd -r 0.005 -ds 5"<::Ptr cloud_src (new pcl::PointCloud); 
	pcl::io::loadPCDFile (argv[1], *cloud_src);	
	std::vector indices1; 
	pcl::removeNaNFromPointCloud (*cloud_src, *cloud_src, indices1); 
	pcl::PointCloud::Ptr ds_src (new pcl::PointCloud); 
	pcl::VoxelGrid grid; 
	grid.setLeafSize (voxel_re, voxel_re, voxel_re); 
	grid.setInputCloud (cloud_src); 
	grid.filter (*ds_src); 

	//计算法向量
	pcl::PointCloud::Ptr norm_src (new pcl::PointCloud); 
	pcl::search::KdTree::Ptr tree_src(new pcl::search::KdTree()); 
	pcl::NormalEstimation ne; 
	PCL_INFO ("Normal Estimation - Source\n");	
	ne.setInputCloud (ds_src); 
	ne.setSearchSurface (cloud_src); 
	ne.setSearchMethod (tree_src); 
	ne.setRadiusSearch (ds_N*2*voxel_re); 
	ne.compute (*norm_src); 

	// 提取关键点
	pcl::PointCloud::Ptr keypoints_src (new pcl::PointCloud); 
	pcl::PointCloud::Ptr keypoints_tgt (new pcl::PointCloud); 
	grid.setLeafSize (ds_N*voxel_re,ds_N*voxel_re,ds_N*voxel_re); 
	grid.setInputCloud (ds_src); 
	grid.filter (*keypoints_src); 

	//Feature-Descriptor 
	PCL_INFO ("VFH - Feature Descriptor\n"); 
	//VFH	
	//VFH Source 
	pcl::VFHEstimation vfh_est_src; 
	pcl::search::KdTree::Ptr tree_vfh_src (new pcl::search::KdTree); 

	vfh_est_src.setSearchSurface (ds_src);//输入完整点云数据
	vfh_est_src.setInputCloud (keypoints_src); // 输入关键点
	vfh_est_src.setInputNormals (norm_src); 
	vfh_est_src.setRadiusSearch (2*ds_N*voxel_re);
	vfh_est_src.setSearchMethod(tree_vfh_src);
	pcl::PointCloud::Ptr vfh_src (new pcl::PointCloud);
	vfh_est_src.compute (*vfh_src); 

	//定义绘图器
	PCLPlotter *plotter = new PCLPlotter ("My Plotter"); 
	//设置特性
	plotter->setShowLegend (true);
	std::cout<(*vfh_src);
	
	//显示
	plotter->addFeatureHistogram(*vfh_src, "vfh", 0, "vfh");
	plotter->setWindowSize(800, 600);
	plotter->spinOnce(30000);	

	plotter->clearPlots();
    return 1;
}

cmd执行命令: 

 .\vfh_feature.exe ..\..\source\mesh.pcd

显示:

vfhs->points.size ()的大小是1,即vfh描述子是针对全局的特征描述 。

PCL学习:点云特征-VFH示例_第1张图片

你可能感兴趣的:(PCL,点云库PCL从入门到精通)