SLMA十四講”中環(huán)境配置
參考資料:
https://zhuanlan.zhihu.com/p/452256687
https://blog.csdn.net/qq_38629044/article/details/95355859
https://blog.csdn.net/Bonaventure/article/details/122835996
https://blog.csdn.net/weixin_44986556/article/details/108962861
https://blog.csdn.net/qq_38364548/article/details/122055690
https://blog.csdn.net/rong11417/article/details/103905794
https://blog.csdn.net/CSSDCC/article/details/123442605
運(yùn)行官方ORB-SLAM2代碼可以安裝0.5版本Pangolin,相關(guān)報錯參考:https://zhuanlan.zhihu.com/p/411027681
系統(tǒng)版本:Ubuntu 20.04
參考書:slam十四講 第二版
安裝軟件或者庫時,建議加上 sudo 命令?。?!
運(yùn)行代碼時注意檢測代碼中讀取文件的路徑?。?!
1、安裝 VScode 工具:
建議使用普通用戶登陸系統(tǒng),root用戶可能無法正常打開 VScode :
可以在軟件商店安裝(速度較慢);
安裝vscode完成后遇到無法打開軟件的情況:推薦使用普通用戶登錄 Ubuntu,一般能夠正常打開VScode
2、配置 SLAM 環(huán)境:
2.1 安裝 C++、cmake、git :
sudo apt-get install -y g++
sudo apt-get install -y cmake
sudo apt-get install -y git
2.2 安裝 Eigen(第三講中用到)
因?yàn)楹罄m(xù)安裝g2o的時候需要Eigen(線性代數(shù))支持,所以先進(jìn)行Eigen的配置:
sudo apt-get install libeigen3-dev #安裝Eigen
pkg-config --cflags eigen3 #檢查安裝
sudo apt-get remove libeigen3-dev #卸載
Eigen 安裝完成后可以嘗試運(yùn)行“SLMA十四講”第三講48頁代碼“eigenMatrix.cpp”。
使用VScode運(yùn)行時,可能會遇到報錯,查看后文linux下運(yùn)行Vscode代碼的問題處理部分。
2.3 安裝可視化顯示庫:
Pangolin——可視化顯示庫 (第三講中用到)
sudo apt-get install libglew-dev libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt install libgl1-mesa-dev
#安裝依賴項(xiàng)
git clone https://github.com/stevenlovegrove/Pangolin.git #自行指定文件夾下載pangolin
cd Pangolin
mkdir build
cd build
cmake -DCPP11_NO_BOOST= 1 ..
make -j12
sudo make install
Pangolin 安裝完成后可以在pangolin路徑下使用以下代碼測試:
cd examples/HelloPangolin
./HelloPangolin
安裝完成可以嘗試運(yùn)行“SLMA十四講”第三講65頁代碼“coordinateTransform.cpp”以及67頁代碼“plotTrajectory.cpp”
2.4安裝 Sophus——李代數(shù)
Sophus的安裝存在兩個問題,一個是Sophus模板類和非模板類的區(qū)別,為了新手方便使用十四講中推薦的是非模板類的Sophus,需要將git到的Sophus回滾到a621ff版本;另一個就是由于編譯器版本的不同,出現(xiàn)非模板類Sophus編譯不過。
報錯1:報錯c++: fatal error: 已殺死 signal terminated program cc1plus
建議安裝Sophus前先建一個交換分區(qū)(swap分區(qū)):
# 創(chuàng)建分區(qū)路徑
sudo mkdir -p /var/cache/swap/
# 設(shè)置分區(qū)的大小
# bs=64M是塊大小,count=64是塊數(shù)量,所以swap空間大小是bs*count=4096MB=4GB
sudo dd if=/dev/zero of=/var/cache/swap/swap0 bs=64M count=64
# 設(shè)置該目錄權(quán)限
sudo chmod 0600 /var/cache/swap/swap0
# 創(chuàng)建SWAP文件
sudo mkswap /var/cache/swap/swap0
# 激活SWAP文件
sudo swapon /var/cache/swap/swap0
# 查看SWAP信息是否正確
sudo swapon -s
分區(qū)創(chuàng)建并激活的效果圖如下:
swap0文件的路徑在/var/cache/swap/下,編譯完后, 如果不想要交換分區(qū)了, 可以刪除。
#刪除交換分區(qū)的命令
sudo swapoff /var/cache/swap/swap0
sudo rm /var/cache/swap/swap0
釋放空間命令:
sudo swapoff -a
#詳細(xì)的用法:swapoff --help
#查看當(dāng)前內(nèi)存使用情況:free -m
安裝Sophus庫
git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout a621ff **#運(yùn)行第二版代碼不需要回滾**
mkdir build
cd build
cmake ..
make -j12 # 提高編程效率,表示以12線程運(yùn)行,電腦會變卡建議使用交換分區(qū)
sudo make install #安裝sophus庫
問題2:在 ubuntu18.04 下會出現(xiàn)“unit_complex_.real() = 1.; unit_complex_.imag() = 0. ;"的錯誤
解決方法:在sophus/so2.cpp文件中,將
unit_complex_.real() = 1. ;
unit_complex_.imag() = 0. ;
改為
unit_complex_.real(1.) ;
unit_complex_.imag(0.) ;
然后重新編譯即可
2.5 安裝fmt庫
可以在fmt編譯前將CMakeLists.txt中添加“add_compile_options(-fPIC)” 避免在ch13中出現(xiàn)錯誤
git clone https://github.com/fmtlib/fmt.git
cd fmt
git checkout b6f4ceae //回退到 release 8.1.1 版本防止出現(xiàn)問題
mkdir build
cd build
cmake ..
make -j12
sudo make install
2.6 安裝 OpenCV3
安裝依賴項(xiàng):
sudo apt install -y build-essential
sudo apt install -y libgtk2.0-dev
sudo apt install -y libvtk5-dev #可以安裝新版本 sudo apt install -y libvtk6-dev
sudo apt install -y libjpeg-dev
sudo apt install -y libtiff5-dev
sudo apt install -y libjasper-dev
sudo apt install -y libopenexr-dev
sudo apt install -y libtbb-dev
從官網(wǎng)下載 OPenCV 3.4.15版本 linux安裝包,進(jìn)行編譯安裝:
cd opencv-3.4.15
mkdir build && cd build
cmake ..
make -j12
sudo make install
后續(xù)編譯運(yùn)行代碼可能出錯,詳情見第3部分報錯記錄第 6 節(jié)。
2.7安裝:Ceres——最小二乘優(yōu)化 slam 十四講 ch6 需要
先安裝依賴:
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3 libgflags-dev libgoogle-glog-dev libgtest-dev
下載Ceres:
git clone https://github.com/ceres-solver/ceres-solver
安裝Ceres:
cd ceres-solver
mkdir build
cd build/
cmake ..
make -j4
sudo make install
2.8 安裝 g2o 庫
下載 g2o
git clone https://github.com/RainerKuemmerle/g2o
安裝依賴環(huán)境,終端輸入:
sudo apt-get install qt5-qmake qt5-default libqglviewer-dev-qt5 libsuitesparse-dev libcxsparse3 libcholmod3
在slambook2/3rdparty/g2o文件夾下打開終端并輸入:
cd g2o
mkdir build
cd build/
cmake ..
make -j4
sudo make install
2.9 安裝點(diǎn)云庫:pcl——點(diǎn)云庫
sudo apt-get install libpcl-dev pcl-tools
2.10 安裝 DBoW3 庫:
自行指定文件夾下下載并安裝,終端并輸入:
git clone https://github.com/rmsalinas/DBow3
cd DBow3
mkdir build
cd build/
cmake ..
make -j12
sudo make install
2.11 安裝 octomap 終端輸入:
sudo apt-get install liboctomap-dev octovis
3、運(yùn)行代碼時的報錯問題記錄:
注意多檢查代碼運(yùn)行時需要的參數(shù)以及代碼中的文件路徑 !??!
3.1 vscode運(yùn)行代碼報錯:
找不到“Egin/core”,修改源碼中的“Egin/core”為:“eigen3/Egin/core”
或者添加軟鏈接將 eigen3/Eigen 指向 Eigen :
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
3.2 Linux中 error while loading shared libraries錯誤解決辦法
錯誤提示:
./plotTrajectory: error while loading shared libraries: libpango_windowing.so: cannot open shared object file: No such file or directory
錯誤原因:找不到共享庫libpango_windowing.so
查看usr/local/lib 下有沒有,看到已經(jīng)有了。
終端使用命令刷新共享庫:
sudo ldconfig
如果是build里編譯的話可能或找不到trajectory.txt文件,會出現(xiàn)以下報錯:
cannot find trajectory file at ../examples/trajectory.txt
改一下slam十四講 3.7顯示運(yùn)動軌跡的程序 trajectory.txt文件路徑,可以寫絕對路徑,建議改成相對路徑。
string trajectory_file = “./examples/trajectory.txt”;
#改為自己的實(shí)際路徑
string trajectory_file = “/home/dal/slambook2/ch3/examples/trajectory.txt”;
3.3 遇到報錯:error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
修改編譯器標(biāo)準(zhǔn)即可解決問題。
將CmakeLists.txt中
set(CMAKE_CXX_FLAGS “-std=c++11”)
改為
set(CMAKE_CXX_STANDARD 14)
如圖:
修改后可正常編譯運(yùn)行:
3.4 報錯:
error: ‘slots_reference’ was not declared in this scope
1180 | cow_copy_type<list_type, Lockable> ref = slots_reference();
注意將CMakelists.txt中的C++版本切換到C++14。
3.5 運(yùn)行ch4中的代碼出現(xiàn)類似“fatal error: fmt/core.h: 沒有那個文件或目錄”
之所以出現(xiàn)該問題是因?yàn)樵瓡褂肧ophous庫時,僅僅需要EIgen一個依賴,而如今版本的Sophous庫還需要fmt依賴。
因此,要解決此問題按照本文2.5安裝該庫即可。
然而在安裝好fmt之后,雖然解決了尋找不到fmt的問題,但編譯時又出現(xiàn)了新的報錯:
usr/bin/ld: CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o: in function `std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<int>(int)':
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_]+0x23): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
/usr/bin/ld: CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o: in function `std::make_unsigned<long>::type fmt::v8::detail::to_unsigned<long>(long)':
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_]+0x25): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
此時ch4中的 useSophus.cpp 可以正常編譯,但是 example 中的 trajectoryError.cpp 無法編譯成功,注意檢查 cpp 文件中的內(nèi)容和 CMakelists 的內(nèi)容。
應(yīng)遵循調(diào)用層次,從依賴到被依賴。所以在CMakeLists.txt中添加:
target_link_libraries(trajectoryError ${Sophus_LIBRARIES} fmt)
trajectoryError依賴于Sophus,Sophus依賴于fmt。
此時可以編譯完成,運(yùn)行文件提示找不到文件:
修改cpp文件中的代碼,將文件路徑修改為絕對路徑或者相對路徑。再次編譯后運(yùn)行成功。
3.6 進(jìn)行編譯 ch5 imageBasics.cpp 時報錯:
/usr/bin/ld: CMakeFiles/undistortImage.dir/undistortImage.cpp.o: in function `main':
undistortImage.cpp:(.text+0xdc): undefined reference to `cv::imread(cv::String const&, int)'
/usr/bin/ld: undistortImage.cpp:(.text+0x120): undefined reference to `cv::Mat::Mat(int, int, int)'
原因:由于使用 OPenCV 版本的不同,需要在 CMakelists 前添加一段:
cmake_minimum_required(VERSION 2.8)
# 尋找OpenCV庫
find_package(OpenCV REQUIRED)
# 添加頭文件
include_directories(${OpenCV_INCLUDE_DIRS})
#所有涉及到 OPenCV 的源代碼,前面都可以添加。
編譯成功后運(yùn)行代碼,遇到新問題:
./imageBasics: error while loading shared libraries: libopencv_core.so.3.4: cannot open shared object file: No such file or directory
(1) 打開路徑
cd /etc/ld.so.conf.d
(2) 創(chuàng)建文件:
touch OpenCV.conf
或者不創(chuàng)建文件:直接下載OpenCV.conf,將該文件放在第1步的路徑下,然后直接進(jìn)行第四步(注意:OpenCV.conf中的路徑一定要是自己opencv的install路徑,具體參看步驟3)
(3) 在OpenCV.conf中寫入:
/usr/local/lib
注:該路徑為opencv install之后的路徑,一般默認(rèn)的路徑為/usr/local/lib,即lib*.so庫文件所在的路徑。
(4) 在終端執(zhí)行命令:
sudo ldconfig
完成后可以正常運(yùn)行
3.7 運(yùn)行ch5 中 undistorImage.cpp 時報錯:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.15) /root/opencv-3.4.15/modules/imgproc/src/median_blur.dispatch.cpp:283: error: (-215:Assertion failed) !_src0.empty() in function 'medianBlur'
已放棄 (核心已轉(zhuǎn)儲)
解決方法:檢查 cpp 文件中的文件路徑是否正確。
如果確認(rèn)文件位置正確后依然報錯,嘗試參考博客,對比報錯代碼進(jìn)行修改:
https://blog.csdn.net/weixin_45617478/article/details/102648651
https://blog.csdn.net/BigDream123/article/details/89477248
3.8 運(yùn)行ch5 中的 joinMap.cpp 文件報錯:
/usr/bin/ld: CMakeFiles/joinMap.dir/joinMap.cpp.o: in function `std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<i nt>(int)':
joinMap.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13 make_unsignedIT_E4typeES4_]+0x23): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
... ...
joinMap.cpp:(.text._ZN3fmt2v86detail13width_checkerINS1_13error_handlerEEclIjLi0EEEyT_[_ZN3fmt2v86detail13width_checkerINS1_ 13error_handlerEEclIjLi0EEEyT_]+0x33): undefined reference to `fmt::v8::detail::error_handler::on_error(char const*)'
/usr/bin/ld: CMakeFiles/joinMap.dir/joinMap.cpp.o:joinMap.cpp:(.text._ZN3fmt2v86detail13width_checkerINS1_13error_handlerEEc lIxLi0EEEyT_[_ZN3fmt2v86detail13width_checkerINS1_13error_handlerEEclIxLi0EEEyT_]+0x36): more undefined references to `fmt:: v8::detail::error_handler::on_error(char const*)' follow
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/joinMap.dir/build.make:120:joinMap] 錯誤 1
make[1]: *** [CMakeFiles/Makefile2:76:CMakeFiles/joinMap.dir/all] 錯誤 2
make: *** [Makefile:84:all] 錯誤 2
產(chǎn)生這個錯誤的原因是 CMakeLists文件沒有寫完整,
修改文件內(nèi)容為:
project(rgbd)
cmake_minimum_required(VERSION 3.10)
find_package(Sophus REQUIRED)
add_executable(joinMap joinMap.cpp)
include_directories(${Sophus_INCLUDE_DIRS})
#鏈接OpenCV庫
find_package(OpenCV REQUIRED)
#添加頭文件
include_directories( ${OpenCV-INCLUDE_DIRS})
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
find_package(Pangolin REQUIRED)
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
# Eigen
include_directories("/usr/local/include/eigen3")
target_link_libraries(joinMap ${Sophus_LIBRARIES} fmt)
#鏈接c++11
set(CMAKE_CXX_STANDARD 14)
按照以上內(nèi)容修改 CMakeLists.txt 文件后,運(yùn)行程序提示:
root@slam-virtual-machine:/home/slam/slambook2-master/ch5/rgbd/build# ./joinMap
轉(zhuǎn)換圖像中: 1
轉(zhuǎn)換圖像中: 2
轉(zhuǎn)換圖像中: 3
轉(zhuǎn)換圖像中: 4
轉(zhuǎn)換圖像中: 5
點(diǎn)云共有0個點(diǎn).
Point cloud is empty!
root@slam-virtual-machine:/home/slam/slambook2-master/ch5/rgbd/build#
檢查 cpp 中文件路徑是否正確,共有兩處文件路徑需要根據(jù)實(shí)際路徑修改。
3.9 SLAM十四講 ch7 代碼報錯:
此時將 CMakeLists.txt 中的C++11 改為C++14(之前也有過類似錯誤):
重新編譯,報錯:
/usr/bin/ld: CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o: in function `unsigned long long fmt::v8::detail::width_checker<fmt::v8::detail::error_handler>::operator()<float, 0>(float) [clone .isra.0]':
pose_estimation_3d2d.cpp:(.text+0xe): undefined reference to `fmt::v8::detail::error_handler::on_error(char const*)'
/usr/bin/ld: CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o: in function `unsigned long long fmt::v8::detail::precision_checker<fmt::v8::detail::error_handler>::operator()<float, 0>(float) [clone .isra.0]':
pose_estimation_3d2d.cpp:(.text+0x2e): undefined reference to `fmt::v8::detail::error_handler::on_error(char const*)'
/usr/bin/ld: CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o: in function `Sophus::SO3Base<Sophus::SO3<double, 0> >::normalize() [clone .part.0]':
原因是沒有引用 fmt :
修改CMakeList.txt中所有的 target_link_libraries :
target_link_libraries(orb_self ${OpenCV_LIBS}
改為:
target_link_libraries(orb_self ${OpenCV_LIBS} fmt)
此時編譯可能有一個缺少返回的語句,不影響程序運(yùn)行,可以自行修改。
3.10 運(yùn)行ch9中的代碼報錯。
CMakeLists.txt中的 C++ 版本問題,修改即可(下面還有一處需要修改,修改截圖在最后)。
重新編譯,有告警信息可以暫時不管。
報錯,由于沒有鏈接 fmt :
解決方法:
同時注意cpp文件中的目錄部分是否和自己當(dāng)前文件目錄一直,確認(rèn)無誤后重新編譯運(yùn)行正常。
3.11 運(yùn)行ch10時報錯:
參考問題10,同樣是C++版本的問題,后續(xù)fmt未鏈接的問題。(后續(xù)同樣問題不再寫)
解決方法:
編譯時會產(chǎn)生一個告警:
可以在 pose_graph_g2o_lie_algebra.cpp 文件54行的部分,添加 return true語句,重新編譯。
注意檢查 CPP 文件中的部分文件路徑(次數(shù)沒有需要修改的路徑)。
3.12 在ch11中需要安裝 DBow3 庫,未安裝會報錯:
安裝完成后編譯代碼報錯: 修改CMakeLists.txt 中的庫文件后綴。則將cmakelist中的libDBoW3.a改為libDBoW3.so即可。
若cmakelist中原來是libDBoW3.so,則改為libDBoW3.a
重新編譯運(yùn)行,注意cpp文件中的路徑。
注意檢查gen_vocab_large.cpp 文件,此處應(yīng)該帶參數(shù)運(yùn)行程序“gen_vocab”。
(此處存在部分疑問,尚未解決)
3.13 編譯ch12中“dense_RGBD”的代碼報錯:
By not providing "Findoctomap.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "octomap", but
CMake did not find one.
此時需要安裝:octomap
終端輸入:
sudo apt-get install liboctomap-dev octovis
安裝完成后編譯,運(yùn)行 pointcloud_mapping 后使用 pcl_viewer 對此章生成的點(diǎn)云圖“map.pcd”進(jìn)行查看。
3.14 編譯ch13報錯:注意修改CMakeLists.txt中的C++版本,改為C++ 14。
error: ‘index_sequence’ is not a member of ‘std’
199 | struct HessianTupleType<std::index_sequence<Ints...>>
3.15 編譯ch13報錯:
/usr/bin/ld: 找不到 -lglut
collect2: error: ld returned 1 exit status
安裝庫文件:
sudo apt install freeglut3-dev
3.16 編譯ch13報錯:
/usr/bin/ld: ../../lib/libmyslam.so: undefined reference to `fmt::v8::detail::error_handler::on_error(char const*)'
/usr/bin/ld: ../../lib/libmyslam.so: undefined reference to `std::locale fmt::v8::detail::locale_ref::get<std::locale>() const'
/usr/bin/ld: ../../lib/libmyslam.so: undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
/usr/bin/ld: ../../lib/libmyslam.so: undefined reference to `fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)'
/usr/bin/ld: ../../lib/libmyslam.so: undefined reference to `fmt::v8::detail::th
需要鏈接fmt庫。在ch13中src文件夾中加入以下代碼:
target_link_libraries(myslam
${THIRD_PARTY_LIBS}
fmt::fmt # 加入這一行
)
3.17 編譯ch13報錯:
[ 75%] Linking CXX shared library ../../lib/libmyslam.so
/usr/bin/ld: /usr/local/lib/libfmt.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: 最后的鏈結(jié)失敗: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/myslam.dir/build.make:273:../lib/libmyslam.so] 錯誤 1
make[1]: *** [CMakeFiles/Makefile2:136:src/CMakeFiles/myslam.dir/all] 錯誤 2
make: *** [Makefile:95:all] 錯誤 2
此處提供一種方法:
如果之前已經(jīng)安裝過fmt,刪除fmt路徑下的文件"libfmt.a"后重新安裝fmt
下載fmt編譯前在CMakeLists.txt中添加“add_compile_options(-fPIC)”文章來源:http://www.zghlxwxcb.cn/news/detail-413623.html
重新編譯安裝fmt。安裝完fmt后重新編譯ch13代碼沒有報錯。編譯fmt見上文2.5節(jié)。文章來源地址http://www.zghlxwxcb.cn/news/detail-413623.html
到了這里,關(guān)于slam十四講~環(huán)境安裝以及問題記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!