本章程序的详细解析可参考以下网址:
程序一:dense_mapping.cpp→单目稠密地图
SLAM14讲学习笔记(十四)ch13 建图(代码详述带注释)
程序二:pointcloud_mapping.cpp→点云地图 & 程序三:octomap_mapping.cpp→八叉树地图
《视觉SLAM十四讲》笔记(ch13)
——————————————————————————————————————————
该程序的编译运行方法:
按照书P328网址下载本例程的测试数据,将解压后的文件夹放在文件夹dense_monocular内:
在文件夹dense_monocular路径下打开终端,依次输入以下指令:
mkdir build
cd build
cmake ..
make
./dense_mapping ../test_data
运行该工程文件,第一步需要按照书P350安装Octomap库及其依赖项doxygen,如若没安装这些直接编译程序,则会出现如下报错:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "Findoctomap.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "octomap", but
CMake did not find one.
Could not find a package configuration file provided by "octomap" with any
of the following names:
octomapConfig.cmake
octomap-config.cmake
Add the installation prefix of "octomap" to CMAKE_PREFIX_PATH or set
"octomap_DIR" to a directory containing one of the above files. If
"octomap" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
①
安装依赖项doxygen:
sudo apt-get install doxygen
②
安装Octomap库:
按照书P350提供的网址:
https://github.com/OctoMap/octomap
下载该库的cmake工程,之后编译安装:
~/slambook-master/3rdparty/octomap-devel目录下(本人的,读者以自身实际为准),打开终端,依次输入以下命令:
mkdir build
cd build
cmake ..
make
sudo make install
————————————————————————————————————
安装完之后,再次编译例程,在执行make指令的时候出现如下报错:
/usr/bin/ld: 找不到 -lvtkproj4
collect2: error: ld returned 1 exit status
CMakeFiles/octomap_mapping.dir/build.make:366: recipe for target 'octomap_mapping' failed
make[2]: *** [octomap_mapping] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/octomap_mapping.dir/all' failed
make[1]: *** [CMakeFiles/octomap_mapping.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
解决办法:
先执行:sudo apt-get install libproj-dev
再在CMakeLists.txt中加一条指令修复,即在add_executable语句前面加上list(REMOVE_ITEM PCL_LIBRARIES “vtkproj4”)
修改后的CMakeLists.txt如下:
cmake_minimum_required( VERSION 2.8 )
set( CMAKE_BUILD_TYPE Release )
set( CMAKE_CXX_FLAGS "-std=c++11" )
# opencv
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# eigen
include_directories( "/usr/include/eigen3/" )
# pcl
find_package( PCL REQUIRED COMPONENT common io filters )
include_directories( ${PCL_INCLUDE_DIRS} )
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") #20190703YC 新加修复语句
add_definitions( ${PCL_DEFINITIONS} )
# octomap
find_package( octomap REQUIRED )
include_directories( ${OCTOMAP_INCLUDE_DIRS} )
add_executable( pointcloud_mapping pointcloud_mapping.cpp )
target_link_libraries( pointcloud_mapping ${OpenCV_LIBS} ${PCL_LIBRARIES} )
add_executable( octomap_mapping octomap_mapping.cpp )
target_link_libraries( octomap_mapping ${OpenCV_LIBS} ${PCL_LIBRARIES} ${OCTOMAP_LIBRARIES} )
之后重新执行cmake、make指令编译程序,不再出现报错。
该问题的解决方法来源于网址:Ubuntu16.04安装pcl出现cannot find -lvtkproj4解决办法
————————————————————————————————————
程序运行(点云地图):
./build/pointcloud_mapping
会生成点云文件map.pcd,用以下指令打开该文件:
pcl_viewer map.pcd
————————————————————————————————————
程序运行(八叉树地图):
./build/octomap_mapping
会生成八叉树文件——octomap.bt文件,用以下指令打开该文件:
octovis octomap.bt