pcl点云数据库,用来进行3D信息的获取与处理,和opencv相比较,opencv是用来处理二维信息,他是学术界与工业界针对点云最全的库,且网络上相关的资料很多。以下是pcl的安装步骤以及遇到的问题。
提前说明,本人用的是ubuntu20.04+pcl1.12.0+vtk7.1.1,使用源码编译的方式,Vtk用来完成点云的可视化。
之前安装过pcl1.12.0+vtk9.1.1,最后pcl安装可视化闪退,所以还是Vtk下载的vtk7.1.1
网络上有说pcl1.8.0+vtk7.1.1是标配,但是在安装pcl1.8.1时出现过错误。
所以本文选择安装 pcl1.12.1 + vtk7.1.1 +qt5.12(在此不做安装说明)
- 首先安装pcl各种依赖
sql
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 # ubuntu20.4对应1.9
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-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 libopenni-dev
sudo apt-get install libopenni2-dev
可能问题:
(1) sudo apt-get install libflann1.9 libflann-dev 显示无法定位包libflann,
首先去查看系统对应的版本 查看地址:Ubuntu -- Package Search Results -- libflann
搜索libflann 选择ubuntu20.04对应的codename代号 :focal :
打开终端,执行以下命令:
css
lsb_release -a
可以看到ubuntu20.04对应libflan1.9
(2) 安装过程中遇到无法连接的问题,考虑更换源
参考文章:Ubuntu更换软件源_寥廓长空的博客-CSDN博客_ubuntu源
- 安装VTK
下载地址:Download | VTK
本人下载:VTK-7.1.1.zip
2.1 首先安装vtk各种依赖:
csharp
# 首先安装VTK的依赖:X11,OpenGL;cmake和cmake-gui在安装pcl依赖的时候安装过了的话可以跳过
# X11
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
# OpenGL
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
# cmake && cmake-gui
sudo apt-get install cmake cmake-gui
2.2 安装Vtk
2.2.1 解压到准备好的安装目录。在目录下新建build文件夹
打开终端输入:
undefined
cmake-gui
where is the source code: 路径为VTK目录
where to build the binaries:路径为VTK目录下build的路径
如下图:
点击:configure,显示"Configuring done"。
再勾选"VTK-Group-Qt",点击"Configure";完成后,显示"Configuring done";
最后点击"Generate";显示"Generating done",完成。
2.2.2 在build目录下,打开终端输入:
go
make -j8 # 要是8核处理器还比较着急看结果的话,可以:make -j16
sudo make install
- 安装pcl
下载地址: Release PCL 1.12.0 · PointCloudLibrary/pcl · GitHub
打开pcl目录,新建build文件夹
在build文件中,打开终端,输入:
cobol
cmake -DCMAKE_TYPE=None ..
make -j8 // 选择8个进程同时处理,如果机子比较差,可以选择make -j4 或者 make
sudo make install
到此pcl下载完成,时间会比较长。
- pcl测试
以下使用两段代码进行测试
4.1 文件构成
cmakelist.txt
scss
cmake_minimum_required(VERSION 2.6)
project(pcl_test)
find_package(PCL 1.12 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)
pcl_test.cpp
cobol
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
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);
}
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);
}
运行:进入build,打开终端输入:
cobol
cmake ..
make
./pcl_test.cpp
得到结果:
4.2 另一个测试代码为
pcl_test.cpp
cobol
#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 -= 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;
}
运行结果:
如果以上结果没问题,pcl就安装成功了。
- cloudcompare软件安装
推荐snap安装方式
sql
sudo apt-get update
sudo apt install snap
sudo snap install cloudcompare
undefined
cloudcompare.CloudCompare
loudcompare.ccViewer