Code Description:
A display mesh.pcd FPFH histogram corresponding to the midpoint;
Code:
CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(fpfh_feature)
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(fpfh_feature fpfh_feature.cpp)
target_link_libraries(fpfh_feature ${PCL_LIBRARIES})
fpfh_feature.cpp
#include<pcl/visualization/pcl_plotter.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/filter.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/console/parse.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/filters/normal_space.h>
#include <pcl/common/eigen.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/fpfh.h>
#include <pcl/visualization/histogram_visualizer.h>
#include<iostream>
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"<<endl;
return 0;
}
float voxel_re=0.005,ds_N=5;
parse_argument (argc, argv, "-r", voxel_re);// 设置点云分辨率
parse_argument (argc, argv, "-ds", ds_N);// 设置半径
//调节下采样的分辨率以保持数据处理的速度。
// 下采样
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_src (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile (argv[1], *cloud_src);
std::vector<int> indices1;
pcl::removeNaNFromPointCloud (*cloud_src, *cloud_src, indices1);
pcl::PointCloud<pcl::PointXYZ>::Ptr ds_src (new pcl::PointCloud<pcl::PointXYZ>);
pcl::VoxelGrid<pcl::PointXYZ> grid;
grid.setLeafSize (voxel_re, voxel_re, voxel_re);
grid.setInputCloud (cloud_src);
grid.filter (*ds_src);
//计算法向量
pcl::PointCloud<pcl::Normal>::Ptr norm_src (new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_src(new pcl::search::KdTree<pcl::PointXYZ>());
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> 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<pcl::PointXYZ>::Ptr keypoints_src (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr keypoints_tgt (new pcl::PointCloud<pcl::PointXYZ>);
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 ("FPFH - Feature Descriptor\n");
//FPFH
//FPFH Source
pcl::FPFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh_est_src;
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_fpfh_src (new pcl::search::KdTree<pcl::PointXYZ>);
fpfh_est_src.setSearchSurface (ds_src);//输入完整点云数据
fpfh_est_src.setInputCloud (keypoints_src); // 输入关键点
fpfh_est_src.setInputNormals (norm_src);
fpfh_est_src.setRadiusSearch (2*ds_N*voxel_re);
fpfh_est_src.setSearchMethod(tree_fpfh_src);
pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfh_src (new pcl::PointCloud<pcl::FPFHSignature33>);
fpfh_est_src.compute (*fpfh_src);
//定义绘图器
PCLPlotter *plotter = new PCLPlotter ("My Plotter");
//设置特性
plotter->setShowLegend (true);
std::cout<<pcl::getFieldsList<pcl::FPFHSignature33>(*fpfh_src);
//显示
for (int m=0; m<6;m++)
{
plotter->addFeatureHistogram<pcl::FPFHSignature33>(*fpfh_src, "fpfh", m, std::to_string(m)/*"one_fpfh"*/);
plotter->setWindowSize(800, 600);
plotter->spinOnce(1000);
}
plotter->clearPlots();
return 1;
}
cmake to compile:
vs open the project to generate exe:
cmd command:
.\fpfh_feature.exe ..\..\source\mesh.pcd
show result: