《视觉SLAM 十四讲:从理论到实践》第二版,Ubuntu20.04系统中视觉SLAM各种库的安装

发布时间:2023-10-30 17:00

Ubuntu20.04系统中视觉SLAM各种库的安装

——《视觉SLAM十四讲:从理论到实践》第二版

对于某些cmake工程,使用cmake-make方式进行编译安装,先建立build文件夹,再使用 cmake .. 对安装包进行分析,当找不到合适的安装教程类帮助时,可以根据分析的结果,看看缺少那些依赖,就装哪些,一直到没有缺少,或根据需要安装相应依赖,可能有些依赖库是非必要的,注意cmake时有的可能需要设置某些参数或root权限,接着make编译与make install安装。

mkdir build -> cd build -> cmake .. -> make -> sudo make install

CMake 指定安装目录,

方法一:使用 CMAKE_INSTALL_PREFIX 来指定 cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..

方法二:修改cmake文件,加入:SET(CMAKE_INSTALL_PREFIX < install_path >)  ,要加在 PROJECT(< project_name>)

1.Eigen3安装

Ubuntu20.04系统中,直接在终端输入以下命令即可安装Eigen最新版本(模板类Sophus要求Eigen3.3以上,笔者使用该命令安装的Eigen的版本是3.3.7-2,其它Ubuntu版本的系统,也可参考博客:视觉SLAM学习中各种库安装,通过在Eigen官网下载源码,使用cmake安装Eigen最新版。

sudo apt-get install libeigen3-dev

2.Sophus安装

Sophus,李代数库,由Strasdat维护,可通过以下命令从Github获取源码,默认是模板类,可直接通过cmake方式进行安装。

git clone http://github.com/strasdat/Sophus
cd Sophus
mkdir build
cd build
cmake ..
make
suod make install

在《视觉SLAM十四讲:从理论到实践》第一版中,使用的是非模板类Sophus,需在Sophus目录下使用以下命令回到非模板类Sophus的版本,再通过cmake方式安装。

git checkout a621ff

3.OpenCV3

OpenCV中文官方文档

首先在终端运行以下命令,安装OpenCV库的依赖项。其中前两条命令用于添加编码工具jasper( libjasper-dev)的软件源。

sudo add-apt-repository \"deb http://security.ubuntu.com/ubuntu xenial-security main\"

sudo apt update

sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev  libgphoto2-dev libopenblas-base libopenblas-dev doxygen  openjdk-8-jdk pylint libvtk6-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libopenexr-dev 

然后从官网或Github下载OpenCV3系列安装包编译安装,(在Github下载对应版本的opencv_contrib扩展模块,笔者在Github上下载的opencv3.4.11和对应版本的opencv_contrib),分别进行解压,注意需要将opencv_contrib-3.4.11移动到opencv-3.4.11文件夹,在终端打开opencv-3.4.11q文件夹,通过cmake方式安装OpenCV。其中cmake命令的OPENCV_EXTRA_MODULES_PATH参数是opencv_contrib扩展模块的modules目录。

mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 -D OPENCV_EXTRA_MODULES_PATH=/home/xvshilin/opencv-3.4.11/opencv_contrib-3.4.11/modules/ ..
sudo make -j4
sudo make install


sudo gedit ~/.bashrc

//切换成 opencv3,根据安装路径,在文件末尾加上:
export PKG_CONFIG_PATH=/usr/local/opencv3/lib/pkgconfig  
export LD_LIBRARY_PATH=/usr/local/opencv3/lib

//切换成 opencv2,则在文件末尾加上:
export PKG_CONFIG_PATH=/usr/local/opencv2/lib/pkgconfig  
export LD_LIBRARY_PATH=/usr/local/opencv2/lib

// 也可参考下面 DBoW3 的 CMakeLists.txt 配置,使用cmake语句 set()
set(OpenCV_DIR /usr/local/opencv2/share/OpenCV)
find_package(OpenCV 2.4 REQUIRED)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS} /usr/local/opencv2/include)

source ~/.bashrc // 使(在当前终端)即使生效

pkg-config –modversion opencv
pkg-config –cflags opencv
pkg-config –libs opencv 

 

OpenCV2的安装,从官网下载源码,安装依赖项

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

建立文件夹/usr/local/opencv2

cmake三连

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2 ..
make
sudo make install

make编译时出现以下错误时,参考这篇博客,由ffmpeg的版本问题引起。在最新版本的ffmpeg中对很多关键字进行了重命名,例如CODEC_FLAG_GLOBAL_HEADER就被重新命名为AV_CODEC_FLAG_GLOBAL_HEADER,因此以老版本ffmpeg开发的opencv无法编译。解决方法,装旧版本的ffmpeg或者修改opencv的源码。

In file included from /home/***/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg.cpp:45:
/home/***/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, AVCodecID, int, int, int, double, int)’:
/home/***/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg_impl.hpp:1484:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope; did you mean ‘AV_CODEC_FLAG_GLOBAL_HEADER’?
 1484 |         c->flags |= CODEC_FLAG_GLOBAL_HEADER;
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~
      |                     AV_CODEC_FLAG_GLOBAL_HEADER

解决方法是打开/opencv-2.4.13.6/modules/highgui/src/cap_ffmpeg_impl.hpp,在里最顶端添加

#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

顺利编译。

4.PCL点云库

https://github.com/PointCloudLibrary/pcl

5.Ceres优化库

http://ceres-solver.org/installation.html

源码下载

git clone https://github.com/ceres-solver/ceres-solver

依赖

sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev libgoogle-glog-dev libgtest-dev

出现无法定位libcxsoarse3.1.2问题的解决方法:

sudo gedit /etc/apt/sources.list

将下面的源加入到sources.list

deb http://cz.archive.ubuntu.com/ubuntu trusty main universe

sudo apt-get update
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev libgoogle-glog-dev libgtest-dev

之后就是mkdir build -> cd build -> cmake .. -> make -> sudo make install ,安装之前可以使用 make test 进行测试,即

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ceres ..
nproc (查看cpu核心数,???)
make 
make test
sudo make install

6.g2o图优化库

sudo apt-get install qt5-qmake libqglviewer-dev-qt5 libsuitesparse-dev libcxsparse3.1.2 libcholmod-dev

git clone https://github.com/RainerKuemmerle/g2o.git
cd git
mkdir build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/g2o ..
make
sudo make install

7.DBoW3词袋模型库

词袋模型 DBoW2 DBoW3 FBoW Vocabulary_of_GSLAM

git clone https://github.com/rmsalinas/DBow3.git # 下载源文件
cd DBoW3 # 进入源文件夹
mkdir build
cd build
cmake -DUSE_CONTRIB=ON -DCMAKE_INSTALL_PREFIX=/usr/local/DBow3..
make -j4
sudo make install 			

 使用DBoW3时,CMakeLists.txt的配置,头文件+库文件+链接

set( DBoW3_INCLUDE_DIRS \"/usr/local/DBoW3/include\" )
set( DBoW3_LIBS \"/usr/local/DBoW3/lib/libDBoW3.so\" )
target_link_libraries( 可执行文件名 ${DBoW3_LIBS} )

8.Pangolin

 https://github.com/stevenlovegrove/Pangolin

9.GTSAM

安装失败,待定

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.

GTSAM 是一个在机器人领域和计算机视觉领域用于平滑(smoothing)和建图(mapping)的C++类库。下载地址:http://borg.cc.gatech.edu/download.html

官方网站:
[1] Eigen官方主页:http://eigen.tuxfamily.org/index.php?title=Main_Page

[2] Sophus in github:http://github.com/strasdat/Sophus

[3] OpenCV官网:http://opencv.org

[4] PCL官网:http://pointclouds.org

[5] Ceres官网:http://ceres-solver.org

[6] Ceres in github:https://github.com/ceres-solver/ceres-solver

[7] G2O in github:https://github.com/RainerKuemmerle/g2o

[8] GTSAM :http://borg.cc.gatech.edu/?destination=node%2F299

 

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号