系统配置:ubuntu16.04
说明:之前成功编译过ORB_SLAM项目,所有很多库包括opencv在我的电脑之前已经安装好了,这些库的安装具体方法具体见ORB_SLAM的github网址:
https://github.com/raulmur/ORB_SLAM
因为中间出了点问题,因此我重新建了一个文件夹ORB_SLAM(将原来的文件移除) 进行编译,中间碰到的问题和解决方法如下。
1、编译ORB_SLAM过程中,移除manifest.xml中的opencv2的依赖以后,出现类或者函数未声明的问题。
/media/lee/ubuntu/myslam/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputeKeyPoints(std::vector<std::vector<cv::KeyPoint> >&)’:
/media/lee/ubuntu/myslam/src/ORBextractor.cc:607:63: error: ‘FAST’ was not declared in this scope
FAST(cellImage,cellKeyPoints[i][j],fastTh,true);
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc:616:34: error: ‘ORB’ has not been declared
if( scoreType == ORB::HARRIS_SCORE )
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc:683:17: error: ‘KeyPointsFilter’ has not been declared
KeyPointsFilter::retainBest(keysCell,nToRetain[i][j]);
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc:699:13: error: ‘KeyPointsFilter’ has not been declared
KeyPointsFilter::retainBest(keypoints,nDesiredFeatures);
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::operator()(cv::InputArray, cv::InputArray, std::vector<cv::KeyPoint>&, cv::OutputArray)’:
/media/lee/ubuntu/myslam/src/ORBextractor.cc:760:82: error: ‘GaussianBlur’ was not declared in this scope
GaussianBlur(workingMat, workingMat, Size(7, 7), 2, 2, BORDER_REFLECT_101);
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc: In member function ‘void ORB_SLAM::ORBextractor::ComputePyramid(cv::Mat, cv::Mat)’:
/media/lee/ubuntu/myslam/src/ORBextractor.cc:800:78: error: ‘INTER_LINEAR’ was not declared in this scope
resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEA
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc:800:90: error: ‘resize’ was not declared in this scope
resize(mvImagePyramid[level-1], mvImagePyramid[level], sz, 0, 0, INTER_LINEAR);
^
/media/lee/ubuntu/myslam/src/ORBextractor.cc:803:80: error: ‘INTER_NEAREST’ was not declared in this scope
resize(mvMaskPyramid[level-1], mvMaskPyramid[level], sz, 0, 0, INTER_NEARE
^
CMakeFiles/myslam.dir/build.make:443: recipe for target 'CMakeFiles/myslam.dir/src/ORBextractor.cc.o' failed
make[2]: *** [CMakeFiles/myslam.dir/src/ORBextractor.cc.o] Error 1
CMakeFiles/Makefile2:613: recipe for target 'CMakeFiles/myslam.dir/all' failed
make[1]: *** [CMakeFiles/myslam.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
解决方法:在src/ORBextractor.cc中添加
#include <opencv2/opencv.hpp>
然后重新编译,结果如下:
运行完
cmake .. -DROS_BUILD_TYPE=Release
结果如下:
-- Configuring done
-- Generating done
-- Build files have been written to: /media/lee/ubuntu/myslam/build
2、继续执行make命令后结果如下,出现libboost_system.so共享库的问题:
[ 78%] Linking CXX executable ../bin/myslam
/usr/bin/ld: CMakeFiles/myslam.dir/src/main.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
CMakeFiles/myslam.dir/build.make:1609: recipe for target '../bin/myslam' failed
make[2]: *** [../bin/myslam] Error 1
CMakeFiles/Makefile2:421: recipe for target 'CMakeFiles/myslam.dir/all' failed
make[1]: *** [CMakeFiles/myslam.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
-----------------------------
解决方法:
在CmakeLists.txt 的 include_directories 中添加${Boost_INCLUDE_DIRS}
include_directories(
${PROJECT_SOURCE_DIR}
${EIGEN3_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
)
添加${Boost_LIBRARIES}如下:
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Boost_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
)
添加find_package(Boost COMPONENTS system)如下:
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Boost COMPONENTS system)
编译结果如下:
-- Configuring done
-- Generating done
-- Build files have been written to: /media/lee/ubuntu/myslam/build
[ 0%] Built target rospack_genmsg_libexe
[ 0%] Built target rosbuild_precompile
[ 5%] Linking CXX executable ../bin/myslam
[100%] Built target myslam
------------------------分界线--------------------------
接下来,开始测试编译好的程序,运行案例中的launch文件:
1、首先我们需要做一些准备工作,将之前使用的Example.bag文件复制到myslam文件夹下;然后,将Data文件夹下的ORBvoc.txt.tar.gz解压,加快运行程序时的读取速度。
2、接下来开始真正的运行测试。
打开终端,输入:roscore
打开新的终端,输入:
roscd myslam
roslaunch ExampleGroovyOrNewer.launch
打开新的终端,输入:
rosbag play --pause Example.bag
按一下空格键,就可以看到rviz上开始建图了。截图如下:
----------------------分割线-----------------------
下面是运行笔记本电脑的摄像头过程:
说明:我之前用ros重现标定过笔记本自带的摄像头了,标定完的文件命名为Settingsnew.yaml,后面加了new以示区别。
1、打开终端,运行roscore
2、运行myslam 节点:
未完待续。。。。。。