(双系统GPU版)DynaSLAM超详细安装配置运行ubantu20.0.4+opencv2.4.11+tensorflow-gpu1.14.0

(双系统GPU版)DynaSLAM超详细安装配置运行ubantu20.0.4+opencv2.4.11+tensorflow-gpu1.14.0

下面链接是之前在虚拟机上安装的cpu版教程:
DynaSLAM超详细安装配置运行ubantu20.0.4+opencv2.4.11+tensorflow1.4.0

一、安装Anaconda

参考:安装Anaconda

二、安装boost库

sudo apt-get install libboost-all-dev

三. 下载DynaSLAM源码和mask_rcnn_coco.h5

3.1 下载DynaSLAM源码

git clone https://github.com/BertaBescos/DynaSLAM.git

3.2 下载mask_rcnn_coco.h5

注:找不到的拉到页面的最下面。

在这里插入图片描述

四、用Anaconda配置Python相关的环境

4.1 配置Anaconda环境

这里先在Anaconda创建一个新的虚拟环境并激活,然后在虚拟环境中依次安装tensorflowkeras
PS: 我已经安装了cuda11.4: ubuntu20.04,GeForce RTX 3060,CUDA Version: 11.4安装cuda

conda create -n DynaSLAM python=2.7  
conda activate DynaSLAM
pip install tensorflow-gpu==1.14.0
pip install keras==2.0.9
pip install h5py==2.10.0
pip install numpy==1.16.6
pip install pillow==6.2.2 
pip install pycocotools==2.0.3
pip install scikit-image==0.14.5
sudo apt-get install libcanberra-gtk-module 

我后面又配置了一个conda环境 (MASKRCNN) 用的是 conda create -n MASKRCNN python=2.7.18

PS: 如果安装了scikit-image但是在运行 conda list后,找不到scikit-image,可以试试关闭这个conda环境,再重新激活环境。

conda deactivate
conda activate DynaSLAM

如果下载慢,可以试试添加清华镜像

  • 第一步:添加Anaconda的清华镜像
    anaconda默认的各种包的下载源,全部在国外,下载速度慢,而且经常中断,所以需要配置国内安装的镜像,这样下载速度就很快了。
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  • 第二步:设置搜索时显示通道地址
conda config --set show_channel_urls yes 

注意:首次运行conda config会产生一个anacnoda的配置文件,这个配置文件和jupyter的配置文件一样,默认是不存在的。Windows为的默认位置为C://Users/username/.condarcLinux/Mac~/.condarc

  • 第三步:更新pip的源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  • 查看当前下载源
(yolact) cgm:~$ conda config --show channels                                                                                                                                                                                
channels:                                                                                                                                                                                                                       
 - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/                                                                                                                                                                 
 - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/                                                                                                                                                             
 - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/                                                                                                                                                                   
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2                                                                                                                                                                    
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro                                                                                                                                                                      
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r                                                                                                                                                                        
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free                                                                                                                                                                     
 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main                                                                                                                                                                     
 - defaults  

添加上了上述镜像后,原先源仍然存在,文件中的-defaults就是原来的源。

  • 清除添加的所有下载源
    当我们想换回Anaconda的默认下载源时,把之前设置的移除就行了:
conda config --remove-key channels

4.2 以下是安装的截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、测试Mask R-CNN环境

4.1 测试Mask R-CNN环境

前提:激活conda环境,cd到DynaSLAM,再运行以下命令

python src/python/Check.py

如果输出为Mask R-CNN is correctly working,就可以下一步了。
在这里插入图片描述
在这里插入图片描述
PS: 如果安装了scikit-image,在测试的时候报错ImportError: No module named skimage.io,并且在运行 conda list后,找不到scikit-image,可以试试关闭这个conda环境,再重新激活环境。

conda deactivate DynaSLAM
conda activate DynaSLAM

4.2、相应的依赖的版本

(DynaSLAM) cgm@cgm:~$ conda list
# packages in environment at /home/cgm/anaconda3/envs/DynaSLAM:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex             4.5                       2_gnu    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
absl-py                   0.15.0                   pypi_0    pypi
astor                     0.8.1                    pypi_0    pypi
backports-functools-lru-cache 1.6.4                    pypi_0    pypi
backports-weakref         1.0.post1                pypi_0    pypi
ca-certificates           2022.12.7            ha878542_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
certifi                   2016.9.26                py27_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
cloudpickle               1.3.0                    pypi_0    pypi
cycler                    0.10.0                   pypi_0    pypi
cython                    0.29.33                  pypi_0    pypi
decorator                 4.4.2                    pypi_0    pypi
enum34                    1.1.10                   pypi_0    pypi
funcsigs                  1.0.2                    pypi_0    pypi
futures                   3.4.0                    pypi_0    pypi
gast                      0.5.3                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.41.1                   pypi_0    pypi
h5py                      2.10.0                   pypi_0    pypi
keras                     2.0.9                    pypi_0    pypi
keras-applications        1.0.8                    pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
kiwisolver                1.1.0                    pypi_0    pypi
ld_impl_linux-64          2.40                 h41732ed_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libffi                    3.2.1             he1b5a44_1007    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgcc-ng                 12.2.0              h65d4601_19    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgomp                   12.2.0              h65d4601_19    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libsqlite                 3.40.0               h753d276_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libzlib                   1.2.13               h166bdaf_4    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
markdown                  3.1.1                    pypi_0    pypi
matplotlib                2.2.5                    pypi_0    pypi
mock                      3.0.5                    pypi_0    pypi
ncurses                   6.3                  h27087fc_1    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
networkx                  2.2                      pypi_0    pypi
numpy                     1.16.6                   pypi_0    pypi
openssl                   1.1.1t               h0b41bf4_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pillow                    6.2.2                    pypi_0    pypi
pip                       20.0.2                   py27_1    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
protobuf                  3.17.3                   pypi_0    pypi
pycocotools               2.0.3                    pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
python                    2.7.15          h5a48372_1011_cpython    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                2.7                    1_cp27mu    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pytz                      2022.7.1                 pypi_0    pypi
pywavelets                1.0.3                    pypi_0    pypi
pyyaml                    5.4.1                    pypi_0    pypi
readline                  8.2                  h8228510_1    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
scikit-image              0.14.5                   pypi_0    pypi
scipy                     1.2.3                    pypi_0    pypi
setuptools                44.1.1                   pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
sqlite                    3.40.0               h4ff8645_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
subprocess32              3.5.4                    pypi_0    pypi
tensorboard               1.14.0                   pypi_0    pypi
tensorflow-estimator      1.14.0                   pypi_0    pypi
tensorflow-gpu            1.14.0                   pypi_0    pypi
termcolor                 1.1.0                    pypi_0    pypi
tk                        8.6.12               h27826a3_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
werkzeug                  1.0.1                    pypi_0    pypi
wheel                     0.34.2                   py27_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wrapt                     1.15.0                   pypi_0    pypi
zlib                      1.2.13               h166bdaf_4    http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

在这里插入图片描述

五、安装OpenCV2.4.11和OpenCV4.2.0双版本共存

5.1 OpenCV版本要求

ps:有人说:(不是我说的,我没测试OpenCV 3.X)

README.md中写的DynaSLAM 现在支持 OpenCV 2.X 和 OpenCV 3.X。在实测中发现3.4.3版本运行异常,具体原因不知道;根据网上的建议,我重新安装了老版本的OpenCV 2.4.11

查看DynaSLAM的CMakeLists.txt ,我电脑是OpenCV4.2.0,现在安装OpenCV2.4.11双版本共存。
在这里插入图片描述

  • 查看自己opencv版本
pkg-config opencv --modversion
  • 查看opencv4版本的命令:
pkg-config opencv4 --modversion

在这里插入图片描述

5.2下载安装包

官网opencv 2.4.11安装包点击下载,下载好后

注:第三行和 cmake .. 一样,最后有两个点点

  • 防止报错如下:CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list)
  • 解决:将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()
  • 防止报错如下:rgbdodometry.cpp:65:12: fatal error: unsupported/Eigen/MatrixFunctions: 没有那个文件或目录
  • 解决方案:在opencv-2.4.11/modules/contrib/src/rgbdodometry.cpp65行加上eigen3
#include <eigen3/unsupported/Eigen/MatrixFunctions>
//或者
#include </usr/include/eigen3/unsupported/Eigen/MatrixFunctions>

5.2 开始编译并安装

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 -D WITH_CUDA=OFF -D CUDA_nppicom_LIBRARY=stdc++ ..
make -j4
sudo make install

我这里没有用cuda-D WITH_CUDA=OFF
我试过:-D WITH_CUDA=ON 或者不要这个命令,但是编译出来有个错误:CUDA_nppi_LIBRARY (ADVANCED),折腾了一下没弄好就算了。

在这里插入图片描述

在这里插入图片描述

cgm@cgm:~/opencv-2.4.11/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.11 -DENABLE_PRECOMPILED_HEADERS=OFF -D WITH_FFMPEG=OFF -D WITH_CUDA=OFF  ..
CMake Deprecation Warning at CMakeLists.txt:47 (cmake_policy):
  The OLD behavior for policy CMP0022 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


CMake Deprecation Warning at CMakeLists.txt:52 (cmake_policy):
  The OLD behavior for policy CMP0026 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


-- Detected version of GNU GCC: 90 (900)
-- Could NOT find Jasper (missing: JASPER_LIBRARIES JASPER_INCLUDE_DIR) 
-- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- 
-- General configuration for OpenCV 2.4.11 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Host:                        Linux 5.15.0-67-generic x86_64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 9.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -msse3 -ffunction-sections -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     Precompiled headers:         NO
-- 
--   OpenCV modules:
--     To be built:                 core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib python stitching superres ts videostab
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera dynamicuda java viz
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 2.x:                    YES (ver 2.24.32)
--     GThread :                    YES (ver 2.64.6)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.1.0)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.3.0)
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.5)
--     FFMPEG:                      NO
--       codec:                     NO
--       format:                    NO
--       util:                      NO
--       swscale:                   NO
--       gentoo-style:              NO
--     GStreamer:                   
--       base:                      YES (ver 1.16.3)
--       video:                     YES (ver 1.16.3)
--       app:                       YES (ver 1.16.3)
--       riff:                      YES (ver 1.16.3)
--       pbutils:                   YES (ver 1.16.3)
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    Using libv4l1 (ver 1.18.0) / libv4l2 (ver 1.18.0)
--     XIMEA:                       NO
--     Xine:                        NO
-- 
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use Eigen:                   YES (ver 3.3.7)
--     Use TBB:                     NO
--     Use OpenMP:                  NO
--     Use GCD                      NO
--     Use Concurrency              NO
--     Use C=:                      NO
--     Use Cuda:                    NO
--     Use OpenCL:                  YES
-- 
--   OpenCL:
--     Version:                     dynamic
--     Include path:                /home/cgm/opencv-2.4.11/3rdparty/include/opencl/1.2
--     Use AMD FFT:                 NO
--     Use AMD BLAS:                NO
-- 
--   Python:
--     Interpreter:                 /usr/bin/python2 (ver 2.7.18)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.18)
--     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.5)
--     packages path:               lib/python2.7/dist-packages
-- 
--   Java:
--     ant:                         NO
--     JNI:                         /usr/lib/jvm/java-8-openjdk-amd64/include /usr/lib/jvm/java-8-openjdk-amd64/include/linux /usr/lib/jvm/java-8-openjdk-amd64/include
--     Java tests:                  NO
-- 
--   Documentation:
--     Build Documentation:         NO
--     Sphinx:                      NO
--     PdfLaTeX compiler:           NO
--     Doxygen:                     YES (/usr/bin/doxygen)
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     C/C++ Examples:              NO
-- 
--   Install path:                  /usr/local/opencv2.4.11
-- 
--   cvconfig.h is in:              /home/cgm/opencv-2.4.11/build
-- -----------------------------------------------------------------
-- 
-- Configuring done
CMake Warning (dev) at apps/haartraining/CMakeLists.txt:37 (add_library):
  Policy CMP0038 is not set: Targets may not link directly to themselves.
  Run "cmake --help-policy CMP0038" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  Target "opencv_haartraining_engine" links to itself.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at apps/haartraining/CMakeLists.txt:37 (add_library):
  Policy CMP0038 is not set: Targets may not link directly to themselves.
  Run "cmake --help-policy CMP0038" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  Target "opencv_haartraining_engine" links to itself.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /home/cgm/opencv-2.4.11/build
  • 编译到96%时报错:error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
  • 找到opencv-2.4.11/build/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make文件,删掉-Werror=address
    在这里插入图片描述
    然后再就成功安装了
make -j4
sudo make install

安装在这里的/usr/local/opencv2.4.11

在这里插入图片描述

5.3 添加环境变量

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

使用另一个版本(我的是4.2.0)的时候,同样终端输入 gedit ~/.bashrc 就将前两行的#号去掉即可(取消注释)。

记得要 source ~/.bashrc
在这里插入图片描述

六 安装编译DynaSLAM

6.1下载bbescos/feature/carla分支的DynaSLAM源码

//通过以下命令可以克隆带有carla文件的源码
git clone -b bbescos/feature/carla https://github.com/BertaBescos/DynaSLAM

PS:如果克隆的master分支,master分支里没有mono_carla.cc这个文件,需要注释掉

git clone https://github.com/BertaBescos/DynaSLAM
//注释master分支的CMakeLists.txt的末尾部分

# add_executable(mono_carla
# Examples/Monocular/mono_carla.cc)
# target_link_libraries(mono_carla ${
      
      PROJECT_NAME})

注:master里没有mono_carla.cc这个文件

在这里插入图片描述

6.2 运行DynaSLAM报错解决

cgm@ubuntu:~$ conda activate DynaSLAM
(DynaSLAM) cgm@ubuntu:~$ cd DynaSLAM/
(DynaSLAM) cgm@ubuntu:~/DynaSLAM$ chmod +x build.sh
(DynaSLAM) cgm@ubuntu:~/DynaSLAM$ ./build.sh

(1)将Dynaslam根目录中的CMakeLists.txt 以及 ThirdpartyDBoW2g2o中的CMakeLists.txt文件中的 -march=native去掉 (否则会报核心转储的错误)

//快速去掉的操作是:vscode里 ctrl+shift+F 打开搜索框,输入`-march=native`  进行全部替换

注:我最后的测试发现不删掉也可以运行。

在这里插入图片描述

(2)修改有错误的文件:

  • 进入Dynaslamsrcviewer.cc中,按Ctrl+F查找imshow,我们可以看到2imshow,而且调用之前没有判断,会在某些情况导致程序终止。我们将两句话依次对应替换即可(其实就是先if(!image.empty())判断一下)
        pangolin::FinishFrame();		
        cv::Mat im = mpFrameDrawer->DrawFrame();
		//cv::imshow("DynaSLAM: Current Frame",im); //替换为如下if语句
        if(!im.empty())
        {
    
    
           cv::imshow("DynaSLAM: Current Frame",im);
        }
         cv::Mat im_dyn = mpFrameDrawer->GetDynamicFrame();
         //cv::imshow("DynaSLAM: Dynamic Frame", im_dyn); //替换为如下if语句
         if(!im_dyn.empty())
        {
    
    
           cv::imshow("DynaSLAM: Dynamic Frame", im_dyn);
        }

我测试的是不修改这个会闪退

在这里插入图片描述

在这里插入图片描述

注意:master分支viewer.cc是这样的

在这里插入图片描述

(3)报错:/usr/include/c++/9/bits/stl_map.h:122:71: error: static assertion failed: std::map must have the same value_type as its allocator

  • 解决办法:(这个不修改100%报错)
//打开LoopClosing.h,将
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;

(4)如果报错:

In file included from /home/cgm/DynaSLAM/src/Conversion.cc:9:/home/cgm/DynaSLAN/include/Conversion.h:17:10: fatal error: ndarrayobject.h:没有那个文件或目录
17|#include "ndarrayobject.h"
compilation terminated .

解决办法:在anaconda3/envs下搜索ndarrayobject.h,复制其路径,添加到ndarrayobject.h

//Conversion.h
//将
#include "ndarrayobject.h"
//改为正确的python2.7下的路径
#include "/home/cgm/anaconda3/envs/DynaSLAM/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h"

在这里插入图片描述

6.3 编译成功DynaSLAM

在这里插入图片描述

七 运行DynaSLAM

7.1 TUM 数据集上的 RGB-D 示例

对于TUM 动态序列,这些关联文件在./Examples/RGB-D/associations/的文件夹中给出。

在这里插入图片描述

7.2 上面这些关联文件的由来

例如我们使用 数据集TUM的DYNAMIC OBJECTS下的(rgbd_dataset_freiburg2_desk_with_person

在这里插入图片描述

使用associate.py将数据集中的RGB图片和深度图建立关联

原因:

Kinect 以非同步方式提供颜色和深度图像。这意味着来自彩色图像的时间戳集不会与深度图像的时间戳集相交。因此,我们需要某种方式将彩色图像与深度图像相关联。

为此,您可以使用“associate.py”脚本。rgb.txt文件和从文件中读取时间戳depth.txt,并通过查找最佳匹配来连接它们。

点这里下载associate.py

python associate.py rgb.txt depth.txt > rgbd_dataset_freiburg2_desk_with_person.txt

在这里插入图片描述

7.3 TUM 数据集上的 RGB-D 示例程序运行

说明:

  • ​ 运行./Examples/RGB-D/rgbd_tum,传入参数分别为:ORB字典、配置信息、数据集路径、Mask目录、OUTPUT目录。其中mask目录和output目录是我们新建的。
  • ​ 如果提供了 PATH_TO_MASKSMask R-CNN 用于分割每一帧的潜在动态内容。这些mask保存在提供的文件夹 PATH_TO_MASKS 中。如果此参数为 no_save,则使用mask但不保存。如果它在 PATH_TO_MASKS 中找到 Mask R-CNN 计算的动态掩码,它会使用它们但不会再次计算它们。
  • ​ 如果提供了 PATH_TO_OUTPUT,则计算修复的帧并将其保存在 PATH_TO_OUTPUT 中。(背景修复)

(1)如果未提供 PATH_TO_MASKS 和 PATH_TO_OUTPUT,则仅使用几何方法检测动态对象

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM3.yaml ../DataSet/TUM_Dataset/rgbd_dataset_freiburg3_walking_xyz/ Examples/RGB-D/associations/fr3_walking_xyz.txt

报错:

Light Tracking not working because Tracking is not initialized...
Geometry not working.
New map created with 717 points
Geometry not working.
Geometry not working.
Geometry not working.
  • 解决:如果运行起来发现Light Track一直不成功,无法初始化,那么就把ORB参数设置中特征点的数目增多,github上大家一般改成3000就好了。
//TUM3.yaml文件
//ORB Extractor: Number of features per image
ORBextractor.nFeatures: 3000

我这里报了个错误:Failed to load module "canberra-gtk-module"
解决:sudo apt-get install libcanberra-gtk-module
在这里插入图片描述

evo_ape tum groundtruth.txt KeyFrameTrajectory.txt --plot -va --plot_mode xy

在这里插入图片描述

(2)有PATH_TO_MASKSMask R-CNN用于分割每一帧的潜在动态内容

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM3.yaml ../DataSet/TUM_Dataset/rgbd_dataset_freiburg3_walking_xyz/ Examples/RGB-D/associations/fr3_walking_xyz.txt /data/mask 
  • 报错:
Geometry not working.
Light Tracking not working because Tracking is not initialized...
  • 解决:如果运行起来发现Light Track一直不成功,无法初始化,那么就把ORB参数设置中特征点的数目增多,github上大家一般改成3000就好了。
//TUM3.yaml文件
//ORB Extractor: Number of features per image
ORBextractor.nFeatures: 3000

在这里插入图片描述

运行着运行着(卡着卡着)大概在kps:25,就崩了…

Depth Threshold (Close/Far Points): 2.98842

-------
Start processing sequence ...
Images in the sequence: 827

Light Tracking not working because Tracking is not initialized...
Geometry not working.
New map created with 769 points
OpenCV Error: Assertion failed (a_size.width == len) in gemm, file /home/cgm/opencv-2.4.11/modules/core/src/matmul.cpp, line 728
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/cgm/opencv-2.4.11/modules/core/src/matmul.cpp:728: error: (-215) a_size.width == len in function gemm
  
已放弃 (核心已转储)

哪的问题?? OpenCV Error: Assertion failed (a_size.width == len) in gemm

在这里插入图片描述
(3)有PATH_TO_MASKSPATH_TO_OUTPUT路径,Mask R-CNN用于分割每一帧的潜在动态内容

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM3.yaml ../DataSet/TUM_Dataset/rgbd_dataset_freiburg3_walking_xyz/ Examples/RGB-D/associations/fr3_walking_xyz.txt /data/mask /data/f3_wxyz_imOut

这个不会报错,不知道为什么提供一个路径就要报错...
卡的话多跑几遍,后面再运行程序就直接读取你保存的掩码了。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u013454780/article/details/130007251