一.安装PCL
PCL1.8.0的下载地址: http://pan.baidu.com/s/1c1sqoQO
安装前先确认VS2013的版本,32位还是64位,PCL的版本应与VS的版本保持一致,查看版本的方法:
打开vs后,打开任务管理器:
下载相应版本的PCL之后,解压直接安装,一直下一步就好了我这里修改了一下安装路径:
安装途中会弹出安装openni的框,我们将OpenNI安装在PCL安装目录下3rdParty\OpenNI2里
安装完成之后将下载好的PCL-1.8.0-AllInOne-msvc2013-win32-pdb,pdb文件拷贝到PCL 根目录下的bin文件夹中,下图是拷贝后的样子。
安装完成后重启一下电脑。
二.配置
之前第一次安装时发现网上有两种配置方法:一种是配置环境变量PATH,另外一种就是直接打开一个VS的项目进行配置,不知道这两种有什么区别,我用的是第一种。打开环境变量:右击我的电脑-高级系统设置-环境变量,我们需要自己添加如下几个变量:
%PCL_ROOT%\bin;
%PCL_ROOT%\3rdParty\FLANN\bin;
%PCL_ROOT%\3rdParty\VTK\bin;
%PCL_ROOT%\3rdParty\OpenNI2\Tools (感觉这个可以不加上)
三.创建新项目
打开vs2013,新建C++空项目,直接添加cpp文件 ,复制以下代码:
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
int user_data;
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere(o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;
}
void viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape("text", 0);
viewer.addText(ss.str(), 200, 300, "text", 0);
//FIXME: possible race condition here:
user_data++;
}
int main()
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile("example.pcd的位置", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
//This will only get called once
viewer.runOnVisualizationThreadOnce(viewerOneOff);
//This will get called once per visualization iteration
viewer.runOnVisualizationThread(viewerPsycho);
while (!viewer.wasStopped())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}
然后在属性管理器中右击项目- 添加现有属性表-点击选中开头为Debug的子项里右键,点击添加现有属性表,然后找到你下载的文件夹里的PCLDebug.props,添加上。点击选中开头为Release的子项里右键,点击添加现有属性表,然后找到你下载的文件夹里的PCLRelease.props,添加上,然后运行。
四.出现的问题
问题一:
解决方法:c++-预处理器-编辑-添加-_SCL_SECURE_NO_WARNINGS
问题二:
解决方案:将运行平台Debug改为Relese
问题三:缺少OpenNI2.dll
解决方案:找到OpenNI2的安装路径,我的是:D:\Program Files (x86)\PCL 1.8.0\3rdParty\OpenNI2\Tools,将OpenNI2.dll复制到项目文件夹即可。
五.运行结果
?