Ubuntu16.04安装PCL
程序员文章站
2024-01-23 12:12:28
...
3D重建中,肯定是避免不了需要看自己的建立的模型的效果,所以之前一段时间在纠结用什么库来显示,最后还是决定了用PCL库进行模型的显示。我也仅仅只是懂得普通的安装和在自己的程序里测试使用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.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
2.从github上把PCL源码clone下来
git clone https://github.com/PointCloudLibrary/pcl.git pcl-trunk
ln -s pcl-trunk pcl
3.编译源码。过程极其漫长,可以去泡杯茶喝了
cd pcl
mkdir release
cd release
cmake cmake -DCMAKE_BUILD_TYPE=None -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make
4.安装。整个过程耗时3-4个小时
sudo make install
5.测试PCL
创建demo包
cd catkin_ws/src/
catkin_create_pkg demo std_msgs rospy roscpp
demo下创建pcl_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 -= 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)
编译运行:
sudo cmake .
sudo make
./pcl_test
结果:
BUG:#include <pcl/*****>找不到PCL包
执行完上面的步骤之后,如果你在IDE(比如Kdevelop)中#include <pcl/*****>的时候,你会发现kdevelop找不到pcl包含文件,原因是在/usr/include中pcl文件夹的名称是pcl1.9,我们可以把pcl1.9中的pcl文件夹移动到/usr/include中,然后删掉pcl1.9,这样就可以了
BUG:安装pcl缺失visualization
问题:经阅读pcl安装包中的CMakeLists文件发现,安装该模块需要安装依赖库vtk的高版本,网上给的教程中安装时VTK默认版本较低。解决方法:安装vtk7.1.1
vtk7.1.1安装方法: 下载地址:https://vtk.org/download/
首先下载VTK-7.1.1.tar.gz
参考https://blog.csdn.net/qq_29761791/article/details/94135193
解压vtk,然后将vtkdata解压至vtk文件夹下,执行如下命令:
mkdir build
cd build
cmake ../ -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DVTK_WRAP_PYTHON=ON
make -j8
sudo make install
还可参考这个网址:http://www.cb.uu.se/~johan/vtk/installing_vtk_on_rhel6.txt
END.