Ubuntu 16.04下PCL1.9安装教程及demo测试

本文提供了一步一步的指南,教你如何在Ubuntu16.04上安装PCL库并测试安装结果。文章首先介绍了PCL依赖库的安装,接着详细描述了PCL的下载及环境安装过程,并通过一个直通滤波器demo验证了PCL环境的成功搭建。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

博主之前在学校的时候就一直都是用的ubuntu16.04,所以今天也和大家分享如何在ubuntu16.04下,配置和安装我们的PCL库。之前有一本《点云库PCL 从入门到精通》,上面是基于ROS进行PCL配置的,其实可以跳过ROS直接配置PCL。

另外插一句,如果有条件的朋友,最好是装个双系统,然后在Ubuntu下配置PCL,而不是在Windows下配置PCL。

两个原因:
1.相比Windows,Ubuntu下配置环境更为方便,只需要几行代码即可解决。
2.在实际项目过程中,在对点云数据进行预处理或者算法计算的时候。相同的代码,Windows需要运行几十秒甚至几百秒,而Ubuntu下可能几秒甚至一秒不到实现了。

下面直接进行我们的环境配置

一、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

二、PCL下载

先点击这个pcl的github官方链接link

点击后下滑找到这个地方:
在这里插入图片描述
然后点击6项中最下面的Source.code(tar.gz)进行下载。
在这里插入图片描述选择保存文件,点击确定。等待下载完毕,即完成第一步。

三、PCL环境安装

将下载好的PCL压缩包,移动到你想要安装的位置。然后打开按键ctrl+alt+T打开终端,cd到该位置。或者是在该窗口界面单击右键,选择在终端中打开。
在这里插入图片描述然后我们依次在终端中按照顺序,输入以下的命令。

step1:解压压缩包

tar xvfj pcl-pcl-1.9.1.tar.gz

step2:进入解压后的pcl文件夹

cd pcl-pcl-1.9.1 && mkdir build && cd build

进入pcl文件夹,创建build文件夹,再进入build文件夹

step3:默认设置安装

cmake ..

使用cmake来根据默认设置创建系统。

cmake -DCMAKE_BUILD_TYPE=Release ..
make -j2
make -j2 install

以上需要很长的时间,可以泡杯茶喝了。

四、测试你的pcl环境是否安装完成

这里选用pcl常用的直通滤波器demo,来测试我们的环境是否搭建完成。
大家可以直接到我的github帐号上去下载。

passthrough.cpp

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>

int
 main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);

  // Fill in the cloud data
  cloud->width  = 5;
  cloud->height = 1;
  cloud->points.resize (cloud->width * cloud->height);

  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);
  }

  std::cerr << "Cloud before filtering: " << 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;

  // Create the filtering object
  pcl::PassThrough<pcl::PointXYZ> pass;
  pass.setInputCloud (cloud);
  pass.setFilterFieldName ("z");
  pass.setFilterLimits (0.0, 1.0);
  //pass.setFilterLimitsNegative (true);
  pass.filter (*cloud_filtered);

  std::cerr << "Cloud after filtering: " << std::endl;
  for (size_t i = 0; i < cloud_filtered->points.size (); ++i)
    std::cerr << "    " << cloud_filtered->points[i].x << " " 
                        << cloud_filtered->points[i].y << " " 
                        << cloud_filtered->points[i].z << std::endl;

  return (0);
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(passthrough)

find_package(PCL 1.2 REQUIRED)

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

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

把他们放在同一目录下,然后打开当前目录下的终端:
在这里插入图片描述然后,按照顺序依次在终端中输入以下命令:

step1:cmake生成makefile

cmake . 

在这里插入图片描述

step2:make对passthrough进行编译,生成可执行文件

make

在这里插入图片描述
100%表示编译完成,那个长得像齿轮一样的passthrough文件就是我们的可执行文件了。

step3:运行可执行文件

./passthrough

执行后的结果如下图所示:
在这里插入图片描述如果以上步骤都没有问题,说明我们的环境搭建成功,恭喜你迈入了pcl库的门槛。

参考文献

1.官方linux下pcl安装教程
http://pointclouds.org/documentation/tutorials/compiling_pcl_posix.php
2.官方pcl进阶教程-给大家墙裂推荐!!!
http://pointclouds.org/documentation/tutorials/#filtering-tutorial

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值