本文介绍在windows环境下配置PCL1.80的开发环境。
电脑配置如下:
1.windows 10 64位操作系统
2.下载对应Visual Studio 2015 64 位PCL1.8和对应的PDB文件
1.点击安装对应的PCL文件,安装过程中勾选配置系统环境变量
把PDB文件解压缩,把里面所有的.pdb文件拷贝到PCL安装bin目录下
2.安装完成后,得到环境变量下的如下:
以上几个是自己安装过程中自动添加的,下面需要自己手动添加几个环境变量
3.接着打开visual studio 2015,新建项目文件,然后配置对应的属性文件,点击DEBUG 64,添加新属性表文件。
把对应的包和库目录文件一并添加进来
4.接着添加连接器-输入,把对应的lib文件添加
其中的PCL安装目录下的lib文件夹,以及下面几个文件夹下的lib文件夹下的文件都添加
我的属性表文件下载如下:
http://download.csdn.net/detail/oliverkingli/9828188
4.
接着使用以下代码进行测试:
#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("my_point_cloud.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;
}
我的是使用opencv配置环境下学习高翔博士的slam
// RGB_D_slam_test1.2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
// c++标准库
#include <iostream>
#include <string>
using namespace std;
// Opencv 库
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
// PCL 库
#include <pcl\io\pcd_io.h>
#include <pcl\point_types.h>
// 定义点云类型
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud<PointT> PointCloud;
// 相机参数
const double camera_factor = 1000;
const double camera_cx = 325.5;
const double camera_cy = 253.5;
const double camera_fx = 518.0;
const double camera_fy = 519.0;
int _tmain(int argc, _TCHAR* argv[])
{
// 图像矩阵
cv::Mat rgb, depth;
// rgb 是8UC3的彩色图像
rgb = cv::imread("data\\rgb.png");
// depth 是16UC1的单通道图像,flags设置-1,表示读取原始数据不做任何的修改
depth = cv::imread("data\\depth.png", -1);
// 点云变量;使用智能指针,创建一个空点云
PointCloud::Ptr cloud(new PointCloud);
// 遍历深度图
for (int m = 0; m < depth.rows; ++m)
{
for (int n = 0; n < depth.cols; ++n)
{
// 获取深度图中(m,n)处的值
ushort d = depth.ptr<ushort>(m)[n];
if (d == 0)
continue;
PointT p;
// 计算这个点的空间坐标
p.z = double(d) / camera_factor;
p.x = (n - camera_cx) * p.z / camera_fx;
p.y = (m - camera_cy) * p.z / camera_fy;
// 从rgb图像中获取它的颜色
// rgb是三通道的RGB格式图,所以俺下面的顺序获取颜色
p.b = rgb.ptr<uchar>(m)[n * 3];
p.g = rgb.ptr<uchar>(m)[n * 3 + 1];
p.r = rgb.ptr<uchar>(m)[n * 3 + 2];
// 把p加入到点云中
cloud->points.push_back(p);
}
}
// 设置并保存点云
cloud->height = 1;
cloud->width = cloud->points.size();
cout << "point cloud size = " << cloud->points.size() << endl;
cloud->is_dense = false;
pcl::io::savePCDFile("data\\pointcloud.pcd", *cloud);
// 清楚数据并退出
cloud->points.clear();
cout << "point cloud saved." << endl;
return 0;
}
得到的点云图如下: