概述
目前网上大部分PCL安装教程针对的是1.8版本. 按照网上的教程安装PCL 1.9后缺少很多东西. 编译PCL demo时典型报错为: fatal error: pcl/visualization/pcl_visualizer.h: No such file or directory. 然后发现在PCL安装目录下("/usr/include/pcl-1.9/")根本没有visualization文件夹. 博主出现这种问题的原因主要是cmake版本太低. 解决过程如下:
1. 安装高版本cmake
1) 首先卸载旧版本cmake
apt-get autoremove cmake
2) 下载高版本cmake, 以13.4为例
wget https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.tar.gz
3) 解压并进入cmake-3.13.4-Linux-x86_64目录
tar -zxvf cmake-3.13.4-Linux-x86_64.tar.gz
cd cmake-3.13.4-Linux-x86_64/
4) 配置并安装
./configure
make
sudo make install
5) 解决路径问题
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
cmake
6) 验证
cmake --version
2. 自己编译安装PCL 1.9
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) 下载并解压pcl
3) 编译安装
解压完成后进入pcl目录
cd pcl
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON -DCMAKE_INSTALL_PREFIX=/usr ..
make
如果make时报错: make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/libproj.so', needed by 'lib/libpcl_io.so.1.9.1.99'。 停止。CMakeFiles/Makefile2:499: recipe for target 'io/CMakeFiles/pcl_io.dir/all' failed
建立软连接, 终端中输入: sudo ln -s /usr/lib/x86_64-linux-gnu/libproj.so.9 /usr/lib/x86_64-linux-gnu/libproj.so
之后重新make
make成功后, 在终端输入: sudo make install
完成安装.
3. PCL测试程序
//------------------------pcl_test.cpp--------------------
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
std::cout << "Test PCL !!!" << std::endl;
pcl::PointCloud<:pointxyzrgb>::Ptr point_cloud_ptr (new pcl::PointCloud<: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(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 needs this line
cmake_minimum_required(VERSION 2.8)
# Define project name
project(pcl_test_project)
find_package(PCL 1.9 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})
最后
以上就是开心冷风为你收集整理的pcl程序如何在linux上运行,Ubuntu系统安装PCL 1.9及以上版本的全部内容,希望文章能够帮你解决pcl程序如何在linux上运行,Ubuntu系统安装PCL 1.9及以上版本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复