PCL:点云特征-VFH示例

mac2024-11-08  8

#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/vfh.h> #include <pcl/visualization/histogram_visualizer.h> #include<iostream> #pragma comment(lib,"User32.lib") #pragma comment(lib, "gdi32.lib") 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("table_scene_lms400_downsampled.pcd", *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("VFH - Feature Descriptor\n"); //VFH //VFH Source pcl::VFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::VFHSignature308> vfh_est_src; pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_vfh_src(new pcl::search::KdTree<pcl::PointXYZ>); 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<pcl::VFHSignature308>::Ptr vfh_src(new pcl::PointCloud<pcl::VFHSignature308>); vfh_est_src.compute(*vfh_src); //定义绘图器 PCLPlotter *plotter = new PCLPlotter("My Plotter"); //设置特性 plotter->setShowLegend(true); std::cout << pcl::getFieldsList<pcl::VFHSignature308>(*vfh_src); //显示 plotter->addFeatureHistogram<pcl::VFHSignature308>(*vfh_src, "vfh", 0, "vfh"); plotter->setWindowSize(800, 600); plotter->spinOnce(30000); plotter->clearPlots(); system("pause"); return 0; }

最新回复(0)