目录
0.1 对动态场景的跟踪
一、准备工作
1.1环境准备
二、ORB-SLAM2的编译
2.1 安装高版本的CMake
2.2 安装Eigen
2.3 安装Pangolin0.5版本(版本一定要选这个 0.6编译ORBSLAM2会拉闸)
2.3.1 依赖安装
2.3.2 下载 Pangolin0.5版本
2.3.3 安装
2.4 安装opencv 2.4.11
2.4.1 安装依赖
2.4.2 安装opencv ---Configuration Debug
到opencv的根目录执行如下代码:会出现下列错误
2.4.3 安装opencv ---Configuration Debug1
2.4.4 安装opencv ---Make Debug
2.4.5 安装opencv ---Make Debug
2.4.6 安装opencv ---Make Debug
2.4.7 安装opencv到系统
2.4.8 配置opencv
2.5 编译ORB-SLAM2
2.5.0 下载ORB-SLAM2源码命令
2.5.1 给予build.sh可执行权限
2.5.2 Dubug (error: ‘usleep’ was not declared in this scope)
2.5.3 重新编译,第一阶段完结撒花
三、DynaSLAM的编译
3.1 下载DynaSLAM包
3.2 下载coco数据集
3.3 下载mask_rcnn_coco.h5
3.4 下载tensorflow1.12.3压缩包
在这个链接下载
3.5 下载pip(python2.x)
3.6 安装tensorflow
3.7 安装与tensorflow1.12.3对应版本的Keras2.0.9
3.8 安装必备包
3.9 用Anaconda配置Python相关的环境
3.9.1 下载Anaconda安装包
3.9.2 安装 Anaconda
3.9.3 用Anaconda配置Python相关的环境
3.9.4 在conda外面做的一些操作
3.10 编译DynaSLAM
3.10.1 注释掉DynaSLAM根目录的carla行
3.10.2 注释掉根目录、g2o库、DBow2库的-match native去掉
3.10.3 编译Dynaslam
四、运行ORB-SLAM2与DynaSLAM
4.1 运行ORB-SLAM2
4.1.1 下载数据集
数据集点我下载
4.1.2 数据集处理
4.1.3 运行脚本关联RGB 图像和深度图像
4.1.4 运行查看结果
4.2 运行DynaSLAM
4.2.1 下载数据集
4.2.2 数据集处理
4.2.3 运行查看结果
一、装好的VMWare虚拟机 / 双系统:如果不会装双系统,请参阅我这篇博客:
win乌班图双系统安装(win11、Ubuntu20.04)及安装后的环境、软件配置_Courage2022的博客-CSDN博客_乌班图系统
二、安装好的Ubuntu 18.04.5系统
由于系统自带的cmake版本过低,导致有些库不满足cmake的minmum_requried,因此在安装库之前我们要升级以下cmake版本。
这里我推荐版本为CMake的3.21.3版本。
赋予这个脚本可执行权限,将解压出来的包移到 /opt 目录下,并建立软链接。
chmod +x cmake-3.21.3.linux-x86_64.sh ./cmake-3.21.3.linux-x86_64.sh sudo mv cmake-3.21.3-Linux-x86_64 /opt/cmake-3.21.3 sudo ln -sf /opt/cmake-3.21.3/bin/* /usr/bin/
执行脚本如下:
测试安装:
cmake --version
安装成功.
如果之前装过老版本的CMake,千万不要用下面一行代码去卸载,原因是卸载掉老版本的CMake会使所有依赖CMake编译的库拉闸!
sudo apt-get autoremove cmake
cmake安装成功之后,不要忘记将cmake的文件路径添加至 .bashrc里面:
# 进入~/.bashrc sudo gedit ~/.bashrc # 输入以下内容 export PATH=$PATH:/opt/cmake-3.21.3/bin
保存 .bashrc的更改和更新source一下:
source ~/.bashrc
用命令安装即可:
sudo apt-get install libeigen3-dev
更改安装位置以能被CMake发现:(特别重要)
cd /usr/include/eigen3 sudo cp Eigen/ .. -R
sudo apt-get install libglew-dev sudo apt-get install libboost-dev libboost-thread-dev sudo apt-get install libboost-filesystem-dev sudo apt-get install libpython2.7-dev sudo apt-get install build-essential
GitHub - stevenlovegrove/Pangolin: Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input.下载zip压缩包解压(v0.5版本)
我推荐把所有包放到/home目录下:
执行:
cd Pangolin mkdir build cd build cmake -DCPP11_NO_BOOSR=1 .. make sudo make install
一定要选这个版本,否则DynaSLAM编译不通过...............
sudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev sudo apt-get install qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev sudo apt-get install pkg-config
sudo apt-get install libjasper-dev
最后安装libjasper-dev的时候,会遇到找不到包的情况:执行下列代码
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" sudo apt update sudo apt install libjasper1 libjasper-dev
完美解决。
到opencv的根目录执行如下代码:会出现下列错误
mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.11 -DENABLE_PRECOMPILED_HEADERS=OFF -D WITH_FFMPEG=OFF ..
解决:将
OpenCVDetectCXXCompiler.cmake
的内容替换为如下:# ---------------------------------------------------------------------------- # Detect Microsoft compiler: # ---------------------------------------------------------------------------- if(CMAKE_CL_64) set(MSVC64 1) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_GNUCXX 1) set(CMAKE_COMPILER_IS_CLANGCXX 1) endif() if(CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_COMPILER_IS_GNUCC 1) set(CMAKE_COMPILER_IS_CLANGCC 1) endif() if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache") set(CMAKE_COMPILER_IS_CCACHE 1) endif() # ---------------------------------------------------------------------------- # Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ): # see include/opencv/cxtypes.h file for related ICC & CV_ICC defines. # NOTE: The system needs to determine if the '-fPIC' option needs to be added # for the 3rdparty static libs being compiled. The CMakeLists.txt files # in 3rdparty use the CV_ICC definition being set here to determine if # the -fPIC flag should be used. # ---------------------------------------------------------------------------- if(UNIX) if (__ICL) set(CV_ICC __ICL) elseif(__ICC) set(CV_ICC __ICC) elseif(__ECL) set(CV_ICC __ECL) elseif(__ECC) set(CV_ICC __ECC) elseif(__INTEL_COMPILER) set(CV_ICC __INTEL_COMPILER) elseif(CMAKE_C_COMPILER MATCHES "icc") set(CV_ICC icc_matches_c_compiler) endif() endif() if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl") set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) endif() # ---------------------------------------------------------------------------- # Detect GNU version: # ---------------------------------------------------------------------------- if(CMAKE_COMPILER_IS_CLANGCXX) set(CMAKE_GCC_REGEX_VERSION "4.2.1") set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4) set(CMAKE_OPENCV_GCC_VERSION_MINOR 2) set(CMAKE_OPENCV_GCC_VERSION 42) set(CMAKE_OPENCV_GCC_VERSION_NUM 402) execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL ERROR_STRIP_TRAILING_WHITESPACE) string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}") string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}") elseif(CMAKE_COMPILER_IS_GNUCXX) execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL OUTPUT_STRIP_TRAILING_WHITESPACE) # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)" # Look for the version number, major.minor.build string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}") if(NOT CMAKE_GCC_REGEX_VERSION)#major.minor string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}") endif() if(CMAKE_GCC_REGEX_VERSION) # Split the parts: string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}") list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR) list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR) else()#compiler returned just the major version number string(REGEX MATCH "[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}") if(NOT CMAKE_GCC_REGEX_VERSION)#compiler did not return anything reasonable set(CMAKE_GCC_REGEX_VERSION "0") message(WARNING "GCC version not detected!") endif() set(CMAKE_OPENCV_GCC_VERSION_MAJOR ${CMAKE_GCC_REGEX_VERSION}) set(CMAKE_OPENCV_GCC_VERSION_MINOR 0) endif() set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR}) math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}") message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})") if(WIN32) execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE OUTPUT_STRIP_TRAILING_WHITESPACE) if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64") set(MINGW64 1) endif() endif() endif() if(MSVC64 OR MINGW64) set(X86_64 1) elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING)) set(X86 1) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*") set(X86_64 1) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*") set(X86 1) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)") set(ARM 1) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)") set(AARCH64 1) endif() # Workaround for 32-bit operating systems on 64-bit x86_64 processor if(X86_64 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64) message(STATUS "sizeof(void) = 4 on x86 / x86_64 processor. Assume 32-bit compilation mode (X86=1)") unset(X86_64) set(X86 1) endif() # Similar code exists in OpenCVConfig.cmake if(NOT DEFINED OpenCV_STATIC) # look for global setting if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS) set(OpenCV_STATIC OFF) else() set(OpenCV_STATIC ON) endif() endif() if(MSVC) if(CMAKE_CL_64) set(OpenCV_ARCH x64) elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm")) # see Modules/CmakeGenericSystem.cmake set(OpenCV_ARCH ARM) else() set(OpenCV_ARCH x86) endif() if(MSVC_VERSION EQUAL 1400) set(OpenCV_RUNTIME vc8) elseif(MSVC_VERSION EQUAL 1500) set(OpenCV_RUNTIME vc9) elseif(MSVC_VERSION EQUAL 1600) set(OpenCV_RUNTIME vc10) elseif(MSVC_VERSION EQUAL 1700) set(OpenCV_RUNTIME vc11) elseif(MSVC_VERSION EQUAL 1800) set(OpenCV_RUNTIME vc12) elseif(MSVC_VERSION EQUAL 1900) set(OpenCV_RUNTIME vc14) elseif(MSVC_VERSION EQUAL 1910) set(OpenCV_RUNTIME vc15) endif() elseif(MINGW) set(OpenCV_RUNTIME mingw) if(MINGW64) set(OpenCV_ARCH x64) else() set(OpenCV_ARCH x86) endif() endif()
再次运行:配置成功
make -j16
报错1:编译到94%时报错,错误在91%下, error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
解决方案:假设opencv中生成的临时编译文件为build,则在文件中找到
./build/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make,删除第四行中的-Werror=address。
解决!
make -j16
报错2:rgbdodometry.cpp:65:12: fatal error: unsupported/Eigen/MatrixFunctions: 没有那个文件或目录
解决方案:在rgbdodometry.cpp的65行加上eigen3
#include
//或者 #include 再次执行,成功编译opencv
编译到14%时一长串的错误,全都是一个类型:error: ‘CODEC_ID_H264’ was not declared in this scope
{ CODEC_ID_H264, MKTAG(‘H’, ‘2’, ‘6’, ‘4’) }还有这种错误 ``error: ‘PIX_FMT_YUV444P’ was not declared in this scope;
解决方案:cmake直接关闭ffmpeg,在cmake命令后面加上
-D WITH_FFMPEG=OFF
编译到12%时报错 fatal error: stdlib.h: 没有那个文件或目录,可能要往上翻一翻找到红字error的部分。
解决方案:cmake的时候在命令后面加上
-DENABLE_PRECOMPILED_HEADERS=OFF
bug全部处理完毕,在build目录安装opencv到系统路径
sudo make install
sudo gedit ~/.bashrc //在文件末尾加上下面两行: #export PKG_CONFIG_PATH="/usr/local/opencv2.4.11/lib/pkgconfig:$PKG_CONFIG_PATH" #export LD_LIBRARY_PATH="/usr/local/opencv2.4.11/lib:$LD_LIBRARY_PATH" //保存之后 //更新环境 source ~/.bashrc //查看opencv的版本 pkg-config --modversion opencv
出现这个就表明安装成功了。
git clone https://github.com/raulmur/ORB_SLAM2.git
sudo chmod 777 build.sh
执行:
./build.sh
解决方式:在
ORB_SLAM2/include/System.h
中添加一句#include "unistd.h"
git clone https://github.com/BertaBescos/DynaSLAM.git
git clone https://github.com/waleedka/coco.git
Releases · matterport/Mask_RCNN (github.com)
在这个链接下载
sudo apt install python-pip
把下载的tensorflow压缩包放到主目录下,终端输入如下命令来安装(否则找不到文件)
sudo pip install tensorflow-1.12.3-cp27-cp27mu-manylinux1_x86_64.whl
报错:
解决办法:
python -m pip install --upgrade pip
下载的很慢,等了半个小时....成功!
sudo pip install keras==2.0.9 -i https://pypi.tuna.tsinghua.edu.cn/simple
sudo apt-get install libboost-all-dev pip install Cython -i https://pypi.tuna.tsinghua.edu.cn/simple/ pip install fasttext -i https://pypi.tuna.tsinghua.edu.cn/simple/ sudo pip install scikit-image sudo apt install python-tk sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev sudo apt-get install libboost-all-dev sudo apt-get install qtbase5-dev pip install pycocotools
点我下载
bash ./Anaconda3-2021.11-Linux-x86_64.sh
yes
初始化Anaconda:
执行完
上一步
Anaconda在Ubuntu系统里面的安装基本完毕了,但是还需要最后一步 初始化Anaconda,这一步只需要根据提示输入yes
即可,界面如下:
如果您希望 conda 的基础环境在启动时不被激活,请将 auto_activate_base 参数设置为 false
,命令如下:conda config --set auto_activate_base false
当然这一条命令执行完毕后,想要再次进入conda的base环境,只需要使用对应的conda指令即可,如下:
conda activate base
1.激活conda环境
执行下列代码:
conda create -n MaskRCNN python=2.7 conda activate MaskRCNN pip install tensorflow==1.4.0 #或者 pip install tensorflow-gpu==1.4.0 pip install keras==2.0.9
2.安装scikit-image
sudo pip install scikit-image
3.安装pycocotools
pip install pycocotools
4.安装依赖
pip install Cython pip install fasttext
5.安装coco工具箱
cd coco cd PythonAPI which python sudo /home/liuhongwei/anaconda3/envs/MaskRCNN/bin/python setup.py install
6.将新生成的 build/lib.linux-x86_64-2.7/pycocotools
文件夹里的内容替换到 pycocotools
文件夹中
7.测试Mask R-CNN环境及报错解决
python src/python/Check.py
有Bug: ImportError: No module named skimage.io
选择安装低版本:
pip uninstall scikit-image pip install scikit-image==0.14.5
pip install numpy==1.15.0
1.下载tensorflow1.12.3压缩包
tenserflow1.12.3
2.安装
sudo pip install tensorflow-1.12.3-cp27-cp27mu-manylinux1_x86_64.whl
出bug了.............
3.Debug
python -m pip install --upgrade pip
重新执行
4.安装与tensorflow1.12.3对应版本的Keras2.0.9
sudo pip install keras==2.0.9 -i https://pypi.tuna.tsinghua.edu.cn/simple
5.继续check.py
出错了,继续Debug!
- 把文件
mask_rcnn_coco.h5
复制到DynaSLAM/src/python/
下还是不行...................
报错信息:Unable to open file (unable to open file: name = './src/python/mask_rcnn_coco.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
文件目录出现问题。查看maskrcnncoco.h5的属性,把DynaSLAM/src/python/Check.py的目录修改如下:ROOT_DIR = "/home/liuhongwei/Desktop/DynaSLAM/src/python"
成功!
-match native去掉
./build.sh
安装成功!
数据集点我下载
在这些动态场景里随便下一个 !
将ORB-SLAM2的根目录下新建data文件夹,将我们的数据集解压后放到里面,如图:
点我下载associate.py
liuhongwei@ubuntu:~/Desktop/ORB_SLAM2-master$ python ./data/associate.py ./data/rgbd_dataset_freiburg3_sitting_static/rgb.txt ./data/rgbd_dataset_freiburg3_sitting_static/depth.txt > data/rgbd_dataset_freiburg3_sitting_static/associations.txt
./Examples/RGB-D/rgbd_tum ./Vocabulary/ORBvoc.txt ./Examples/RGB-D/TUM3.yaml data/rgbd_dataset_freiburg3_sitting_static/ data/rgbd_dataset_freiburg3_sitting_static/associations1.txt
相同数据集
运行RGB-D数据集:传入参数分别为:可执行程序、ORB字典、配置信息、数据集路径、Mask目录、OUTPUT目录。其中mask目录和output目录是我们新建的。
如果提供了 PATH_TO_MASKS,Mask R-CNN 用于分割每一帧的潜在动态内容。这些mask保存在提供的文件夹 PATH_TO_MASKS 中。如果此参数为 no_save,则使用mask但不保存。如果它在 PATH_TO_MASKS 中找到 Mask R-CNN 计算的动态掩码,它会使用它们但不会再次计算它们。
如果提供了 PATH_TO_OUTPUT,则计算修复的帧并将其保存在 PATH_TO_OUTPUT 中。(背景修复)
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM3.yaml ./data/rgbd_dataset_freiburg3_sitting_static/ ./data/rgbd_dataset_freiburg3_sitting_static/associations.txt ./data/mask/ ./data/output/