链接:https://pan.baidu.com/s/1kLJNW5OfwHv-1ZNi7FcMxg
提取码:pdx6
1) 右键选择PCL-1.8.1-AllInOne-msvc2017-win64.exe,以管理员身份运行
2)选择第二项“Add PCL to the system PATN for all users”
3)更改安装目录,建议使用英文目录
4)安装过程中会进行OpenNI 2.2 SDK的安装,选择路径安装即可(有人建议安装在PCL 1.8.1\3rdParty\OpenNI2目录下)
将pdb文件解压,把文件夹中的内容(20个项目)复制到PCL目录的bin文件夹下(D:\Program Files\PCL 1.8.1\bin)
右键“此电脑->属性->高级系统设置->高级->环境变量”
将以下内容依次新建到系统变量Path中(Win10)
D:\Program Files\PCL 1.8.1\bin
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\bin
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\bin
D:\Program Files\PCL 1.8.1\3rdParty\VTK\bin
D:\Program Files\OpenNI2\Tools
需要注销或者重启
1) 打开vs2017点击左上角“文件->新建->新建项目->空项目”
2)选择“属性管理器->Debug | x64”,右键“添加新项目属性表”(一劳永逸,以后创建新项目时直接调用即可,不必重新配置)
3)双击新建好的属性表,进入下一步。
将以下路径添加到“通用属性->VC++ 目录->包含目录”中
D:\Program Files\PCL 1.8.1\include\pcl-1.8
D:\Program Files\PCL 1.8.1\3rdParty\Boost\include\boost-1_64
D:\Program Files\PCL 1.8.1\3rdParty\Eigen\eigen3
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\include
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\include
D:\Program Files\PCL 1.8.1\3rdParty\VTK\include\vtk-8.0
D:\Program Files\OpenNI2\Include
将以下ib路径添加到“通用属性->VC++ 目录->库目录”中
D:\Program Files\PCL 1.8.1\lib
D:\Program Files\PCL 1.8.1\3rdParty\FLANN\lib
D:\Program Files\PCL 1.8.1\3rdParty\Boost\lib
D:\Program Files\PCL 1.8.1\3rdParty\Qhull\lib
D:\Program Files\PCL 1.8.1\3rdParty\VTK\lib
D:\Program Files\OpenNI2\Lib
打开”链接器->输入->附加依赖项“,添加vtk_lib文件
debug版本的vtk文件已经在百度网盘中给出
以kd-tree作为测试代码,包括了点云生成,kd-tree的创建及搜索,保存生成的点云及可视化
选择“源文件”,右键“添加->新建项”,建立C++文件.cpp
#include
#include
#include
#include
#include
int main(int argc, char**argv)
{
srand(time(NULL)); //用系统时间初始化随机种子
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//点云生成
cloud->width = 1000; //点云数量
cloud->height = 1; //表示点云为无序点云
cloud->points.resize(cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size(); ++i)
{
cloud->points[i].x = 1024.0f* rand() / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024.0f* rand() / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024.0f* rand() / (RAND_MAX + 1.0f);
}
pcl::KdTreeFLANN<pcl::PointXYZ>kdtree; //创建K-D Tree 对象
kdtree.setInputCloud(cloud); //设置搜索空间
pcl::PointXYZ searchPoint; //定义查询点,并赋随机值
searchPoint.x = 1024.0f* rand() / (RAND_MAX + 1.0f);
searchPoint.y = 1024.0f* rand() / (RAND_MAX + 1.0f);
searchPoint.z = 1024.0f* rand() / (RAND_MAX + 1.0f);
// k近邻搜索
int K = 10;
std::vector<int>pointIdxNKNSearch(K); //存储查询点近邻索引
std::vector<float>pointNKNSquaredDistance(K); //存储近邻点对应平方距离
std::cout << "K nearest neighbor search at ("
<< searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with K=" << K << std::endl;
if (kdtree.nearestKSearch(searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > 0) //执行K近邻搜索
{
for (size_t i = 0; i < pointIdxNKNSearch.size(); ++i)
std::cout << " " << cloud->points[pointIdxNKNSearch[i]].x
<< " " << cloud->points[pointIdxNKNSearch[i]].y
<< " " << cloud->points[pointIdxNKNSearch[i]].z
<< " (squared distance: " << pointNKNSquaredDistance[i] << ")" << std::endl;
}
// 在半径r内搜索近邻
std::vector<int> pointIdxRadiusSearch;
std::vector<float> pointRadiusSquaredDistance;
float radius = 156;
std::cout << "Neighbors within radius search at (" << searchPoint.x
<< " " << searchPoint.y
<< " " << searchPoint.z
<< ") with radius=" << radius << std::endl;
if (kdtree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0)
{
for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i)
std::cout << " " << cloud->points[pointIdxRadiusSearch[i]].x
<< " " << cloud->points[pointIdxRadiusSearch[i]].y
<< " " << cloud->points[pointIdxRadiusSearch[i]].z
<< " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << std::endl;
}
pcl::io::savePCDFileASCII("1.pcd", *cloud); //保存点云
std::cerr << "Saved " << cloud->points.size() << " data points to 1.pcd." << std::endl; //输出保存点的个数
//输出保存点的坐标
for (size_t i = 0; i < cloud->points.size(); ++i)
std::cerr << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << std::endl;
//可视化生成点云
pcl::visualization::CloudViewer viewer("Cloud Viewer");
viewer.showCloud(cloud);
while (!viewer.wasStopped())
{
}
return 0;
}
可视化点云,为一立方体
由于点云坐标偏离坐标原点,默认显示如下
此时,通过滑动滚轮缩小点云,并长按滚轮拖动即可得到如下显示
配置完成后可能会出现以下异常
异常1:
pcl 1.8.1\3rdparty\flann\include\flann\util\serialization.h(484): error C4996: ‘fopen’: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
解决办法:
C/C++ 预处理器 预处理定义,添加 _CRT_SECURE_NO_WARNINGS
解决办法:
修改打开的dish.h文件,将503行的“typedef unsigned long pop_t”移到“#if GNUC”前面一行(往上翻几行就能看到)
异常3:
C4996 ‘std::fpos<_Mbstatet>::seekpos’: warning STL4019
错误 C4996 ‘std::fpos<_Mbstatet>::seekpos’: warning STL4019: The member std::fpos::seekpos() is non-Standard, and is preserved only for compatibility with workarounds for old versions of Visual C++. It will be removed in a future release, and in this release always returns 0. Please use standards-conforming mechanisms to manipulate fpos, such as conversions to and from streamoff, or an integral type, instead. If you are receiving this message while compiling Boost.IOStreams, a fix has been submitted upstream to make Boost use standards-conforming echanisms, as it does for other compilers. You can define _SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING to acknowledge that you have received this warning, or define _REMOVE_FPOS_SEEKPOS to remove std::fpos::seekpos entirely.
解决办法:
VS其实在加粗部分已经给出了解决该错误的办法,具体操作为
C/C++ 预处理器 预处理定义,添加 _SILENCE_FPOS_SEEKPOS_DEPRECATION_WARNING
应用并确定,重新调试运行(我到这就已经调试成功了)
若还有问题,再添加_REMOVE_FPOS_SEEKPOS
若还有问题,尝试 C/C++ 常规 SDL检查设置为“否”
目前未遇到其他异常,如出现其他异常请检查以上步骤是否执行正确,或者参考其他博主的文章