目录
1 安装教程(本教程参考网络课程资料)
1.1 安装前准备
1.2 安装Pangolin (建议源码安装)
1.3 安装OpenCV3.4 (建议源码安装 )
1.4 安装Eigen3.3.7 (建议源码安装)
1.5 安装运行ORB-SLAM2及常见问题解决办法
2 安装问题及解决办法
问题1
解决办法
问题2
解决办法(1)
解决办法 (2)
问题3
解决办法(参考文章)
问题4
解决办法(1)
解决办法(2)
问题5
解决办法 (参考文章)
本文是作者在安装ORB-SLAM2过程中遇到的问题汇总,安装过程中遇到非常多的问题,参考众多博客,由于参考文章较多,只给出部分链接,在此谢谢参考文章的博主。
在刚装好的 Ubuntu 系统上安装 ORB-SLAM2、Pangolin 、 OpenCV 、 Eigen 、 g2o 与 DBoW2 ( ORB-SLAM2 自带)
安装前的准备: 安装 vim 、 cmake 、 git 、 gcc 、 g++
sudo apt-get install vim cmake
sudo apt-get install git
sudo apt-get install gcc g++
(1)安装依赖项
sudo apt-get install libglew-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libpython2.7-dev
(2)安装 Pangolin
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake -DCPP11_NO_BOOSR=1 ..
make -j
(1)安装依赖项
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev
sudo apt-get install libtiff4.dev libswscale-dev libjasper-dev
(2)安装 OpenCV3.4
进入下载的安装压缩包,解压到某文件夹,然后进去该文件夹建立build文件夹 编译文件夹
cd opencv-3.4.5
mkdir build
cd build
cmake ..
make
sudo make install
(3)配置环境变量
sudo vim /etc/ld.so.conf.d/opencv.conf
在打开的空白文件中添加 /usr/local/lib
执行 sudo ldconfig ,使配置的环境变量生效
(4)配置 .bashrc ,末尾添加下面两行
//打开.bashrc
sudo vim /etc/bash.bashrc
//添加以下两行内容到.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
(5)source 与 update
source /etc/bash.bashrc
sudo updatedb
(6)测试是否正常安装 (成功会出现带 “hello opcv” 字样的窗口)
cd opencv-3.4.5/samples/cpp/example_cmake
cmake .
make
./opencv_example
(1)安装
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install
(2)#安装后 头文件安装在/usr/local/include/eigen3/
(3)#移动头文件
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
备注:在很多程序中 include 时经常使用 #include
安装 运行ORB_SLAM2 (如果在ROS下 推荐工程目录: orbslam_ws/src )
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh
安装Pangolin 依赖项 > sudo apt-get install libpython2.7-dev时出现暂时不能解析域名问题。
错误:1 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libpython2.7-minimal amd64 2.7.18-1~20.04.3
暂时不能解析域名“cn.archive.ubuntu.com”
错误:2 http://security.ubuntu.com/ubuntu focal-updates/universe amd64 libpython2.7-stdlib amd64 2.7.18-1~20.04.3
暂时不能解析域名“cn.archive.ubuntu.com”
访问不了网络。执行命令,重启网关服务:
sudo service network-manager stop //把network-manager停掉(//后的不要复制)
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start //启动
编译时出现了error: ‘usleep’ was not declared in this scope usleep(1000);
^~~~~~
/home/hazyparker/project/ORB_SLAM2/src/System.cc: In member function ‘cv::Mat ORB_SLAM2::System::TrackStereo(const cv::Mat&, const cv::Mat&, const double&)’:
/home/hazyparker/project/ORB_SLAM2/src/System.cc:134:17: error: ‘usleep’ was not declared in this scope
usleep(1000);
^~~~~~
/home/hazyparker/project/ORB_SLAM2/src/System.cc:134:17: note: suggested alternative: ‘fseek’
usleep(1000);
^~~~~~
fseek
/home/hazyparker/project/ORB_SLAM2/src/System.cc: In member function ‘cv::Mat ORB_SLAM2::System::TrackRGBD(const cv::Mat&, const cv::Mat&, const double&)’:
/home/hazyparker/project/ORB_SLAM2/src/System.cc:185:17: error: ‘usleep’ was not declared in this scope
usleep(1000);
^~~~~~
usleep问题:直接在include文件夹下 System.h 文件中加上#include
在LoopClosing.h中将
typedef map
Eigen::aligned_allocator
改为
typedef map
Eigen::aligned_allocator
只需要在对应的System.cc或其他报错的文件路径中(如下)添加#include
ORB_SLAM2/src/LocalMapping.cc
ORB_SLAM2/src/LoopClosing.cc
ORB_SLAM2/src/System.cc
ORB_SLAM2/src/Tracking.cc
ORB_SLAM2/src/Viewer.cc
ORB_SLAM2/Examples/Monocular/mono_euroc.cc
ORB_SLAM2/Examples/Monocular/mono_kitti.cc
ORB_SLAM2/Examples/Monocular/mono_tum.cc
ORB_SLAM2/Examples/RGB-D/rgbd_tum.cc
ORB_SLAM2/Examples/Stereo/stereo_euroc.cc
ORB_SLAM2/Examples/Stereo/stereo_kitti.cc
安装时可能出现 > error: class ‘sigslot::detail::slot_pmf_extended
/usr/local/include/sigslot/signal.hpp:958:11: error: class ‘sigslot::detail::slot_pmf_extended’ does not have any field named ‘pmf’
958 | , pmf{std::forward(f)}
| ^~~
/usr/local/include/sigslot/signal.hpp:959:11: error: class ‘sigslot::detail::slot_pmf_extended’ does not have any field named ‘ptr’
959 | , ptr{std::forward(p)} {}
| ^~~
/usr/local/include/sigslot/signal.hpp:1376:10: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type; did you mean ‘enable_if’?
1376 | std::enable_if_t<(trait::is_callable_v ||
| ^~~~~~~~~~~
| enable_if
/usr/local/include/sigslot/signal.hpp:1399:10: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type; did you mean ‘enable_if’?
1399 | std::enable_if_t &&
| ^~~~~~~~~~~
| enable_if
/usr/local/include/sigslot/signal.hpp: In member function ‘const std::type_info& sigslot::detail::slot_tracked::get_callable_type() const’:
/usr/local/include/sigslot/signal.hpp:1027:23: error: ‘func’ was not declared in this scope; did you mean ‘Func’?
1027 | return typeid(func);
| ^~~~
| Func
仔细研究std后发现,可能是编译过程中调用了某一些库,库里面使用的是c++14的标准语法,但ORB_SLAM2中只有c++11的语法许可,没有14的,这就造成了冲突。
(1)打开ORB_SLAM3/CMakeLists.txt
(2)添加c++14的使用许可 > add_compile_options(-std=c++14)
but it set Pangolin_FOUND to FALSE so package "Pangolin" is considered to
be NOT FOUND. Reason given by package:
Pangolin could not be found because dependency Eigen3 could not be found.
可能由于Pangolin不对应造成,重新安装Pangolin,重新安装前先卸载。
(1)删除库和头文件
cd Pangolin/build
make clean
sudo make uninstall
执行之后就会开始卸载所有的.so文件和.h文件。
(2)删除源代码
cd ../..
sudo rm -r Pangolin
执行之后删除源代码文件夹。
(3)删除残留文件夹
更新下索引,搜索pangolin的位置
sudo updatedb
locate pangolin
可以看到在/usr/local/include/pangolin目录还未删除,因为第一步是卸载了该目录下的所有.h文件。
/usr/local/include/pangolin
/usr/local/include/pangolin/compat
/usr/local/include/pangolin/console
/usr/local/include/pangolin/display
/usr/local/include/pangolin/factory
/usr/local/include/pangolin/geometry
/usr/local/include/pangolin/gl
/usr/local/include/pangolin/handler
/usr/local/include/pangolin/image
/usr/local/include/pangolin/log
所以,我们将该目录删除即可。
sudo rm -r /usr/local/include/pangolin
(4)检查卸载
再次搜索pangolin的位置
locate pangolin
发现只有在Trash中才能找到,卸载成功!
/home/dzh/.local/share/Trash/expunged/2600043745/build/include/pangolin
/home/dzh/.local/share/Trash/expunged/2600043745/build/include/pangolin/factory
/home/dzh/.local/share/Trash/expunged/2600043745/build/include/pangolin/factory/RegisterFactoriesVideoInterface.h
/home/dzh/.local/share/Trash/expunged/2600043745/build/include/pangolin/factory/RegisterFactoriesVideoOutputInterface.h
/home/dzh/.local/share/Trash/expunged/2600043745/build/include/pangolin/factory/RegisterFactoriesWindowInterface.h
(5)重新安装Pangolin库(上文)
在cmakelist .txt中将find_package(Eigen3 3.1.0 REQUIRED)更改为find_package(Eigen3 3.1.0 REQUIRED NO_MODULE)解决了这个问题。
/home/qinlong/Software/ORB_SLAM2/Examples/Monocular/mono_tum.cc:82:22: error: ‘std::chrono::monotonic_clock’ has not been declared
82 | std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
| ^~~~~~~~~~~~~~~
/home/qinlong/Software/ORB_SLAM2/Examples/Monocular/mono_tum.cc:91:22: error: ‘std::chrono::monotonic_clock’ has not been declared
91 | std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
| ^~~~~~~~~~~~~~~
/home/qinlong/Software/ORB_SLAM2/Examples/Monocular/mono_tum.cc:94:83: error: ‘t2’ was not declared in this scope; did you mean ‘tm’?
94 | double ttrack= std::chrono::duration_cast >(t2 - t1).count();
| ^~
| tm
/home/qinlong/Software/ORB_SLAM2/Examples/Monocular/mono_tum.cc:94:88: error: ‘t1’ was not declared in this scope; did you mean ‘y1’?
94 | double ttrack= std::chrono::duration_cast >(t2 - t1).count();
| ^~
| y1
出现这个问题的原因是C++版本之间存在区别。在C++11版里已经没有momotonic_clock了,有steady_clock作为替代。所以orb-slam2的作者在代码中使用了ifdef来判断用户的C++版本。对应路径下的文件需处理的代码段如下。
#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
#endif
//Pass the image to the SLAM system
SLAM.TrackMonocular(im,tframe);
#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
#endif
如果你这部分报错了,大概率你的C++是11版本,那么我们其实可以删掉这部分判断语句,只保留如下部分。
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
//Pass the image to the SLAM system
SLAM.TrackMonocular(im,tframe);
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
//......
这部分就行,把monotonic_clock的代码删掉之后就能正常编译了!