Ubuntu16.04下安装并测试pcl

Ubuntu16.04下安装并测试pcl

一 、必须先安装VTK,首先准备编译环境,再下载VTK源码编译安装
(1)安装Qt5
从Qt官网下载开源版本,官网地址:https://www.qt.io/download-open-source/#section-2
在官网里点击go open source,填写邮箱等信息,就可以获得下载地址了,目前我下载的版本名称是qt-unified-linux-x64-3.1.0-online.run。下载完成后,应该是不能直接双击运行的,要在终端键入如下命令来运行:

sudo chmod u+x qt-unified-linux-x64-3.1.0-online.run
sudo ./qt-unified-linux-x64-3.1.0-online.run

根据提示进行,并设置安装路径就好(我用的是默认的路径)

(2)安装X11

sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev

(3)安装OpenGL

sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev

(4)安装libglut-dev

sudo apt-get install freeglut3-dev

(5)在VTK官网下载,https://www.vtk.org/download/ ,我下载的是VTK-8.2.0.tar.gz,
下载完成后,提取到Home目录下。然后终端一步一步进行如下操作:

cd VTK-8.2.0
mkdir release
cd release
cmake ..
sudo make
sudo make install

编译时间较长,完成后,继续下面等pcl编译安装。

二、首先,要先安装一大堆依赖库,这个过程耗时挺久的,终端操作如下一步一步进行:

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

接着从github上把PCL源码clone下来

git clone https://github.com/PointCloudLibrary/pcl.git

pcl源码下载后应该出现在home下,有一个pcl文件,然后:

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

至此,pcl安装结束。

三、测试pcl是否安装成功
在home下进入pcl文件夹,新建文件夹pcl_test,进入pcl_test文件夹,新建文档并命名为pcl_test.cpp,继续新建文档并命名为CMakeLists.txt,其中,pcl_test.cpp文档内的代码如下:

#include 
#include 
#include 
#include 
#include 
#include 
 
 
int main(int argc, char **argv) {
    std::cout << "Test PCL !!!" << std::endl;
    
    pcl::PointCloud::Ptr point_cloud_ptr (new pcl::PointCloud);
    uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
      for (float angle(0.0); angle <= 360.0; angle += 5.0)
      {
	pcl::PointXYZRGB point;
	point.x = 0.5 * cosf (pcl::deg2rad(angle));
	point.y = sinf (pcl::deg2rad(angle));
	point.z = z;
	uint32_t rgb = (static_cast(r) << 16 |
		static_cast(g) << 8 | static_cast(b));
	point.rgb = *reinterpret_cast(&rgb);
	point_cloud_ptr->points.push_back (point);
      }
      if (z < 0.0)
      {
	r -= 12;
	g += 12;
      }
      else
      {
	g -= 12;
	b += 12;
      }
    }
    point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
    point_cloud_ptr->height = 1;
    
    pcl::visualization::CloudViewer viewer ("test");
    viewer.showCloud(point_cloud_ptr);
    while (!viewer.wasStopped()){ };
    return 0;
}

CMakeLists.txt文档内的代码如下:

cmake_minimum_required(VERSION 2.6)
project(pcl_test)

find_package(PCL 1.2 REQUIRED)

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

add_executable(pcl_test pcl_test.cpp)

target_link_libraries (pcl_test ${PCL_LIBRARIES})

install(TARGETS pcl_test RUNTIME DESTINATION bin)

然后打开终端,进行如下操作:

cd pcl/pcl_test
mkdir build
cd build
cmake ..
make

make成功后,终端继续键入:

./pcl_test

就可以看到点云模型了(如下图),至此,安装全部结束。
Ubuntu16.04下安装并测试pcl_第1张图片

你可能感兴趣的:(教程,环境配置)