《SLAM十四讲》slambook2 遇到的坑

《SLAM十四讲》slambook2 遇到的坑

ch5

01
安装opencv时,正常安装后便可以使用,注意检查CmakeLists.txt文件有没有搜索包含opencv库

02
问题:在编译高博的视觉SLAM十四讲第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、删除build目录。重新cmake,不管pcap和png

————————————————
参考链接
————————————————
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 时做如下修改:
比如修改前:

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 语句。
(其实在make过程中有warnning,我没注意…这就是教训了。)

[ 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函数体最后(290行附近)添加 return true;

// 对整个深度图进行更新
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库,make 链接过程报错!

/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),需要对重新对fmt进行动态编译,得到(libfmt.so)再进行安装。

/STUDY/slambook2/3rdparty/fmt/build > cmake -DBUILD_SHARED_LIBS=TRUE .. 

再在ch13/build下重新make:

~/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

————————————————
参考链接

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WoooChi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值