slambook2 が遭遇した「SLAM 14 講義」の落とし穴
ch5
01
opencv をインストールする場合は、通常のインストール後に使用できますが、CmakeLists.txt ファイルに opencv ライブラリが含まれているかどうかを確認してください。
02
問題: Gaobo の Visual SLAM の講義 14 の講義 5 で imageBasics.cpp をコンパイルすると、コンパイル エラーが発生します。
Scanning dependencies of target joinMap
[ 87%] Building CXX object rgbd/CMakeFiles/joinMap.dir/joinMap.cpp.o
/home/wj/STUDY/slambook2/ch5/rgbd/joinMap.cpp:4:10: fatal error: boost/format.hpp: No such file or directory
4 | #include <boost/format.hpp> // for formating strings
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [rgbd/CMakeFiles/joinMap.dir/build.make:63: rgbd/CMakeFiles/joinMap.dir/joinMap.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:219: rgbd/CMakeFiles/joinMap.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
回避策: libboost-all-dev をインストールします。
sudo apt-get install libboost-all-dev
———————————————
参考リンク
03
問題: rgbd のコンパイル、リンク joinMap レポートのエラー
100%] Linking CXX executable joinMap
/usr/bin/ld: CMakeFiles/joinMap.dir/joinMap.cpp.o: in function `char const* fmt::v8::detail::parse_replacement_field<char, fmt::v8::detail::format_string_checker<char, fmt::v8::detail::error_handler, Eigen::Transpose<Eigen::Matrix<double, 4, 1, 0, 4, 1> > >&>(char const*, char const*, fmt::v8::detail::format_string_checker<char, fmt::v8::detail::error_handler, Eigen::Transpose<Eigen::Matrix<double, 4, 1, 0, 4, 1> > >&)':
joinMap.cpp:(.text._ZN3fmt2v86detail23parse_replacement_fieldIcRNS1_21format_string_checkerIcNS1_13error_handlerEJN5Eigen9TransposeINS5_6MatrixIdLi4ELi1ELi0ELi4ELi1EEEEEEEEEEPKT_SE_SE_OT0_[_ZN3fmt2v86detail23parse_replacement_fieldIcRNS1_21format_string_checkerIcNS1_13error_handlerEJN5Eigen9TransposeINS5_6MatrixIdLi4ELi1ELi0ELi4ELi1EEEEEEEEEEPKT_SE_SE_OT0_]+0x149): undefined reference to `fmt::v8::detail::throw_format_error(char const*)'
# 此处省略10240字符
/usr/bin/ld: joinMap.cpp:(.text._ZN3fmt2v86detail18fallback_formatterIN5Eigen9TransposeINS3_6MatrixIdLi4ELi1ELi0ELi4ELi1EEEEEcvE6formatINS0_8appenderEEET_RKS7_RNS0_20basic_format_contextISB_cEE[_ZN3fmt2v86detail18fallback_formatterIN5Eigen9TransposeINS3_6MatrixIdLi4ELi1ELi0ELi4ELi1EEEEEcvE6formatINS0_8appenderEEET_RKS7_RNS0_20basic_format_contextISB_cEE]+0xd62): undefined reference to `fmt::v8::detail::throw_format_error(char const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [rgbd/CMakeFiles/joinMap.dir/build.make:154: rgbd/joinMap] Error 1
make[1]: *** [CMakeFiles/Makefile2:219: rgbd/CMakeFiles/joinMap.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
解決策:
rgbd ディレクトリ内の CMakeLists.txt ファイルが不完全です (ああ、これ~)。追加してください。
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})
find_package(Pangolin REQUIRED)
add_executable(joinMap joinMap.cpp)
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
正しい内容は次のとおりです。
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_FLAGS "-std=c++11")
———————————————
参考リンク
ch10
01
問題: g2o_viewer
ソリューションをコンパイルしてインストールします:
1. まずいくつかのライブラリをインストールします。
sudo apt-get install libsuitesparse-dev qtdeclarative5-dev qt5-qmake
sudo apt-get install libqglviewer-dev-qt5
2. g2o ライブラリ全体を再コンパイルします。
cd g2o
mkdir build #已经建立了请忽略
cd build
cmake ..
make
sudo make install
3. g2o_viewerを開く
g2o/bin ディレクトリで実行します。
~/slambook2/3rdparty/g2o/bin$ ./g2o_viewer
———————————————
参考リンク
ch12
01
問題: PCL 関連のエラー
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
-- Eigen found (include: /usr/include/eigen3, version: 3.3.7)
-- OpenNI found (version: 1.5.4.0, include: /usr/include/ni, lib: /usr/lib/libOpenNI.so;libusb::libusb)
-- OpenNI2 found (version: 2.2.0.33, include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so;libusb::libusb)
-- Could NOT find Qhull (missing: QHULL_INCLUDE_DIR)
** WARNING ** surface features related to qhull will be disabled
解決:
1. ビルドディレクトリを削除します。pcap と png に関係なく、cmake を再作成します
———————————————
参考リンク
—————————————————
02
コンパイルの問題:
This header is deprecated. Use the facilities in <boost/timer/timer.hpp> instead.
BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp>" )
方法:
将dense_mapping.cpp头文件#include <boost/timer.hpp> 改为#include <boost/timer/timer.hpp>
コンパイルの問題:
‘CV_GRAY2BGR’ was not declared in this scope
cv::cvtColor(ref, ref_show, CV_GRAY2BGR);
方法:
将所有cv::cvtColor(ref, ref_show, CV_GRAY2BGR)中CV_GRAY2BGR改为COLOR_GRAY2BGR
—————————————————
参考リンク
—————————————————
03
fmt 関連の
コンパイル問題:
dense_mapping.cpp:(.text+0x31): 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> >)'
...
解決策:
CMakeLists.txt を変更します。
find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt)
...
target_link_libraries(xxx ${xxx} ${FMT_LIBRARIES})
———————————————
04
コンパイル問題:pcl関連
...
error: ‘plus’ is not a member of ‘pcl::traits’
...
解決策:
CMakeLists.txt を変更します。
set(CMAKE_CXX_STANDARD 14)
———————————————
参考リンク
———————————————
05
コンパイルの問題: PCL 関連
surfel_mapping.cpp:31:9: error:
‘class pcl::MovingLeastSquares<pcl::PointXYZRGB, pcl::PointXYZRGBNormal>’
has no member named ‘setPolynomialFit’;
did you mean ‘setPolynomialOrder’?
解決:
注释报错行
———————————————
参考リンク
06
質問:
segmentation fault (core dumped) ./build/dense_mono/dense_mapping test_data
回避策:
1 (機能しません)
在程序中,加上头文件<Eigen/StdVector>,并将所有
vector<Eigen::??> 都改为:
vector<Eigen::??,Eigen::aligned_allocator<Eigen::??>>(不是真的问号,根据变量类型而定)
具体的には、
まずヘッダー ファイルを追加します。
#include<Eigen/StdVector>
そして、ベクトルを定義するときに次の変更を加えます。
たとえば、変更前:
vector<Eigen::Isometry3d>
変更後:
vector<Eigen::Isometry3d,Eigen::aligned_allocator<Eigen::Isometry3d>>
参考リンク
———————————————
2(無効)
~/STUDY/slambook2/ch12/dense_mono > ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-m: resident set size (kbytes) unlimited
-u: processes 31081
-n: file descriptors 1024
-l: locked-in-memory size (kbytes) 65536
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 31081
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
~/STUDY/slambook2/ch12/dense_mono > ulimit -s 102400
参考リンク
———————————————
3 (OK!)
bool update 関数には return ステートメントがありません。
(実際には、メイクプロセス中に警告が表示されますが、私は注意を払いませんでした...これが教訓です。)
[ 12%] Building CXX object dense_mono/CMakeFiles/dense_mapping.dir/dense_mapping.cpp.o
/home/wj/STUDY/slambook2/ch12/dense_mono/dense_mapping.cpp: In function ‘bool update(const cv::Mat&, const cv::Mat&, const SE3d&, cv::Mat&, cv::Mat&)’:
/home/wj/STUDY/slambook2/ch12/dense_mono/dense_mapping.cpp:290:1: warning: no return statement in function returning non-void [-Wreturn-type]
290 | }
| ^
[ 25%] Linking CXX executable dense_mapping
[ 25%] Built target dense_mapping
[ 50%] Built target surfel_mapping
[ 75%] Built target octomap_mapping
[100%] Built target pointcloud_mapping
bool update 関数本体の最後に return true を追加します (行 290 付近)。
// 对整个深度图进行更新
bool update(const Mat &ref, const Mat &curr, const SE3d &T_C_R, Mat &depth, Mat &depth_cov2) {
for (int x = boarder; x < width - boarder; x++)
for (int y = boarder; y < height - boarder; y++) {
// 遍历每个像素
if (depth_cov2.ptr<double>(y)[x] < min_cov || depth_cov2.ptr<double>(y)[x] > max_cov) // 深度已收敛或发散
continue;
// 在极线上搜索 (x,y) 的匹配
Vector2d pt_curr;
Vector2d epipolar_direction;
bool ret = epipolarSearch(
ref,
curr,
T_C_R,
Vector2d(x, y),
depth.ptr<double>(y)[x],
sqrt(depth_cov2.ptr<double>(y)[x]),
pt_curr,
epipolar_direction
);
if (ret == false) // 匹配失败
continue;
// 取消该注释以显示匹配
// showEpipolarMatch(ref, curr, Vector2d(x, y), pt_curr);
// 匹配成功,更新深度图
updateDepthFilter(Vector2d(x, y), pt_curr, T_C_R, epipolar_direction, depth, depth_cov2);
}
return true; //***这个位置***
}
もう一度実行すると、ついにうまくいきました。
ch13
01
問題: opencv のバージョンとコードを変更し、fmt ライブラリを追加し、リンク作成プロセス中にエラーを報告します。
/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: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/myslam.dir/build.make:309: ../lib/libmyslam.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:136: src/CMakeFiles/myslam.dir/all] Error 2
make: *** [Makefile:95: all] Error 2
解決策:
エラーの理由は、CMakeLists.txt 内の他のサードパーティ ライブラリが共有ライブラリであり、fmt が静的ライブラリ (libfmt.a) であるためです。(libfmt.so) を取得するには、fmt を動的に再コンパイルする必要があります。それをインストールしてください。
/STUDY/slambook2/3rdparty/fmt/build > cmake -DBUILD_SHARED_LIBS=TRUE ..
次に、ch13/build で再作成します。
~/STUDY/slambook2/ch13/build > make
[ 6%] Linking CXX shared library ../../lib/libmyslam.so
[ 75%] Built target myslam
Scanning dependencies of target test_triangulation
[ 81%] Building CXX object test/CMakeFiles/test_triangulation.dir/test_triangulation.cpp.o
[ 87%] Linking CXX executable ../../bin/test_triangulation
[ 87%] Built target test_triangulation
Scanning dependencies of target run_kitti_stereo
[ 93%] Building CXX object app/CMakeFiles/run_kitti_stereo.dir/run_kitti_stereo.cpp.o
[100%] Linking CXX executable ../../bin/run_kitti_stereo
[100%] Built target run_kitti_stereo
———————————————
参考リンク