到网站“https://github.com/PointCloudLibrary/pcl/releases”找到PCL1.8.1
或者
git clone https://github.com/PointCloudLibrary/pcl.git
下载最新版本
或者
mkdir pcl1.8
cd pcl1.8
wget https://github.com/PointCloudLibrary/pcl/archive/pcl-1.8.1.tar.gz
tar -xf pcl-1.8.1.tar.gz
cd pcl-pcl-1.8.1
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
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev
sudo apt-get install libqhull-dev
在安装某些依赖项时可能会比较耗时。
wget http://www.vtk.org/files/release/7.1/VTK-7.1.0.tar.gz
tar -xf VTK-7.1.0.tar.gz
cd VTK-7.1.0 && mkdir build && cd build
cmake ..
make
sudo make install
进入解压缩的pcl文件夹,建立build文件并进入:
cd ~/Downloads/pcl-pcl-1.8.1
mkdir build && cd build
指定编译的相关参数,指定安装文件位置为/usr/local:
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON -DBUILD_apps_point_cloud_editor=ON -DBUILD_apps_3d_rec_framework=ON -DBUILD_apps_in_hand_scanner=ON ..
有的文档中说安装文件位置为/usr/local/include/pcl-1.8,这种设置会使得在CMakeLists.txt中find_package()时找不到PCL,需要在CMakeLists.txt中添加set(PCL_DIR "/usr/local/include/pcl-1.8/share/pcl-1.8")
才可以。
如果在环境检查过程中,发现缺少“PCAP",请参考文章末尾提到的解决办法进行解决。
根据CPU核心数目不同,选择编译使用的-j选项,如使用6个核心进行编译:
make -j6
编译后安装到之前指定的文件夹中(即”/usr/local/pcl-1.8)
make install
如果将PCL安装到了默认路径,则直接用即可。
如果将pcl安装到自己设置的路径中,则需要在进行设置。比如把pcl-1.8安装到了 “/usr/local/include/pcl-1.8”,所以任何程序调用pcl-1.8库,都要在CMakeLists.txt里设置PCLConfig.cmake这个文件所在目录,之后才能在CMakeLists.txt里面使用find_package(),其中,PCL_DIR的值是PCLConfig.cmake这个文件所在的目录。
set(PCL_DIR "/usr/local/include/pcl-1.8/share/pcl-1.8")
find_package(PCL 1.8 REQUIRED COMPONENTS)
include_directiories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definations(${PCL_DEFINATIONS})
(1)建立一个pcl_test的文件夹,在里面新建pcl_test.cpp文件,文件内容如下:
#include
#include
#include
#include
#include
#include
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;
}
(2)在pcl_test文件夹下新建CMakeLists.txt文件,文件内容如下:
cmake_minimum_required(VERSION 2.6)
project(pcl_test)
find_package(PCL 1.8 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)
(3)在pcl_test文件夹下新建build文件并进入
mkdir build
cd build
cmake ..
make
./pcl_test
显示图片即安装成功。
问题1:缺少PCAP
“Could Not find PCAP (missing: PCAP_LIBRARIES PCAP_INCLUDE_DIRS), Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)”
第一条解决办法便是安装libpcap
下载pcap http://www.tcpdump.org/#latest-release
然后
tar -zxvf libpcap-1.9.0.tar.gz
cd libpcap-1.9.0
sudo ./configure
sudo make
sudo make install
如果在安装libpcap时出现这个错误:
error: Neither flex nor lex was found.
原因是缺少文件支持。
解决办法:
sudo apt-get install flex bison
参考:
“https://blog.csdn.net/lilywri823/article/details/86583269”
“https://blog.csdn.net/suyunzzz/article/details/96722184”