前文:
从零开始Ubuntu16.04+ORBSLAM2+ROS实验实录(一):安装与配置
从零开始Ubuntu16.04+ORBSLAM2+ROS实验实录(二):相机测试与标定
1 编译ROS_ORBSLAM
进入ORB_SLAM2项目根目录直接运行
chmod +x ./build_ros.sh ./build_ros.sh
一般情况下会遇到若干错误,例如
错误1 /usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
「解决方法」
在ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中添加一行
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 -lboost_system # 添加这行 )
2 启动ORBSLAM
# 终端A运行ROS roscore # 终端B启动相机 roslaunch usb_cam usb_cam-test.launch # 终端C启动ORBSLAM rosrun ORB_SLAM2 Mono /home/winter/Project/SLAM/ORBSLAM2/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/winter/Project/SLAM/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2/my_cam.yaml
注意:my_cam.yaml用从零开始Ubuntu16.04+ORBSLAM2+ROS实验实录(二):相机测试与标定的标定文件,否则可能出现始终无法初始化帧(TRYING INITIALIZATION)的情况。
这里记录几个常见的也是本文遇到的错误
错误2:
OpenCV Error: Bad argument (Invalid pointer to file storage) in cvGetFileNodeByName, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp, line 861
terminate called after throwing an instance of ‘cv::Exception’
what(): /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp:861: error: (-5) Invalid pointer to file storage in function cvGetFileNodeByName
已放弃 (核心已转储)
错误分析:很显然,该错误由Opencv引起,叙述为“严重冲突”,查阅资料得知是opencv的版本问题,ros自带的opencv版本为3.3.1
winter@Winter:~$ find /opt/ros/ -name opencv /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv
与编译ORBSLAM工程时使用的openCV版本不同,例如本文使用的是opencv2.4.11,产生版本冲突,具体地,体现在编译时的警告信息中:
Linking CXX executable ../Mono /usr/bin/ld: warning: libopencv_core.so.2.4, needed by ../../../../lib/libORB_SLAM2.so, may conflict with libopencv_core.so.3.3 [100%] Built target Mono Linking CXX executable ../RGBD Linking CXX executable ../Stereo /usr/bin/ld: warning: libopencv_core.so.2.4, needed by ../../../../lib/libORB_SLAM2.so, may conflict with libopencv_core.so.3.3
解决方法简言之就是:更改链接库为3.3.1,重新编译工程。
(1) 删除ORB_SLAM2、DBoW2以及ROS/ORB_SLAM2/src下的build文件
(2) 更改ORB_SLAM2、DBoW2以及ROS/ORB_SLAM2/src下的CMakeList文件
set(OpenCV_DIR "/usr/local/include/opencv331/share/OpenCV") find_package(OpenCV 3.3.1 QUIET) if(NOT OpenCV_FOUND) find_package(OpenCV 2.4.3 QUIET) if(NOT OpenCV_FOUND) message(FATAL_ERROR "OpenCV > 2.4.3 not found.") endif() endif()