首先查看安装的eigen库的版本号,因为slam十四讲(第二版)中安装的为模板类Sophus,该sophus对eigen库的版本有要求,如果你有3.3以下的版本的eigen,那么请先卸载:
sudo rm -rf /usr/include/eigen3 /usr/lib/cmake/eigen3 /usr/share/doc/libeigen3-dev /usr/share/pkgconfig/eigen3.pc /var/lib/dpkg/info/libeigen3-dev.list /var/lib/dpkg/info/libeigen3-dev.md5sums
输入以下命令查看eigen版本。
cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h
#或者
cat /usr/local/include/eigen3/Eigen/src/Core/util/Macros.h
输入以下命令查看eigen版本。
locate eigen3
安装eigen3.3以上版本(这里查看得到的版本号为3.3.4,注意3.2系列的不可以!!!)
如果版本太低去官网下载安装,具体步骤如下:
eigen-版本号.tar.bz2
,然后提取到此处eigen-版本号
,右键在终端打开。mkdir build
cd build
cmake ..
sudo make install
注意,如果看网上的其他教程可能会出错,因为大部分教程是根据第一版的书,使用的是非模板类,但是这里使用的是模板类的sophus
git clone https://github.com/strasdat/Sophus.git
cd Sophus/
mkdir build
cd build
cmake ..
make
sudo make install
在安装模板类的sophus库时可能出现没有安装“fmt”库提示
,如下图所示:
git clone https://github.com/fmtlib/fmt.git
cd fmt
mkdir build
cd build
cmake ..
make
sudo make install
/home/sfann/sf_slam_temp_code/ch4/build> /home/sfann/sf_slam_temp_code/ch4/build/useSophus
SO(3) from matrix:
2.22045e-16 -1 0
1 2.22045e-16 0
0 0 1
SO(3) from quaternion:
2.22045e-16 -1 0
1 2.22045e-16 0
0 0 1
they are equal
so3 = 0 0 1.5708
so3 hat=
0 -1.5708 0
1.5708 0 -0
-0 0 0
so3 hat vee= 0 0 1.5708
SO3 updated =
0 -1 0
1 0 -0.0001
0.0001 2.03288e-20 1
*******************************
SE3 from R,t=
2.22045e-16 -1 0 1
1 2.22045e-16 0 0
0 0 1 0
0 0 0 1
SE3 from q,t=
2.22045e-16 -1 0 1
1 2.22045e-16 0 0
0 0 1 0
0 0 0 1
se3 = 0.785398 -0.785398 0 0 0 1.5708
se3 hat =
0 -1.5708 0 0.785398
1.5708 0 -0 -0.785398
-0 0 0 0
0 0 0 0
se3 hat vee = 0.785398 -0.785398 0 0 0 1.5708
SE3 updated =
2.22045e-16 -1 0 1.0001
1 2.22045e-16 0 0
0 0 1 0
0 0 0 1
*** 已完成 ***
1.运行ch4的example报错
:
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘fmt::v8::detail::error_handler::on_error(char const*)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail13error_handler8on_errorEPKc[_ZN3fmt2v86detail13error_handler8on_errorEPKc]+0x8):对‘fmt::v8::detail::throw_format_error(char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘std::make_unsigned<long>::type fmt::v8::detail::to_unsigned<long>(long)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_]+0x21):对‘fmt::v8::detail::assert_fail(char const*, int, char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<int>(int)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_]+0x1f):对‘fmt::v8::detail::assert_fail(char const*, int, char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘Sophus::SO3Base<Sophus::SO3<double, 0> >::logAndTheta() const’中:
trajectoryError.cpp:(.text._ZNK6Sophus7SO3BaseINS_3SO3IdLi0EEEE11logAndThetaEv[_ZNK6Sophus7SO3BaseINS_3SO3IdLi0EEEE11logAndThetaEv]+0x200):对‘fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)’未定义的引用
target_link_libraries(trajectoryError ${Sophus_LIBRARIES} fmt)
trajectoryError依赖于Sophus,Sophus依赖于fmt。
报错:
trajectory ./example/groundtruth.txt not found.
trajectory ./example/estimated.txt not found.
trajectoryError: /home/haha/slambook2/ch4/example/trajectoryError.cpp:22: int main(int, char**): Assertion `!groundtruth.empty() && !estimated.empty()' failed.
已放弃 (核心已转储)
还是trajectoryError.cpp中地址的问题。
解决办法:
我们打开源码trajectoryError.cpp
把本来写的是 ./examples/groundtruth.txt
改成../../examples/groundtruth.txt
因为你观察外边的目录结构,就发现这个txt文件是存在examples下面的,但是呢你使用KDevelop执行的时候,是在examples/build
下执行的,所以要先退出build 再退出examples 然后 /examples/groundtruth.txt
即:
string groundtruth_file = "../../example/groundtruth.txt";
string estimated_file = "../../example/estimated.txt";