参考博客:
1、ROS进阶学习(七)-- ORB_SLAM2实战(一)
2、/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
3、ROS(三):使用ROS跑通ORB_SLAM2
4、ORB_SLAM2之Pangolin的安装与问题处理
一、编译平台:
操作系统:ubuntu 16.04
ROS版本: kinetic
摄像头:笔记本自带
二、安装步骤:(摘自:ROS进阶学习(七)-- ORB_SLAM2实战(一))
1、驱动摄像头显示图像
$ cd ~/camera_ws/src
$ git clone https://github.com/bosch-ros-pkg/usb_cam
$ cd ..
$ catkin_make
$ source devel/setup.bash
$ roscore
$ roslaunch usb_cam usb_cam-test.launch
记录下显示窗口的topic: /usb_cam/image_raw
2 、编译ORB-SLAM2之前的相关依赖项和库安装
1)安装Boost
$ sudo apt-get install libboost-all-dev
2)安装g2o
为了编译g2o需要先安装如下三个库
$ sudo apt-get install libblas-dev
$ sudo apt-get install liblapack-dev
$ sudo apt-get install libeigen3-dev
$ cd ~/camera_ws/src
$ git clone https://github.com/RainerKuemmerle/g2o
$ cd ~/camera_ws/src/g2o
$ mkdir build
$ cmake ..
$ make
$ sudo make install
3 ) 安装 Pangolin
$ sudo apt-get install libglew-dev #安装Glew
$ sudo apt-get install cmake #安装CMake
$ sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev #安装Boost
$ sudo apt-get install libpython2.7-dev #安装Python2'Python3
#下载、编译、安装Pangolin:
$ cd ~/orbslam_ws/src
$ git clone https://github.com/stevenlovegrove/Pangolin.git
$ cd Pangolin
$ mkdir build
$ cd build
$ cmake -DCPP11_NO_BOOST=1 ..
$ make
$ sudo make install
3、下载ORB_SLAM2 ROS包
$ cd ~/camera_ws/src
$ git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
$ cd ORB_SLAM2
$ chmod +x build.sh
$ ./build.sh
$ chmod +x build_ros.sh
$ ./build_ros.sh
4、运行
$roscore
#新开一个终端
$roslaunch usb_cam usb_cam-test.launch
#这时摄像头应该已经打开,新开一个终端
#这里用的参数文件是examples自带的,其实还是要自己标定下摄像头的
$rosrun ORB_SLAM2 Mono ~/Documents/code/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/Documents/code/ORB_SLAM2/Examples/Monocular/TUM1.yaml
三、出现的问题及解决办法
1、第二步Pangolin安装出错
现象:提示的错误大部分是跟openni.h和XnCppWrapper.h有关的
解决办法:编译Pangolin时,并不需要用到OpenNI,可以在编译时将其屏蔽;
打开~/orbslam_ws/src/Pangolin/src/CMakeLists.txt,注释掉以下关于OpenNI和OpenNI2相关编译选项;
#option(BUILD_PANGOLIN_OPENNI "Build support for OpenNI video input" ON)
#if(BUILD_PANGOLIN_OPENNI AND BUILD_PANGOLIN_VIDEO)
# find_package(OpenNI QUIET)
# if(OPENNI_FOUND)
# set(HAVE_OPENNI 1)
# if(_LINUX_)
# add_definitions(-Dlinux=1)
# endif()
# list(APPEND INTERNAL_INC ${OPENNI_INCLUDE_DIRS} )
# list(APPEND LINK_LIBS ${OPENNI_LIBRARIES} )
# list(APPEND HEADERS ${INCDIR}/video/drivers/openni.h )
# list(APPEND SOURCES video/drivers/openni.cpp)
# list(APPEND VIDEO_FACTORY_REG RegisterOpenNiVideoFactory )
# message(STATUS "OpenNI Found and Enabled")
# endif()
#endif()
#option(BUILD_PANGOLIN_OPENNI2 "Build support for OpenNI2 video input" ON)
#if(BUILD_PANGOLIN_OPENNI2 AND BUILD_PANGOLIN_VIDEO)
# find_package(OpenNI2 QUIET)
# if(OPENNI2_FOUND)
# set(HAVE_OPENNI2 1)
# if(_LINUX_)
# add_definitions(-Dlinux=1)
# endif()
# list(APPEND INTERNAL_INC ${OPENNI2_INCLUDE_DIRS} )
# list(APPEND LINK_LIBS ${OPENNI2_LIBRARIES} )
# list(APPEND HEADERS ${INCDIR}/video/drivers/openni2.h )
# list(APPEND SOURCES video/drivers/openni2.cpp)
# list(APPEND VIDEO_FACTORY_REG RegisterOpenNi2VideoFactory )
# message(STATUS "OpenNI2 Found and Enabled")
# endif()
#endif()
2、第三步./build_ros.sh编译出错/
现象:/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
解决办法:在Examples/ROS/ORB_SLAM2/Cmakelist.txt 的文件后面加入两句话:
target_link_libraries(Stereo boost_system boost_filesystem)
target_link_libraries(RGBD boost_system boost_filesystem)
3、第四步运行完,弹出的视频窗口只出现waiting for image,无任何画面
原因:ORB_SLAM2节点订阅的话题是/image/image_raw,而不是第一步中摄像头usb_cam节点发布的话题/usb_cam/image_raw,故没有视频画面;
解决办法:修改ORB_SLAM2节点订阅的话题为/usb_cam/image_raw
先查看~/camera_ws/src/ORB_SLAM2/build_ros.sh脚本中的内容:
echo "Building ROS nodes"
cd Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j
从~/camera_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2目录下用cmake编译生成ORB_SLAM2节点。
ORB_SLAM2节点生成源码在~/camera_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_mono.cc文件,做如下修改:
//源码中的代码
ros::Subscriber sub = nodeHandler.subscribe("/image/image_raw", 1, &ImageGrabber::GrabImage,&igb);
//修改后的代码
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);
注:另一种方法是将摄像头usb_cam节点发布的话题改为/image/image_raw