PCL点云程序学习

这是本人写的第一篇博客,对PLC程序进行了初步了解,如有不正确的地方还请提出,下面则是我对PCL的初步理解和学习

1.下面编辑一段简单的代码cloud_viewer_PointXYZ.cpp,将其在新建的工程中粘贴过去,保存

#include
#include
#include
#include
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);//test窗口的位置
//FIXME: possible race condition here:
user_data++;
}
int main ()
{
pcl::PointCloud::Ptr cloud (new pcl::PointCloud); //modified

//blocks until the cloud is actually rendered
if(pcl::io::loadPCDFile("my_point_cloud.pcd",*cloud)==-1)//*打开含有点云图案的pcd文件
{
PCL_ERROR("Couldn't read file my_point_cloud.pcd\n");
return(-1);
}
pcl::visualization::CloudViewer viewer("Cloud Viewer");
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++;
}
system("pause");
return 0;
}

2.建立CmakeLists.txt文档源代码可在http://pointclouds.org/documentation/tutorials/project_inliers.php上获得,

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer_PointXYZ)

find_package(PCL 1.6 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (cloud_viewer_PointXYZ cloud_viewer_PointXYZ.cpp)
target_link_libraries (cloud_viewer_PointXYZ ${PCL_LIBRARIES})

再谈谈我对这段代码的理解,由于是初学,所以有不对的地方请指教;当然相关的pcl学习教程也会有相应的介绍,如我的百度网盘链接 http://pan.baidu.com/s/1sj3Jyrz

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)这是对cmake的最低版本要求,由于编程简单,不需要2.8或者更高的版本;

project(cloud_viewer_PointXYZ)这是cpp文件的工程名;

find_package(PCL 1.6 REQUIRED)这是对PCL的版本要求;


include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})这几句是利用Cmake的宏完成对pcl的头文件路径和链接路径变量的配置和添加,若没有这几句,.cpp文件的头文件则会出现报错

add_executable (cloud_viewer_PointXYZ cloud_viewer_PointXYZ.cpp)这句是告诉我们,将把&&.cpp文件装换成另一个名为cloud_viewer_PointXYZ的可执行文件,当然,可以任意取名;

target_link_libraries (cloud_viewer_PointXYZ ${PCL_LIBRARIES})这句是将新生成的可执行文件链接到PCL库;

3.建立文件夹

首先,最好在没有中文字幕的文件夹下建立一个source文件夹,将上面的.cpp文件和CmakeLists.txt文件放入该文件夹下;

再与source文件夹的相同目录下建立cmake-bin文件夹。如下图所示:

PCL点云程序学习_第1张图片

4.打开cmake软件

将上文新建的两个文件夹填入其中:


再按Configure键,出现以下效果,再按Generate键,则大功告成:

PCL点云程序学习_第2张图片

5.打开VS2010,在原有的cmake-bin文件夹下找到新生成的可执行文件,将其打开,运行即可;

6.问题:

(1)在运行过程中可能会出现下面窗口的错误

PCL点云程序学习_第3张图片

原因及修改方法:因为没有将cloud_viewer_PointXYZ工程设为启动项目,只需将其设为启动项目即可,再按Ctrl+F5,或者直接运行即可;

(2)出现1>LINK : fatal error LNK1104: 无法打开文件“C:\Qt\4.8.0\lib\QtGuid4.lib”的错误,这是因为我们C盘内没有相关的文件,所以需要下载相关的Qt文件,

http://qiusuoge.com/11848.html,该链接下有相关的配置方法,最后在(项目》属性》配置属性》链接器》输入》附加依赖项)内将C:\Qt\4.8.0\lib\QtGuid4.lib改为自己的文件目录,例如我的是D:\Qt\4.8.5\lib\QtGuid4.lib。

(3)当然, 在最后可能显示my_point_cloud.pcb不能找到,这个问题还未解决,

总结,本文最后一个问题为解决外,其他步骤应该是正确的。

***************************************************

这是最后的解决方案,原因是没有pcd文件,需要自己查找,如链接(http://pan.baidu.com/s/1eQi1j4A)所示,将其放在工程中,再运行程序即可,结果如下:

PCL点云程序学习_第4张图片







你可能感兴趣的:(pcl)