https://blog.csdn.net/zkj126521/article/details/80157351
https://blog.csdn.net/e_small/article/details/79581484
pcl下载,网址https://github.com/PointCloudLibrary/pcl
使用git命令或者直接下载zip文件即可。
1.安装依赖
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libvtk5.10-qt4 libvtk5.10 libvtk5-dev
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install qt-sdk openjdk-8-jdk openjdk-8-jre
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2.编译源码
cmake -D CMAKE_BUILD_TYPE=None -D BUILD_GPU=ON -D BUILD_apps=ON -D BUILD_examples=ON .
make -j2
sudo make install
1
2
3
3.(可选 and 建议):如果需要PCLVisualizer。安装OpenNI、OpenNI2
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev
1
2
安装完成。
例程测试:
例1:学习向PCD文件写入点云数据
来源于http://www.cnblogs.com/li-yao7758258/p/6435568.html
#include <iostream> //标准C++库中的输入输出的头文件
#include <pcl/io/pcd_io.h> //PCD读写类相关的头文件
#include <pcl/point_types.h> //PCL中支持的点类型的头文件
int
main (int argc, char** argv)
{
//实例化的模板类PointCloud 每一个点的类型都设置为pcl::PointXYZ
/*************************************************
点PointXYZ类型对应的数据结构
Structure PointXYZ{
float x;
float y;
float z;
};
**************************************************/
pcl::PointCloud<pcl::PointXYZ> cloud;
// 创建点云 并设置适当的参数(width height is_dense)
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false; //不是稠密型的
cloud.points.resize (cloud.width * cloud.height); //点云总数大小
//用随机数的值填充PointCloud点云对象
for (size_t i = 0; i < cloud.points.size (); ++i)
{
cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
}
//把PointCloud对象数据存储在 test_pcd.pcd文件中
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
//打印输出存储的点云数据
std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.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;
return (0);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
cmake_minimum_required ( VERSION 2.6 FATAL_ERROR) #对于cmake版本的最低版本的要求
project(ch2) #建立的工程名,例如源代码目录路径的变量名为CH_DIR
#工程存储目录变量名为CH_BINARY_DIR
#要求工程依赖的PCL最低版本为1.3,并且版本至少包含common和IO两个模块 这里的REQUIRED意味着如果对应的库找不到 则CMake配置的过程将完全失败,
#因为PCL是模块化的,也可以如下操作:
# 一个组件 find_package(PCL 1.6 REQUIRED COMPONENTS io)
# 多个组件 find_package(PCL 1.6 REQUIRED COMPONENTS commom io)
# 所有组件 find_package(PCL 1.6 REQUIRED )
find_package(PCL 1.3 REQUIRED)
#下面的语句是利用CMake的宏完成对PCL的头文件路径和链接路径变量的配置和添加,如果缺少下面几行,生成文件的过程中就会提示
#找不到相关的头文件,在配置CMake时,当找到了安装的PCL,下面相关的包含的头文件,链接库,路径变量就会自动设置
# PCL_FOUND:如果找到了就会被设置为1 ,否则就不设置
# PCL_INCLUDE_DIRS:被设置为PCL安装的头文件和依赖头文件的目录
# PCL_LIBRARIES:被设置成所建立和安装的PCL库头文件
# PCL_LIBRARIES_DIRS:被设置成PCL库和第三方依赖的头文件所在的目录
# PCL_VERSION:所找到的PCL的版本
# PCL_COMPONENTS:列出所有可用的组件
# PCL_DEFINITIONS:列出所需要的预处理器定义和编译器标志
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARIES_DIRS})
add_definitions(${PCL_DEFINITIONS})
#这句话告诉CMake从单个源文件write_pcd建立一个可执行文件
add_executable(write_pcd write_pcd.cpp)
#虽然包含了PCL的头文件,因此编译器知道我们现在访问所用的方法,我们也需要让链接器知道所链接的库,PCL找到库文件由
#PCL_COMMON_LIBRARIES变量指示,通过target_link_libraries这个宏来出发链接操作
target_link_libraries(write_pcd ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
mkdir build
cd build
cmake ..
make
1
2
3
4
结果如图所示:
这里写图片描述
例2:可视化
来源于https://blog.csdn.net/a464057216/article/details/54864591
#include <iostream>
#include <string>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
int main (int argc, char** argv){
typedef pcl::PointXYZRGB PointT;
pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
std::string dir = "";//自行修改路径
std::string filename = "sample.pcd";
if (pcl::io::loadPCDFile<PointT> ((dir+filename), *cloud) == -1){
//* load the file
PCL_ERROR ("Couldn't read PCD file \n");
return (-1);
}
printf("Loaded %d data points from PCD\n",
cloud->width * cloud->height);
pcl::visualization::PCLVisualizer viewer("Cloud viewer");
viewer.setCameraPosition(0,0,-3.0,0,-1,0);
viewer.addCoordinateSystem(0.3);
viewer.addPointCloud(cloud);
while(!viewer.wasStopped())
viewer.spinOnce(100);
return (0);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
运行结果如下:
这里写图片描述
参考博客:https://blog.csdn.net/dantengc/article/details/78446600
https://blog.csdn.net/xs1102/article/details/74736298
---------------------
作者:POFEI_IS_SHIT
来源:CSDN
原文:https://blog.csdn.net/zkj126521/article/details/80157351
版权声明:本文为博主原创文章,转载请附上博文链接!
PCL1.8+Ubuntu16.04安装详解以及运行时遇到的一些错误
方式一:官网prebuild版本
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all
方式二:安装 prebuilt DEB file for PCL 1.8 for Ubunut 16.04
会报错没有相关依赖,解决方式:
sudo apt-get -f update
以上两种便捷方式在之后的使用中我都出现了一些问题,所以还是推荐自己编译。
第一步:安装依赖
-
sudo apt-get update
-
sudo apt-get install git build-essential linux-libc-dev
-
sudo apt-get install cmake cmake-gui
-
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
-
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
-
sudo apt-get install libflann1.8 libflann-dev
-
sudo apt-get install libeigen3-dev
-
sudo apt-get install libboost-all-dev
-
sudo apt-get install libvtk5.10-qt4 libvtk5.10 libvtk5-dev
-
sudo apt-get install libqhull* libgtest-dev
-
sudo apt-get install freeglut3-dev pkg-config
-
sudo apt-get install libxmu-dev libxi-dev
-
sudo apt-get install mono-complete
-
sudo apt-get install qt-sdk openjdk-8-jdk openjdk-8-jre
此时运行的过程中,需要确认“需要确认是否执行‘Y/n’”,个人在时间的过程中,时而直接enter,时而输入Y才可以。
第二步:下载源码
-
cd pcl
-
mkdir release
-
cd release
-
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr \
-
-DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON \
-
-DCMAKE_INSTALL_PREFIX=/usr ..
-
make
sudo make install
安装OpenNI、OpenNI2
-
sudo apt-get install libopenni-dev
-
sudo apt-get install libopenni2-dev
安装ensensor
sudo dpkg -i codemeter_6.40.2402.501_amd64.deb
如缺少依赖:sudo apt-get -f install
Done!以上安装步骤就完成了,但是在运行过程中遇到如下问题:
运行测试程序时出现以下错误
make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so', needed by 'joinMap'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failedmake[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
*** Failure: Exit code 2 ***
解决方法,执行
sudo apt-get install libproj-dev
再次编译出现以下错误
-- Build files have been written to: /home/wd/code/slambook-master/ch5/joinMap/build
[ 50%] Linking CXX executable joinMap
/usr/bin/ld: cannot find -lvtkproj4
collect2: error: ld returned 1 exit status
CMakeFiles/joinMap.dir/build.make:349: recipe for target 'joinMap' failed
make[2]: *** [joinMap] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
*** Failure: Exit code 2 ***
解决方法,需要在cmakelist中加一条指令修复,即在add_executable语句前面加上list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
转自:http://blog.csdn.net/dantengc/article/details/78446600
http://blog.csdn.net/danmeng8068/article/details/77341532