Ubuntu18.04,未安装ros_melodic,opencv版本为4.5.1
若opencv版本不需要更改,则参考另一篇文章快速安装ORB_SLAM3
ORB_SLAM3源码地址https://github.com/UZ-SLAMLab/ORB_SLAM3
前置需求Pangolin,OpenCV,Eigen3,DBoW2 and g2o (Included in Thirdparty folder),Python,ROS (optional)
在 ORB_SLAM3 github 网站中,作者对Pangolin的安装有以下说明:
We use Pangolin for visualization and user interface. Dowload and install instructions can be found at: https://github.com/stevenlovegrove/Pangolin.
按照 Pangolin github网站的指示安装即可。
在 ORB_SLAM3 github 网站中,作者对Eigen3的安装有以下说明:
Required by g2o (see below). Download and install instructions can be found at: http://eigen.tuxfamily.org. Required at least 3.1.0.
按照网站右侧提示下载,下载后解压,找到INSTALL文件并根据提示进行安装。
Let’s call this directory ‘source_dir’ (where this INSTALL file is).
Before starting, create another directory which we will call ‘build_dir’.
Do:
cd build_dir
cmake source_dir
make install
简化版本为:
tar -zxvf eien-3.3.9.tar.gz
cd eigen-3.3.9
mkdir build
cmake ..
sudo make install
在 ORB_SLAM3 github 网站中,作者对DBoW2 and g2o的安装有以下说明:
We use modified versions of the DBoW2 library to perform place recognition and g2o library to perform non-linear optimizations. Both modified libraries (which are BSD) are included in the Thirdparty folder.
在下载的ORB_SLAM3源码中包含了 DBoW2 and g2o 两个库,并且在./build.sh文件中包含了对这两个库的编译的脚本。
在 ORB_SLAM3 github 网站中,作者对opencv的安装有以下说明:
We use OpenCV to manipulate images and features. Dowload and install instructions can be found at: http://opencv.org. Required at leat 3.0. Tested with OpenCV 3.2.0.
作者使用的为opencv3.2.0,但是我在使用opencv3.2.0编译时会出现一些问题,故安装了opencv4.5.1版本。以下为一些安装建议。
从 https://github.com/opencv/opencv/releases找到opencv4.5.1版本,下载源码并解压。
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html.按照教程安装,化简后的步骤如下:
cd opencv-4.5.1
mkdir build
cd build
cmake ..
sudo make install
默认安装地址为/usr/local,若需要改变安装地址,则需要将cmake内条语句改为。
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/opencv_4.5.1 ..
若需要多核编译,则需要把make内条语句改为:(在电脑配置不好的情况下可能会死机,j后面加上数字可以指定几个线程编译)
make install -j
更多配置信息可参考https://docs.opencv.org/master/db/d05/tutorial_config_reference.html。
在其他地址安装完opencv4.5.1之后需要更改系统路径,防止在程序运行时出现寻找不到链接库的错误。
libopencv_imgproc.so.4.5: cannot open shared object file: No such file or directory
问题解决方法参考
https://blog.csdn.net/innocent_sheld/article/details/80509651
https://blog.csdn.net/jay463261929/article/details/53860593
https://blog.csdn.net/BeeGreen/article/details/104397348
在安装完前置要求之后,开始ORB_SLAM3的编译。从https://github.com/UZ-SLAMLab/ORB_SLAM3下载源码。运行目录下的build.sh文件。
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git
cd ORB_SLAM3
chmod +x ./build.sh
./build.sh
由于安装的是opencv4.5.1,需要更改根目录下的 CMakeLists.txt 以便 cmake 编译器找到opencv的库文件。
//36行至42行
find_package(OpenCV 4.0)
if(NOT OpenCV_FOUND)
find_package(OpenCV 3.0)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV > 3.0 not found.")
endif()
endif()
//改为
find_package(OpenCV 4.0)
在 ORB_SLAM3 github 网站中,作者对opencv的安装有以下说明:
EuRoC dataset was recorded with two pinhole cameras and an inertial sensor. We provide an example script to launch EuRoC sequences in all the sensor configurations.
Download a sequence (ASL format) from http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets
Open the script “euroc_examples.sh” in the root of the project. Change pathDatasetEuroc variable to point to the directory where the dataset has been uncompressed.
从http://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets下载ASL Dataset Format数据集,并把数据集解压到名为MH01的文件夹内。再将euroc_examples.sh中数据集的地址更改为解压后数据集的绝对地址。
cd ~
wget http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_01_easy/MH_01_easy.zip
unzip MH_01_easy.zip
mv -rf ./mav0 ~/datasets/MH01
将euroc_examples.sh的第二行进行修改:
pathDatasetEuroc='/home/s/datasets' #Example, it is necesary to change it by the dataset path
运行exampls目录下的euroc_examples.sh即可看到ORB_SLAM3的输出。
roswiki中有详细的安装步骤http://wiki.ros.org/melodic/Installation/Ubuntu
其中有几点需要注意:
详细安装方法参考
https://zhuanlan.zhihu.com/p/347455336
https://blog.csdn.net/wakingking88/article/details/104648636
由于ROS_melodic自带opencv版本为3,故需要重新编译cv_bridge才能使得ros与opencv4.5.1兼容。
对于已经安装好 ros-melodic-desktop-full 的计算机,在执行sudo apt remove ros-melodic-cv-bridge时会导致卸载掉额外的软件包,这是我们不希望看到的。
故我们不选则执行sudo apt remove ros-melodic-cv-bridge,而是在编译好cv_bridge软件包之后需要人工把/opt/ros/melodic文件夹下的各个库文件替换掉。以下为详细步骤:
git clone https://github.com/ros-perception/vision_opencv.git
//开辟工作空间
cd ~
mkdir -p catkin_ws/src
cd catkin_ws
catkin_make
//将代码放入工作空间内
cd ~/catkin_make/src
git clone https://github.com/ros-perception/vision_opencv.git
//由于我使用的ubuntu版本只能使用boost库1.6.5版本,python_boost库版本为3.6,故注释掉以下部分
if(NOT ANDROID)
find_package(PythonLibs)
# if(PYTHONLIBS_VERSION_STRING VERSION_LESS "3.8")
# Debian Buster
# find_package(Boost REQUIRED python37)
# else()
# Ubuntu Focal
find_package(Boost REQUIRED python)
# endif()
#else()
find_package(Boost REQUIRED)
endif()
//由于使用的是opencv4.5.1,故注释掉以下部分
set(_opencv_version 4)
find_package(OpenCV 4 QUIET)
#if(NOT OpenCV_FOUND)
# message(STATUS “Did not find OpenCV 4, trying OpenCV 3”)
# set(_opencv_version 3)
#endif()
//将最后一段(36~40)行改为
static void do_numpy_import( )
{
import_array( );
}
//传统编译方式
cd ~/catkin_ws/src/vision_opencv/cv_bridge
mkdir build
cd build
cmake ..
make
sudo make install
//ros特有编译方式
cd ~/catkin_ws
catkin_make
sudo rm -rf /opt/ros/melodic/include/cv_bridge
sudo rm -rf /opt/ros/melodic/share/cv_bridge
sudo rm -rf /opt/ros/melodic/lib/cv_bridge
sudo cp -rf /usr/local/include/cv_bridge /opt/ros/melodic/include/cv_bridge
sudo cp -rf /usr/local/share/cv_bridge /opt/ros/melodic/share/cv_bridge
sudo cp -rf /usr/local/lib/python2.7/dist-packages/cv_bridge /opt/ros/melodic/lib/cv_bridge
//打开bash环境配置文件
gedit ~/.bashrc
//在文件最下方插入下面这句话(其中PATH改为真实绝对路径)
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples/ROS
//修改第33到39行代码,由于使用的是opencv4.5.1,故注释掉以下部分
find_package(OpenCV 4.0 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()
//修改第62行中的rostopic话题名称为/cam0/image_raw,与数据集中topic话题名称统一
ros::Subscriber sub = nodeHandler.subscribe("/cam0/image_raw", 1, &ImageGrabber::GrabImage,&igb);
cd ~/git/ORB_SLAM3/Examples/ROS/ORB_SLAM3
mkdir build
cd build
cmake ..
make
cd ~
wget http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_01_easy/MH_01_easy.bag
//终端1
roscore
//终端2
rosbag play ~/MH_01_easy.bag
//终端3
rosrun ORB_SLAM3 Mono /home/s/git/ORB_SLAM3/Vocabulary/ORBvoc.txt /home/s/git/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Asus.yaml
CMake Error at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1947 (message):
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_python37
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
vision_opencv/cv_bridge/CMakeLists.txt:11 (find_package)
解决方法:参考cv_bridge的安装的第三步
[ 66%] Building CXX object src/CMakeFiles/cv_bridge_boost.dir/module.cpp.o
In file included from /usr/include/python2.7/numpy/ndarrayobject.h:27:0,
from /home/nano/catkin_ws/src/cv_bridge/src/module.hpp:26,
from /home/nano/catkin_ws/src/cv_bridge/src/module.cpp:35:
/home/nano/catkin_ws/src/cv_bridge/src/module.hpp: In function ‘int do_numpy_import()’:
/usr/include/python2.7/numpy/__multiarray_api.h:1537:144: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
efine import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
^
/usr/include/python2.7/numpy/__multiarray_api.h:1537:144: note: in definition of macro ‘import_array’
efine import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }
^~~~~~
src/CMakeFiles/cv_bridge_boost.dir/build.make:62: recipe for target 'src/CMakeFiles/cv_bridge_boost.dir/module.cpp.o' failed
make[2]: *** [src/CMakeFiles/cv_bridge_boost.dir/module.cpp.o] Error 1
CMakeFiles/Makefile2:930: recipe for target 'src/CMakeFiles/cv_bridge_boost.dir/all' failed
make[1]: *** [src/CMakeFiles/cv_bridge_boost.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
解决方法:参考cv_bridge的安装的第四步
Failed to load image at: /Datasets/MH01/mav0/cam0/data/1403636579763555584.png
./euroc_examples.sh: 行 7: 21285 段错误 (核心已转储)
解决方法:数据集地址出现错误,修改数据集地址即可
usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /opt/ros/melodic/lib/libcv_bridge.so, may conflict with libopencv_imgcodecs.so.4.5
解决方法:重新安装cv_bridge并重新编译ROS软件包,参考cv_bridge的安装与ROS软件包的编译
ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.
Input sensor was set to: Monocular
段错误 (核心已转储)
解决方法:运行命令出错,重新检查命令
参考https://blog.csdn.net/qq_33591712/article/details/82918981
ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.
Input sensor was set to: Monocular
Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!
Creation of new map with id: 0
Creation of new map with last KF id: 0
OpenCV Error: Bad argument (Invalid pointer to file storage) in cvGetFileNodeByName, file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/persistence.cpp, line 863
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/core/src/persistence.cpp:863: error: (-5) Invalid pointer to file storage in function cvGetFileNodeByName
已放弃 (核心已转储)
解决方法:重新安装cv_bridge并重新编译ROS软件包,参考cv_bridge的安装与ROS软件包的编译
libopencv_imgproc.so.4.5: cannot open shared object file: No such file or directory
解决方法:opencv地址没有添加到系统路径中,导致程序运行时刻找不到opencv库文件。需要将opencv安装路径设定在默认路径下或者更改系统路径,参考OPENCV的下载与编译。