文章目录
一、环境搭建
(1)安装 Vs2017
(2)安装PCL-1.8.1-AllInOne-msvc2017-win64.exe
这步需要注意的是PCL下的OpenNI2是空的,可以把步骤里的OpenNI2.2里的内容复制进去
环境变量:
二、 error C2039: “seekpos”: 不是“std::fpos<_Mbstatet>”的成员这样的错误
只要将在positioning.hpp 中报错的这句return pos.seekpos();注释掉即可。
三、解决’fopen’:this function or variable may be unsafe先关问题的方法
四、LNK110 无法打开文件“vtknetcdf_c++_gd.lib”
查看项目属性–链接器–输入里的附加依赖项是否存在这个依赖包,如果有删了即可。
五、找不到OpenNI2.dll
找到安装目录里的 OpenNI2.dll
,将其复制到C:\Windows\System32
六、C3861 “pop_t”:找不到标识符
七、代码
#include<pcl/point_types.h>
#include<pcl/features/pfh.h>
#include<pcl/io/io.h>
#include<pcl/io/pcd_io.h>
#include<pcl/features/integral_image_normal.h>
#include<pcl/features/normal_3d.h>
#include<pcl/visualization/pcl_visualizer.h>
#include<pcl/visualization/histogram_visualizer.h>
#include<pcl/visualization/pcl_plotter.h>
#include<pcl/search/kdtree.h>
#include<pcl/filters/passthrough.h>
#include<pcl/filters/voxel_grid.h>
#include<pcl/features/fpfh.h>
#include<pcl/features/vfh.h>
using namespace std;
int main() {
// 加载点云
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
//pcl::io::loadPCDFile("E:\\Firefox\\rabbit.pcd", *cloud);
//pcl::io::loadPCDFile("D:\\test\\rabbit.pcd", *cloud);
pcl::io::loadPCDFile("D:\\test\\table_scene_mug_stereo_textured.pcd", *cloud);
// 打印点云信息
cout << "cloud:: width: " << cloud->width << " height: " << cloud->height << " size: " << cloud->points.size() << endl;
// ------过滤数据-------//
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_fillter(new pcl::PointCloud<pcl::PointXYZ>);
// 过滤passthrough
pcl::PassThrough<pcl::PointXYZ> filter;
filter.setInputCloud(cloud);
filter.setFilterFieldName("z");
filter.setFilterLimits(0.0f, 1.0f);
filter.filter(*cloud_fillter);
// 再进行三角栅格过滤
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter2(new pcl::PointCloud<pcl::PointXYZ>);
pcl::VoxelGrid<pcl::PointXYZ> voxel;
voxel.setInputCloud(cloud_fillter);
voxel.setLeafSize(0.01, 0.01, 0.01);
voxel.filter(*cloud_filter2);
// 估计法线
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud(cloud_filter2);
// 定义查询树
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>());
ne.setSearchMethod(kdtree);
ne.setRadiusSearch(0.03);
//存储输出数据
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
//使用半径在查询点周围3厘米范围内的所有临近元素
ne.setRadiusSearch(0.03);
//计算特征值
ne.compute(*normals);
cout << "normal:: width:" << normals->width << " height: " << normals->height << " size: " << normals->points.size() << endl;
//pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimation;
//normal_estimation.setNormalEstimationMethod(normal_estimation.AVERAGE_3D_GRADIENT);
//normal_estimation.setMaxDepthChangeFactor(0.02F);
//normal_estimation.setNormalSmoothingSize(10.0f);
//normal_estimation.setInputCloud(cloud);
//normal_estimation.compute(*normals); // 计算法线
// 设置搜索方法
//pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree(new pcl::KdTreeFLANN<pcl::PointXYZ>);
// -----------PFH特征实例化--------- //
pcl::PFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::PFHSignature125> pfhe;
pfhe.setInputCloud(cloud_filter2); // 传入点云
pfhe.setInputNormals(normals); // 传入法线
pcl::search::KdTree<pcl::PointXYZ>::Ptr search_method(new pcl::search::KdTree<pcl::PointXYZ>());
pfhe.setSearchMethod(search_method); // 设置近邻搜索方法
//使用半径在5厘米范围内的所有邻元素。
//注意:此处使用的半径必须要大于估计表面法线时使用的半径!!!
pfhe.setRadiusSearch(0.05); // 设置查询半径
// 设置输出集
pcl::PointCloud<pcl::PFHSignature125>::Ptr pfhs(new pcl::PointCloud<pcl::PFHSignature125>);
// 计算pfh的特征集
pfhe.compute(*pfhs);
cout << "PFH:: width: " << pfhs->width << " height: " << pfhs->height << " size: " << pfhs->points.size() << endl;
//pfh可视化
/*pcl::visualization::PCLHistogramVisualizer view;
view.setBackgroundColor(0, 0, 0);
view.addFeatureHistogram(*output, "output", 10);
view.spinOnce();*/
// ---------------FPFH实例化------------------//
pcl::FPFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::FPFHSignature33> fpfh;
fpfh.setInputCloud(cloud_filter2);
fpfh.setInputNormals(normals);
fpfh.setSearchMethod(search_method);
fpfh.setRadiusSearch(0.05);
// 设置输出集
pcl::PointCloud<pcl::FPFHSignature33>::Ptr fpfhs(new pcl::PointCloud<pcl::FPFHSignature33>);
fpfh.compute(*fpfhs);
cout << "FPFH:: width:" << fpfhs->width << " height: " << fpfhs->height << " size: " << fpfhs->points.size() << endl;
// -----------------VFH实例化-------------------//
pcl::VFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::VFHSignature308> vfh;
vfh.setInputCloud(cloud_filter2);
vfh.setInputNormals(normals);
vfh.setSearchMethod(search_method);
vfh.setRadiusSearch(0.05);
// 设置VFH输出集
pcl::PointCloud<pcl::VFHSignature308>::Ptr vfhs(new pcl::PointCloud<pcl::VFHSignature308>);
vfh.compute(*vfhs);
cout << "VFH:: width: " << vfhs->width << " height: " << vfhs->height << " size: " << vfhs->points.size() << endl;
// -------------- 点云数据可视化------------- //
pcl::visualization::PCLVisualizer viewer("可视化");
viewer.setBackgroundColor(0, 0, 1);
viewer.addPointCloud<pcl::PointXYZ>(cloud, "cloud");
// viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 4, "cloud");
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>(cloud, 0, 1, 0);
viewer.spinOnce();
pcl::visualization::PCLPlotter plotter("pfh特征");
plotter.setWindowName("pfh特征");
plotter.addFeatureHistogram(*pfhs, 300); //设置的很坐标长度,该值越大,则显示的越细致
plotter.plot();
pcl::visualization::PCLPlotter fpfh_plotter("fpfh特征");
fpfh_plotter.setWindowName("fpfh特征");
fpfh_plotter.addFeatureHistogram(*fpfhs, 300); //设置的很坐标长度,该值越大,则显示的越细致
fpfh_plotter.plot();
pcl::visualization::PCLPlotter vfh_plotter("vfh特征");
vfh_plotter.setWindowName("vfh特征");
vfh_plotter.addFeatureHistogram(*vfhs, 300); //设置的很坐标长度,该值越大,则显示的越细致
vfh_plotter.plot();
return 0;
}