Ubuntu18.04下Sophus库的安装(模板库模式)

2,313 阅读1分钟

作者: 边城量子 ( shihezichen@live.cn )

简介

笨猪主要介绍模板方式的Sophus库在Ubuntu18.04下的安装

安装Sophus

Sophus需要3.3.x及以上版本的Eigen, 因此先下载Eigen并部署。 fmt也需要下载和编译。

# Eigen3.4-rc1 下载&编译
wget https://gitlab.com/libeigen/eigen/-/archive/3.4-rc1/eigen-3.4-rc1.zip
unzip eigen*.zip
cd eigen-3.4-rc1/
mkdir build
cd build
cmake ..
sudo make install

# fmt 下载&编译
git clone  https://github.com/fmtlib/fmt.git
cd fmt\
mkdir build\
cd build\
cmake ..\
make\
sudo make install

# Sophus 下载&编译
wget https://github.com/strasdat/Sophus/archive/refs/tags/v1.0.0.zip
unzip Sophus-1.0.0.zip
cd Sophus-1.0.0
mkdir build
cd build
cmake ..
make 
sudo make install

验证安装

useSophus.cpp

#include <iostream>
#include <Eigen/Core>
#include <Eigen/Geometry>

#include "sophus/so3.hpp"
#include "sophus/se3.hpp"

using SO3Type = Sophus::SO3<double>;
using SE3Type = Sophus::SE3<double>;

using namespace std;
using namespace Eigen;

int main(int argc, char **argv) {

    // 沿z轴选装90°的旋转矩阵
    Matrix3d R = AngleAxisd(M_PI/2, Vector3d(0,0,1)).toRotationMatrix();


    // 转成四元数
    Quaterniond q(R);
    SO3Type SO3_R(R);  // 旋转矩阵转SO3
    SO3Type SO3_q(q);  // 四元数转SO3
    //
    cout << "SO(3) from atrix:\n" << SO3_R.matrix() << endl;
    cout << "SO(3) from quaternion:\n" << SO3_q.matrix() << endl;

   return 0;
}

CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED( VERSION 2.8)
PROJECT(useSophus)
FIND_PACKAGE(Sophus REQUIRED)
INCLUDE_DIRECTORIES(${Sophus_INCLUDE_DIRS})
add_executable(useSophus useSophus.cpp)

执行结果:

$ ./useSophus
SO(3) from atrix:
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