Opencv+PCl配置
1.安装
PCL的完全安装包可以到: http://pointclouds.org/downloads/windows.html 下载。由于我的是VS2010的,所以我选择的是32位的进行下载。
http://blog.csdn.net/wishchin/article/details/10072093
然后将PCL安装到D:\opencv\PCL\PCL 1.6.0;
与此同时,该路径下有其他两个文件为:
D:\opencv\PCL\OpenNI;
D:\opencv\PCL\PrimeSense。
2.环境配置:
(1)添加环境变量PCL_ROOT
内容为:D:\opencv\PCL\PCL 1.6.0
(2)在path环境变量下添加:(应该系统变量中的Path和用户变量中的Path都可以的)
D:\opencv\PCL\OpenNI\Bin;%PCL_ROOT%\bin;%PCL_ROOT%\3rdParty\FLANN\bin;%PCL_ROOT%\3rdParty\Qhull\bin;
3.新建一个空工程,代码如下:(我的工程名是:test4)
#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);
//FIXME: possible race condition here:
user_data++;
}
int main ()
{
pcl::PointCloud
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;
}
4.配置工程
项目->属性->配置属性->vc++目录
包含目录配置:
D:\opencv\PCL\PCL 1.6.0\3rdParty\Boost\include;
D:\opencv\PCL\PCL 1.6.0\3rdParty\Eigen\include;
D:\opencv\PCL\PCL 1.6.0\3rdParty\Flann\include;
D:\opencv\PCL\PCL 1.6.0\3rdParty\VTK\include\vtk-5.8;
D:\opencv\PCL\OpenNI\Include;
D:\opencv\PCL\PCL 1.6.0\include\pcl-1.6;
项目属性->VC++目录->库目录:
D:\opencv\PCL\PCL 1.6.0\3rdParty\Boost\lib;
D:\opencv\PCL\PCL 1.6.0\3rdParty\Qhull\lib;
D:\opencv\PCL\PCL 1.6.0\3rdParty\FLANN\lib;
D:\opencv\PCL\PCL 1.6.0\3rdParty\VTK\lib\vtk-5.8;
D:\opencv\PCL\PCL 1.6.0\lib;
D:\opencv\PCL\OpenNI\Lib64;
dubug模式,链接器->输入->附加依赖项 添加:
opengl32.lib
pcl_kdtree_debug.lib
pcl_io_debug.lib
pcl_search_debug.lib
pcl_segmentation_debug.lib
pcl_apps_debug.lib
pcl_features_debug.lib
pcl_filters_debug.lib
pcl_visualization_debug.lib
pcl_common_debug.lib
flann_cpp_s-gd.lib
libboost_system-vc100-mt-gd-1_47.lib
libboost_filesystem-vc100-mt-gd-1_47.lib
libboost_thread-vc100-mt-gd-1_47.lib
libboost_date_time-vc100-mt-gd-1_47.lib
libboost_iostreams-vc100-mt-gd-1_47.lib
vtkalglib-gd.lib
vtkCharts-gd.lib
vtkCommon-gd.lib
vtkDICOMParser-gd.lib
vtkexoIIc-gd.lib
vtkexpat-gd.lib
vtkFiltering-gd.lib
vtkfreetype-gd.lib
vtkftgl-gd.lib
vtkGenericFiltering-gd.lib
vtkGeovis-gd.lib
vtkGraphics-gd.lib
vtkhdf5-gd.lib
vtkHybrid-gd.lib
vtkImaging-gd.lib
vtkInfovis-gd.lib
vtkIO-gd.lib
vtkjpeg-gd.lib
vtklibxml2-gd.lib
vtkmetaio-gd.lib
vtkNetCDF-gd.lib
vtkNetCDF_cxx-gd.lib
vtkpng-gd.lib
vtkproj4-gd.lib
vtkRendering-gd.lib
vtksqlite-gd.lib
vtksys-gd.lib
vtktiff-gd.lib
vtkverdict-gd.lib
vtkViews-gd.lib
vtkVolumeRendering-gd.lib
vtkWidgets-gd.lib
vtkzlib-gd.lib
此时环境已经搭建完毕,编译程序可以通过了,添加一个运行时需要的文件my_point_cloud.pcd就可以了。
文件可以到我的百度云账户去下载。
效果图如下:
注意事项:
由于我的配置是每次新建一个工程文件的时候都需要进行一次上述配置4的配置。就比较麻烦,因此如果不想要每次新建一个工程还要重新进行一次配置的话,我们可以将第一次配置好的.user文件保存下来,当我们新建一个工程时,我们只需要将属性管理器打开。(一般都是在debug条件下进行调试运行的)将debug下面的“.user”文件替换为之前已经配置好的.user文件即可。
具体操作:视图->属性管理器->鼠标右键点击.user文件->添加现有属性表->选择你已经配置好了的.user文件即可。
错误提示:pcl::PCDReader::readheader Could not find file ‘my_point_cloud_pcd’
解决方案是:需要从网上下载一个my_point_cloud_pcd文件。
(如果还有不清楚的,请参照:http://www.cnblogs.com/newpanderking/articles/4022322.html)