【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】
图像处理,大家都知道它有显著的优点和缺点。优点就是分辨率高,信息丰富。缺点就是,整个图像本身没有深度信息。过去在深度信息这部分,大家一般都倚重于激光雷达,但是激光雷达价格比较高,所以一般用的比较少。但是,现在随着3d camera、多线激光雷达的普及,特别是价格的大幅度下降,这样的话,我们不仅可以使用图像来作为数据输入的来源,还可以使用多线雷达的点云,这一点相比较以前就很方便了。
1、pcl点云库的安装
在树莓派4b上面安装点云库,还是很方便的,直接用sudo安装即可,
sudo apt-get install libpcl-dev
2、准备CMakeLists.txt
为了验证pcl点云库是不是真的安装好了,我们有必要编写一个程序验证一下。在这之前,先准备一个cmake的编译脚本CMakeLists.txt,
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)project(pcd_write)find_package(PCL 1.2 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})link_directories(${PCL_LIBRARY_DIRS})add_definitions(${PCL_DEFINITIONS})add_executable (pcd_write pcd_write.cpp)
target_link_libraries (pcd_write ${PCL_LIBRARIES})
3、准备pcd_write.cpp
准备好了编译脚本之后,接下来就是源代码文件,这部分可以复用我们之前写过的一个代码,命名为pcd_write.cpp。
#include <iostream>#include <pcl/io/pcd_io.h>#include <pcl/point_types.h>intmain (){pcl::PointCloud<pcl::PointXYZ> cloud;// Fill in the cloud datacloud.width = 5;cloud.height = 1;cloud.is_dense = false;cloud.resize (cloud.width * cloud.height);for (auto& point: cloud){point.x = 1024 * rand () / (RAND_MAX + 1.0f);point.y = 1024 * rand () / (RAND_MAX + 1.0f);point.z = 1024 * rand () / (RAND_MAX + 1.0f);}pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd." << std::endl;for (const auto& point: cloud)std::cerr << " " << point.x << " " << point.y << " " << point.z << std::endl;return (0);
}
4、生成makefile并编译
有了CMakeLists.txt和cpp文件,下面就可以开始编译了。编译的方法有两步,即cmake . && make。如果在这过程中没有出现错误的话,就代表我们的编译时ok的。
5、执行
编译好了,只是第一步,第二步还需要跑起来看一下。如果跑起来也没问题,才能说明pcl安装是正确的。
feixiaoxing@raspberrypi:~/Desktop/pcl $ ./pcd_write
Saved 5 data points to test_pcd.pcd.0.352222 -0.151883 -0.106395-0.397406 -0.473106 0.292602-0.731898 0.667105 0.441304-0.734766 0.854581 -0.0361733-0.4607 -0.277468 -0.916762
有兴趣的同学可以通过ldd看看pcd_write依赖于哪些动态库,这也是蛮有意思的,
feixiaoxing@raspberrypi:~/Desktop/pcl $ ldd pcd_writelinux-vdso.so.1 (0x0000007f8ea8f000)libpcl_io.so.1.13 => /lib/aarch64-linux-gnu/libpcl_io.so.1.13 (0x0000007f8e760000)libpcl_common.so.1.13 => /lib/aarch64-linux-gnu/libpcl_common.so.1.13 (0x0000007f8e690000)libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000007f8e470000)libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000007f8e430000)libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007f8e280000)libboost_filesystem.so.1.74.0 => /lib/aarch64-linux-gnu/libboost_filesystem.so.1.74.0 (0x0000007f8e240000)libboost_iostreams.so.1.74.0 => /lib/aarch64-linux-gnu/libboost_iostreams.so.1.74.0 (0x0000007f8e200000)libpcl_io_ply.so.1.13 => /lib/aarch64-linux-gnu/libpcl_io_ply.so.1.13 (0x0000007f8e190000)libvtkIOGeometry-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkIOGeometry-9.1.so.1 (0x0000007f8e010000)libvtkIOPLY-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkIOPLY-9.1.so.1 (0x0000007f8dfd0000)libpng16.so.16 => /lib/aarch64-linux-gnu/libpng16.so.16 (0x0000007f8df70000)libusb-1.0.so.0 => /lib/aarch64-linux-gnu/libusb-1.0.so.0 (0x0000007f8df40000)libOpenNI2.so.0 => /lib/aarch64-linux-gnu/libOpenNI2.so.0 (0x0000007f8dec0000)libOpenNI.so.0 => /lib/libOpenNI.so.0 (0x0000007f8de20000)libpcap.so.0.8 => /lib/aarch64-linux-gnu/libpcap.so.0.8 (0x0000007f8ddb0000)libgomp.so.1 => /lib/aarch64-linux-gnu/libgomp.so.1 (0x0000007f8dd40000)libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007f8dca0000)libvtkIOImage-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkIOImage-9.1.so.1 (0x0000007f8db30000)libvtkIOLegacy-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkIOLegacy-9.1.so.1 (0x0000007f8da80000)libvtkImagingCore-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkImagingCore-9.1.so.1 (0x0000007f8d8c0000)libvtkIOCore-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkIOCore-9.1.so.1 (0x0000007f8d840000)libvtkCommonExecutionModel-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonExecutionModel-9.1.so.1 (0x0000007f8d700000)libvtkCommonDataModel-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonDataModel-9.1.so.1 (0x0000007f8d290000)libvtkCommonCore-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonCore-9.1.so.1 (0x0000007f8c940000)/lib/ld-linux-aarch64.so.1 (0x0000007f8ea52000)libz.so.1 => /lib/aarch64-linux-gnu/libz.so.1 (0x0000007f8c900000)libbz2.so.1.0 => /lib/aarch64-linux-gnu/libbz2.so.1.0 (0x0000007f8c8d0000)liblzma.so.5 => /lib/aarch64-linux-gnu/liblzma.so.5 (0x0000007f8c880000)libzstd.so.1 => /lib/aarch64-linux-gnu/libzstd.so.1 (0x0000007f8c7c0000)libvtkFiltersHybrid-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkFiltersHybrid-9.1.so.1 (0x0000007f8c6e0000)libvtkRenderingCore-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkRenderingCore-9.1.so.1 (0x0000007f8c4e0000)libjsoncpp.so.25 => /lib/aarch64-linux-gnu/libjsoncpp.so.25 (0x0000007f8c490000)libvtkFiltersGeneral-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkFiltersGeneral-9.1.so.1 (0x0000007f8c090000)libvtkFiltersCore-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkFiltersCore-9.1.so.1 (0x0000007f8b990000)libvtkCommonSystem-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonSystem-9.1.so.1 (0x0000007f8b930000)libvtkCommonTransforms-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonTransforms-9.1.so.1 (0x0000007f8b8d0000)libvtkCommonMath-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonMath-9.1.so.1 (0x0000007f8b890000)libvtksys-9.1.so.1 => /lib/aarch64-linux-gnu/libvtksys-9.1.so.1 (0x0000007f8b820000)libvtkCommonMisc-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonMisc-9.1.so.1 (0x0000007f8b440000)libudev.so.1 => /lib/aarch64-linux-gnu/libudev.so.1 (0x0000007f8b3f0000)libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007f8b3c0000)libjpeg.so.62 => /lib/aarch64-linux-gnu/libjpeg.so.62 (0x0000007f8b340000)libtinyxml.so.2.6.2 => /lib/aarch64-linux-gnu/libtinyxml.so.2.6.2 (0x0000007f8b300000)libdbus-1.so.3 => /lib/aarch64-linux-gnu/libdbus-1.so.3 (0x0000007f8b280000)libvtkDICOMParser-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkDICOMParser-9.1.so.1 (0x0000007f8b240000)libvtkmetaio-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkmetaio-9.1.so.1 (0x0000007f8b190000)libvtkpugixml-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkpugixml-9.1.so.1 (0x0000007f8b130000)libtiff.so.6 => /lib/aarch64-linux-gnu/libtiff.so.6 (0x0000007f8b090000)libtbb.so.12 => /lib/aarch64-linux-gnu/libtbb.so.12 (0x0000007f8b030000)libdouble-conversion.so.3 => /lib/aarch64-linux-gnu/libdouble-conversion.so.3 (0x0000007f8aff0000)liblz4.so.1 => /lib/aarch64-linux-gnu/liblz4.so.1 (0x0000007f8afa0000)libvtkloguru-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkloguru-9.1.so.1 (0x0000007f8af50000)libvtkImagingSources-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkImagingSources-9.1.so.1 (0x0000007f8af00000)libvtkFiltersGeometry-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkFiltersGeometry-9.1.so.1 (0x0000007f8ae20000)libvtkCommonColor-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonColor-9.1.so.1 (0x0000007f8ade0000)libvtkFiltersSources-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkFiltersSources-9.1.so.1 (0x0000007f8ad20000)libvtkCommonComputationalGeometry-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkCommonComputationalGeometry-9.1.so.1 (0x0000007f8acd0000)libvtkfmt-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkfmt-9.1.so.1 (0x0000007f8ac90000)libvtkkissfft-9.1.so.1 => /lib/aarch64-linux-gnu/libvtkkissfft-9.1.so.1 (0x0000007f8ac60000)libsystemd.so.0 => /lib/aarch64-linux-gnu/libsystemd.so.0 (0x0000007f8ab70000)libwebp.so.7 => /lib/aarch64-linux-gnu/libwebp.so.7 (0x0000007f8aaf0000)libLerc.so.4 => /lib/aarch64-linux-gnu/libLerc.so.4 (0x0000007f8aa40000)libjbig.so.0 => /lib/aarch64-linux-gnu/libjbig.so.0 (0x0000007f8aa10000)libdeflate.so.0 => /lib/aarch64-linux-gnu/libdeflate.so.0 (0x0000007f8a9d0000)libcap.so.2 => /lib/aarch64-linux-gnu/libcap.so.2 (0x0000007f8a9a0000)libgcrypt.so.20 => /lib/aarch64-linux-gnu/libgcrypt.so.20 (0x0000007f8a890000)libgpg-error.so.0 => /lib/aarch64-linux-gnu/libgpg-error.so.0 (0x0000007f8a840000)