1. 查询Eigen版本
vim /usr/include/eigen3/Eigen/src/Core/util/Macros.h
Eigen版本是3.3.7
2.安装Sophus库
2.1安装fmt
git clone https://github.com/fmtlib/fmt.git
cd fmt
mkdir build
cd build
cmake ..
make
sudo make install
2.2安装Sophus
git clone https://github.com/strasdat/Sophus.git
cd Sophus/
mkdir build
cd build
cmake ..
make
sudo make install
参考链接安装Sophus库
3.原文件目录
ch4--->example--->CMakeLists.txt
--->estimated.txt
--->groundtruth.txt
--->trajectoryError.cpp
--->CMakeLists.txt
--->useSophus.cpp
4.修改文件内容
4.1 ch4 —> CMakeLists.txt
添加内容
include_directories(${Sophus_INCLUDE_DIRS})
整体内容
cmake_minimum_required(VERSION 3.0)
project(useSophus)
# 为使用 sophus,需要使用find_package命令找到它
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})
# Eigen
include_directories("/usr/include/eigen3")
add_executable(useSophus useSophus.cpp)
target_link_libraries(useSophus Sophus::Sophus)
add_subdirectory(example)
4.2 ch4—>example—>CMakeLists.txt
整体修改后的内容
#option(USE_UBUNTU_20 "Set to ON if you are using Ubuntu 20.04" OFF)
find_package(Pangolin REQUIRED)
find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt)
#if(USE_UBUNTU_20)
# message("You are using Ubuntu 20.04, fmt::fmt will be linked")
# find_package(fmt REQUIRED)
# set(FMT_LIBRARIES fmt::fmt)
#endif()
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(trajectoryError trajectoryError.cpp)
target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES})
4.3 ch4—>example—>trajectoryError.cpp
string groundtruth_file和string estimated_file的路径修改成绝对路径
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <pangolin/pangolin.h>
#include <sophus/se3.hpp>
using namespace Sophus;
using namespace std;
string groundtruth_file = "/home/yu/slam_learn/slambook2-master/ch4/example/groundtruth.txt";
string estimated_file = "/home/yu/slam_learn/slambook2-master/ch4/example/estimated.txt";
typedef vector<Sophus::SE3d, Eigen::aligned_allocator<Sophus::SE3d>> TrajectoryType;
void DrawTrajectory(const TrajectoryType >, const TrajectoryType &esti);
TrajectoryType ReadTrajectory(const string &path);
5.编译后运行
RMSE = 2.20728