Ubuntu18.04 安装PCL
文章目录
方法一:官网方法安装
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all
在执行第一行命令时,电脑里出现了错误:
网上说继续按ENTER,然后输入下面的命令可以安装成功。
sudo apt install libpcl-dev
//或者使用下面的命令
sudo apt-get install libpcl-dev
方法二:先安装依赖,然后再装pcl
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.9 libflann-dev #Ubuntu18.04要用1.9版本的,否则报错
sudo apt-get install libeigen3-dev #这个需要自己下载正确版本安装
sudo apt-get install libboost-all-dev
sudo apt-get install libvtk7.1-qt libvtk7.1 libvtk7-qt-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 openjdk-8-jdk openjdk-8-jre
可以将上述命令制作成一个Shell文件,然后在控制台执行
sudo sh dependency.sh
【安装问题】安装libflann1.9时报错
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarly unavailable)
输入下面命令解决问题:
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/dpkg/lock
2 安装git
sudo apt-get install git
3 下载pcl代码
可pcl官网手动下载,也可用git下载
git clone https://github.com/PointCloudLibrary/pcl.git
4 编译
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
中途出现[E:49%]错误,导致编译之后出现错误,这种情况,直接再次运行一下编译命令,就可以了。
5 测试
编写源文件
新建一个文件夹,里面新建一个c++的源文件test.cpp
#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
int main(int argc, char **argv) {
std::cout << "Test PCL !!!" << std::endl;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
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<uint32_t>(r) << 16 |
static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
point.rgb = *reinterpret_cast<float*>(&rgb);
point_cloud_ptr->points.push_back (point);
}
if (z < 0.0)
{
r -= 13;
g += 13;
}
else
{
g -= 13;
b += 13;
}
}
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;
}
用cmake编译,编写cmake文件CMakeList.txt
cmake_minimum_required(VERSION 2.6)
project(TEST)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(TEST test.cpp)
target_link_libraries (TEST ${PCL_LIBRARIES})
install(TARGETS TEST RUNTIME DESTINATION bin)
开始编译:新建build文件夹,然后进入文件夹,进行cmake,再make编译
mkdir build
cd build/
cmake ..
make
ls
./TEST
build文件夹下生成TEST二进制文件
执行后的效果为
Reference
以上。