The zero-based VIO - installation configuration of Eigen and Sophus

1 Introduction

I recently started learning lesson dark blue school network "from scratch handwriting VIO", previously read "visual fourteen speak slam" and "Robotics in the state estimate," two books, just inside the mathematical derivation are very difficult practical operation is a mess. It is also taking advantage of some basic Lie algebra and matrix analysis, by means of "from scratch handwriting VIO" program, formally entered the study and practice of visual inertia odometer, share problems encountered in learning and experience. For VIO practice, all the studies are based on the change in attitude of the three-dimensional movement of the focus, so the first step you need to install the library is Sophus.

2. Overview

Operating System: Ubuntu16.04.
Compiler environment: VSCode, C ++. Introduction and installation on VSCode not repeat them here, need to focus on the project's configuration file .vscode / c_cpp_properties.json variables includePath , after studies If you need to add a new library, you need to take the path that library Add this variable.
Eigen Library: matrix library, may be linear algebra, vector, and matrix arithmetic operations such as C ++ library. Decompression can be used without using cmake.
Sophus library: support for two-dimensional motion of SO (2), SE (2 ), three-dimensional motion SO (3), SE (3 ) , etc., is developed on the basis of the Eigen library, libraries and templates are divided into non-template library here select non-template library.

3. Eigen and Sophus installation

(1) a matrix Eigen

Installation Eigen

sudo apt-get install libeigen3-dev

After completion confirmation decompression Eigen path can eigen-3.3.7 in the Eigen folder separate out, and eigen-3.3.7 under the same path (easily write the code directly using the "#include <Eigen / ...> "), to add the path includePath . I was / usr / local / the include / Eigen, . As shown below:
Here Insert Picture Description
Program header added Eigen test, for example the following code, i.e., no error installation was successful.

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

(2) Sophus Lie algebra

Download Sophus non-template class library with the following command:

git clone https://github.com/strasdat/Sophus.git

Sophus to compile (in order to avoid unnecessary trouble, best execution last installation command):

cd Sophus
git checkout a621ff
mkdir build
cmake ..
make
sudo make install

Will be compiled after the installation is complete / usr / local / include / sophus / various header files. Sophus same path to add includePath .
Here Insert Picture Description
A simple example can be used to verify Sophus.cpp:

#include <iostream>
#include <Eigen/Core>
#include "sophus/so3"

int main(){
	Eigen::Matrix3d R = Eigen::Matrix3d::Identity();
    Eigen::AngleAxisd rotation_vector(M_PI/4, Eigen::Vector3d(0,0,1));
    Sophus::Quaterniond q(R);

	return 0;
}

Note that when you compile your code, you can not simply use the g ++ Sophus.cpp -o Sophus compiled, even though the code itself does not complain, but will be prompted to Sophus not found, because the dynamic link library libSophus.so not properly linked. So there are two ways to compile.

(3) compile

g ++ mode

Use the following command:

g++ Sophus.cpp -l Sophus -o Sophus

This way only one seemingly simple command, but generally not appropriate in most cases, so imagine if there are 100 files need to be connected, the compiler can not always write that long string. . .

cmake way

New to compile cpp file in the same directory files CMakeLists.txt, the preparation of this document, so that it can automatically find the path of Sophus library. Here is what I wrote a CMakeLists.txt.

cmake_minimum_required( VERSION 2.8 )
PROJECT(DemoSophus)

FIND_PACKAGE(Sophus REQUIRED)

SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
SET(SOPHUS_INCLUDE_DIR /usr/local/include/sophus)
SET(EIGEN_INCLUDE_DIR /usr/local/include/eigen3)
SET(ALL_CODE_LIST Sophus.cpp)
SET(SOPHUS_LIBRARIES /usr/local/lib/libSophus.so)

MESSAGE(STATUS "This is binary dir: " ${DemoSophus_BINARY_DIR})
MESSAGE(STATUS "This is source dir: " ${DemoSophus_SOURCE_DIR})

INCLUDE_DIRECTORIES(${SOPHUS_INCLUDE_DIR})
ADD_EXECUTABLE(Sophus ${ALL_CODE_LIST})
TARGET_LINK_LIBRARIES(Sophus ${SOPHUS_LIBRARIES})

CMakeLists.txt to write about how I was a beginner, if required, can be easily found on the Internet cmake tutorial, here is a very simple example. This is inside the MESSAGE statement can be ignored, only to prompt information. Note that only the SET statement, the first custom variable name (the name at random, after the name represents the path behind), then the path to completion, please see the path to those files corresponding to yourself. Next, use cmake to compile it.

mkdir build
cd build
cmake ..
make

Finally, in the build folder, it will generate the corresponding executable file Sophus.
Here Insert Picture Description

4. Conclusion

I also did not know the beginning there cmake this way can be compiled, the usual practice of using g ++ mode, experience installation problems Sophus library also took some effort, fishes cmake understand a little bit, here in this simple example record the entire installation process. After more than a need to compile a file, you slowly come to realize at the convenience of cmake.

Released two original articles · won praise 0 · Views 127

Guess you like

Origin blog.csdn.net/EternalGlory_wx/article/details/104423759