#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
[])
{
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
);
PCL_INFO("VFH - Feature Descriptor\n");
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;
}
转载请注明原文地址: https://mac.8miu.com/read-497502.html