Directory
1 Installation tutorial (refer to online course materials for this tutorial)
1.1 Preparation before installation
1.2 Install Pangolin (source code installation recommended)
1.3 Install OpenCV3.4 (source code installation recommended)
1.4 Install Eigen3.3.7 (source code installation recommended)
1.5 Installing and running ORB-SLAM2 and solutions to common problems
2 Installation problems and solutions
This article is a summary of the problems the author encountered during the installation of ORB-SLAM2. During the installation process, he encountered many problems. He referred to many blogs. Due to the large number of reference articles, only some links are given. Thank you to the bloggers who referenced the articles. .
1 Installation tutorial (refer to online course materials for this tutorial)
Install ORB-SLAM2, Pangolin, OpenCV, Eigen, g2o and DBoW2 on the newly installed Ubuntu system (ORB-SLAM2 comes with it)
1.1 Preparation before installation
Preparation before installation: Install vim, cmake, git, gcc, g++
sudo apt-get install vim cmake
sudo apt-get install git
sudo apt-get install gcc g++
1.2 Install Pangolin (source code installation recommended)
(1) Install dependencies
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)Installed Pangolin
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake -DCPP11_NO_BOOSR=1 ..
make -j
1.3 Install OpenCV3.4 (source code installation recommended)
(1) Install dependencies
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) To install OpenCV3.4,
enter the downloaded installation compressed package, unzip it to a folder, and then go into the folder to create a build folder and compile the folder
cd opencv-3.4.5
mkdir build
cd build
cmake ..
make
sudo make install
(3) Configure environment variables
sudo vim /etc/ld.so.conf.d/opencv.conf
Add /usr/local/lib to the opened blank file and
execute sudo ldconfig to make the configured environment variables take effect
(4) Configure .bashrc, add the following two lines at the end
//Open .bashrc
sudo vim /etc/bash.bashrc
//Add the following two lines to .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) Test whether the installation is normal (if successful, a window with "hello opcv" will appear)
cd opencv-3.4.5/samples/cpp/example_cmake
cmake .
make
./opencv_example
1.4 Install Eigen3.3.7 (source code installation recommended)
(1)安装
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install
(2) #After installation, the header files are installed in /usr/local/include/eigen3/
(3) #Move the header file
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
Note: #include <Eigen/Dense> is often used when including in many programs instead of #include < eigen3/Eigen/Dense> So we need to do the following processing
1.5 Installing and running ORB-SLAM2 and solutions to common problems
Install and run ORB_SLAM2 (recommended project directory if under ROS: orbslam_ws/src)
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh
2 Installation problems and solutions
Question 1
When installing Pangolin dependencies > sudo apt-get install libpython2.7-dev, there is a problem that the domain name cannot be resolved temporarily.
错误: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”
Solution
Can't access the network. Execute the command to restart the gateway service:
sudo service network-manager stop //把network-manager停掉(//后的不要复制)
sudo rm /var/lib/NetworkManager/NetworkManager.state
sudo service network-manager start //启动
Question 2
An error occurred during compilation: '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);
^~~~~~
Solution (1)
usleep problem: directly add #include <unistd.h> to the System.h file in the include folder
In LoopClosing.h will
typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;
改为
typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
Eigen::aligned_allocator<std::pair<KeyFrame *const, g2o::Sim3> > > KeyFrameAndPose;
Solution(2)
Just add #include <unistd.h> to the corresponding System.cc or other error file paths (as shown below)
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
Question 3
During installation > error: class 'sigslot::detail::slot_pmf_extended<Pmf, Ptr, Args>' does not have any field named 'ptr' due to version mismatch.
/usr/local/include/sigslot/signal.hpp:958:11: error: class ‘sigslot::detail::slot_pmf_extended<Pmf, Ptr, Args>’ does not have any field named ‘pmf’
958 | , pmf{std::forward<F>(f)}
| ^~~
/usr/local/include/sigslot/signal.hpp:959:11: error: class ‘sigslot::detail::slot_pmf_extended<Pmf, Ptr, Args>’ does not have any field named ‘ptr’
959 | , ptr{std::forward<P>(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<arg_list, Callable> ||
| ^~~~~~~~~~~
| 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<!trait::is_callable_v<arg_list, Obj> &&
| ^~~~~~~~~~~
| enable_if
/usr/local/include/sigslot/signal.hpp: In member function ‘const std::type_info& sigslot::detail::slot_tracked<Func, WeakPtr, Args>::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
Solution ( reference article )
After careful study of std, I found that some libraries may be called during the compilation process. The libraries use the standard syntax of c++14, but ORB_SLAM2 only has the syntax permission of c++11 and not 14. This caused conflict.
(1) Open ORB_SLAM3/CMakeLists.txt
(2) Add c++14 license > add_compile_options(-std=c++14)
Question 4
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.
Solution (1)
It may be caused by Pangolin not supporting it. Reinstall Pangolin and uninstall it before reinstalling.
(1) Delete libraries and header files
cd Pangolin/build
make clean
sudo make uninstall
After execution, all .so files and .h files will begin to be uninstalled.
(2) Delete source code
cd ../..
sudo rm -r Pangolin
Delete the source code folder after execution.
(3) Delete residual folders
Update the index and search for the location of pangolin
sudo updatedb
locate pangolin
You can see that the /usr/local/include/pangolin directory has not been deleted, because the first step is to uninstall all .h files in this directory.
/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
Therefore, we can delete this directory.
sudo rm -r /usr/local/include/pangolin
(4) Check for uninstallation
Search the location of pangolin again
locate pangolin
I found that it can only be found in Trash, and the uninstallation was successful!
/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) Reinstall the Pangolin library (above)
Solution(2)
Changing find_package(Eigen3 3.1.0 REQUIRED) to find_package(Eigen3 3.1.0 REQUIRED NO_MODULE) in cmakelist .txt solved the problem.
Question 5
/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<std::chrono::duration<double> >(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<std::chrono::duration<double> >(t2 - t1).count();
| ^~
| y1
Solution ( reference article )
The problem occurs because there are differences between C++ versions. Momotonic_clock is no longer available in C++11, and is replaced by steady_clock. So the author of orb-slam2 used ifdef in the code to determine the user's C++ version. The code segment that needs to be processed for the files under the corresponding path is as follows.
#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
If you report an error in this part, there is a high probability that your C++ is version 11, then we can actually delete this part of the judgment statement and only keep the following part.
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();
//......
This part is enough. After deleting the monotonic_clock code, it will compile normally!
Question 6:
/usr/bin/ld: cannot find -lEigen3::Eigen
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/joinMap.dir/build.make:102: joinMap] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/joinMap.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Solution ( reference article )
The Eigen library is different from ordinary libraries. It only has header files and does not have binary library files like .so and .a. Where does libEigen.so come from? You need -l?
Added in CMakeLists.txt
#Add the red statement
find_package(Eigen3 3.3 REQUIRED NO_MODULE )
#When compiling an error, add the following statement
include(FindEigen3.cmake)