开发环境:NX+Ubuntu18.04+ROS-melodic
接着上篇,开始orb-slam2稠密回环建图
二、NX + D435i + ORB-SLAM2 稠密回环建图
先上效果图
这里感谢大神提供一个可回环的稠密地图版本:
https://github.com/xiaobainixi/ORB-SLAM2_RGBD_DENSE_MAP.git
2.1 安装依赖(和orb-slam2环境配置一样,如果已经配置过,可以跳到pcl安装)
(1)Pangolin(推荐0.5版本)
//安装依赖:
sudo apt install libgl1-mesa-dev
sudo apt install libglew-dev
sudo apt install libpython2.7-dev
sudo apt install pkg-config
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols
//安装编译
git clone https://github.com/stevenlovegrove/Pangolin/tree/v0.5.git
cd Pangolin
mkdir build
cd build
cmake ..
make
sudo make install
(2)opencv3.2.0(巨坑!!!)
如果直接使用ros自带的3.2.0版本,这里的安装就可以跳过了,后面ubuntu下编译和ros下编译都是引用usr/基本都没问题,当然你也可以源码安装在/usr/local下,步骤如下:
去官网下载源码然后解压,这里是默认安装在/usr/local下,如果安装其它版本(如opencv3.4.x)的时候想让两个版本共存,就更改安装位置,就把“ CMAKE_INSTALL_PREFIX=/usr/local/ .. ”中的/usr/local改为你自己的路径
但是后续ros下编译需要重新下载cv_bridge编译,否则会有两个版本的 .so文件冲突!!!(恶心的是:编译虽然warning,但是会通过,但是后面一运行就报错)
//安装一些依赖
sudo apt-get install libpng-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libopenexr-dev
sudo apt-get install libtiff-dev
sudo apt-get install libwebp-d
sudo apt-get install libgtk2.0-dev
sudo apt-get install libgtk-3-dev
//安装编译
cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release OPENCV_ENABLE_NONFREE=ON -DENABLE_PRECOMPILED_HEADERS=OFF -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local/ ..
make
sudo make install
(3)pcl1.8.1+vtk7.1.1
因为我们需要实现稠密点云,这是通过pcl库实现的,因此需要安装pcl,如果你的ros自带了pcl1.8,那么恭喜你,你又可以跳过安装了,如果不放心,可以重新源码安装:
这里小编一开始使用了如下的配置:vtk8.2.0+pcl1.12.0,但是在编译pcl1.12.0的时候报错了:“c++: fatal error: no input files” 原因是cmakelist.txt中C++的标准不对(pcl1.9开始就需要C++14的标准了),可是nx板也支持c++14,这里具体不知道什么原因,最后还是用原始的pcl1.8.1吧,vtk6.3 或者 7.1.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 libpcap-dev
sudo apt-get install libflann1.9 libflann-dev //ubuntu18.04用1.9;ubuntu16.04用1.8
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-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 libopenni-dev libopenni2-dev
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
如果需要vtk6.3:
sudo apt-get install vtk6 libvtk6.3 libvtk6-dev libvtk6.3-qt libvtk6-qt-dev
如果需要vtk7.1.1,去官网下载7.1.1版本的源码、解压:
cd VTK-7.1.1
mkdir build
cd build
cmake ..
make -j4
sudo make install
若中间报错:Found unsuitable Qt version “” from NOTFOUND, this code requires Qt 4.x
解决办法:sudo apt-get install qt4-default
pcl1.8.1官网源码下载,解压后:
cd pcl-1.8.1
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=None ..
make -j4
sudo make install
若测试程序的时候,执行可执行文件时不显示点云并报错缺少lib.so.1文件,则
1)打开/etc/ld.so.conf文件并在第二行粘贴以下内容后保存
/usr/local/lib/libvtkglew-7.1.so.1
2)sudo ldconfig
然后在测试程序下重新cmake和make即可
2.2 安装编译ORB-SLAM2_RGBD_DENSE_MAP.git
(1)ubuntu下编译:
git clone https://github.com/xiaobainixi/ORB-SLAM2_RGBD_DENSE_MAP.git
下载后,先将正常版本的Vocabulary文件夹复制到ORB-SLAM2_RGBD_DENSE_MAP下,打开camkelist.txt ,将44行左右的 “ find_package( PCL 1.7 REQUIRED ) ”中的1.7改为1.8,修改后如下:
find_package( PCL 1.8 REQUIRED )
将camkelist.txt 的 -march=native 删除,(包括 DBoW2 和 g2o 以及 ros 下的cmakelist.txt) 如下:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 ")
打开include / pointcloudmapping.h,49行“bool loopbusy;”修改如下:
bool loopbusy = false;
打开src / pointcloudmapping.cc,86-88行修改如下,将rgb的颜色修改正确
p.b = color.ptr<uchar>(m)[n*3+2];
p.g = color.ptr<uchar>(m)[n*3+1];
p.r = color.ptr<uchar>(m)[n*3];
在void PointCloudMapping::viewer() 中的while循环后(174-175之间)加入下面一行,用于保存点云地图,同时在开头增加 #include <pcl/io/pcd_io.h>
pcl::io::savePCDFileBinary( "vslam.pcd", *globalMap );
开始ubuntu下编译
cd ORB-SLAM2_RGBD_DENSE_MAP
chmod +x build.sh
./build.sh
(2)ROS下编译
由于我们需要使用的d435i的RGB信息以及深度信息,因此我们将上一篇中配置的rs_camera.launch文件中的以下imu参数修改为false
<arg name="enable_gyro" default="false"/>
<arg name="enable_accel" default="false"/>
将 ORB-SLAM2_RGBD_DENSE_MAP/Examples/ROS/ORB_SLAM21/src/ros_rgbd.cc中的topic修改为D435i发布的rgb和对齐后的depth信息
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/color/image_raw", 100);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/camera/aligned_depth_to_color/image_raw", 100);
打开CMakeLists.txt,将第3行和第6行的opencv、pcl位置就直接删了,并增加下面5行:
find_package(PCL REQUIRED) //新增这一行
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../../
${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS} //新增这一行
)
add_definitions( ${PCL_DEFINITIONS} ) //新增这一行
link_directories( ${PCL_LIBRARY_DIRS} ) //新增这一行
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
${PROJECT_SOURCE_DIR}/../../../lib/libopencv_core3.so
-lboost_system //新增这一行
)
开始编译:
添加环境配置
gedit ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/nx/你自己的路径/Example/ROS
source ~/.bashrc
开始编译
chmod +x build_ros.sh
./build_ros.sh
如果编译过程中报错:“libboost_filesystem.so :error adding symbols: file in wrong format” 以及“libboost_system.so :error adding symbols: file in wrong format”和“lib/libopencv_core3.so :error adding symbols: file in wrong format” 需要我们将系统自带的3个文件替换到ORB-SLAM2_RGBD_DENSE_MAP/lib 下:
首先删掉lib下的3个 libboost_filesystem.so,libboost_system.so 和 lib/libopencv_core3.so“
找到系统文件所在位置,并复制到lib下,例如针对:libboost_filesystem.so
locate boost_filesystem
sudo cp /usr/lib/aarch64-linux-gnu/libboost_filesystem.so /home/nx/ORB-SLAM2_RGBD_DENSE_MAP/lib
然后再 ./build_ros.sh
编译成功后,我们开始配置D435i所需的yaml文件,修改Asus.yaml中的内参和camera.bf。需要完整版的yaml文件,可以在评论区留下联系邮箱
(3)开始试验
打开相机:
cd realsense_ws
source devel setup.bash
roslaunch realsense2_camera rs_camera.launch
稠密建图运行:
rosrun ORBSLAM21 RGBD Vocabulary/ORBvoc.bin Examlpe/ROS/ORB_SLAM21/Asus.yaml
下一篇我们将使用奥比中光的Astrapro 相机实现orb-slam2稠密回环,未完待续~