你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

slambook2(ch3)—— Ubuntu18.04安装eigen库 + Pangolin库 + 例程演示

2021/12/31 6:02:23

Ubuntu18.04安装eigen库+例程演示

  • 安装Eigen库
  • 引用设置
    • 一、终端操作
    • 二、例程演示
      • 1、编译运行
      • 2、使用kdevelop编译运行
  • 安装Pangolin
    • 一、安装Pangolin所需依赖
    • 二、获取Pangolin源码
    • 三、检查是否安装成功
    • 四、例程演示(排错)
      • 解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
        • 1、更改配置文件
        • 2、临时解决方案(关闭终端需要重新配置)
      • 解决cannot find trajectory file at ./examples/trajectory.txt
      • 最终结果
    • 五、ch3_3.7.2显示相机位姿(P69)
      • 错误
      • 原因
      • 解决方法

安装Eigen库

直接安装

sudo apt-get install libeigen3-dev
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen

引用设置

如果需要引用对应的include目录,使用一下目录:

/usr/include/eigen3

一、终端操作

在这里插入图片描述

二、例程演示

//终端按顺序输入如下命令
//程序所在位置slambook2/ch3
 1. cd useEigen
 2. mkdir build
 3. cd build
 4. cmake ..
 5. make
 6. ./eigenMatrix

1、编译运行

结果展示
在这里插入图片描述

2、使用kdevelop编译运行

熟悉一下kdevelop
在这里插入图片描述

安装Pangolin

一、安装Pangolin所需依赖

1. sudo apt install libgl1-mesa-dev
2. sudo apt install libglew-dev
3. sudo apt install cmake
4. sudo apt install libpython2.7-dev
5. sudo apt install python-pip
6. sudo python -mpip install numpy pyopengl Pillow pybind11
7. sudo apt install pkg-config
8. sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols
9. sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev
10. sudo apt install libdc1394-22-dev libraw1394-dev
11. sudo apt install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev

二、获取Pangolin源码

默认git版本为0.6

git clone https://github.com/stevenlovegrove/Pangolin.git

三、检查是否安装成功

编译完,可以运行以下命令测试,如果显示出一个彩色立方体,并且可以通过鼠标左、右键和滚轮按住拖拽,就表示 Pangolin 安装成功了。

1. cd examples/HelloPangolin
2. ./HelloPangolin

在这里插入图片描述

四、例程演示(排错)

解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file

  原因一般有两个,一个是操作系统里确实没有包含该共享库(lib*.so.*文件)或者共享库版本不对,遇到这种情况那就去网上下载并安装上即可。

  另外一个原因就是已经安装了该共享库,但执行需要调用该共享库的程序的时候,程序按照默认共享库路径找不到该共享库文件。
在这里插入图片描述
  如上图,编译、执行示例代码时报该错,但在目录/usr/local/lib下我们可以看到libpango_core.so是存在的:

1、更改配置文件

一般安装目录在

/usr/local/lib

将该目录加入到共享库的配置文件中

 echo "/usr/local/lib" >> /etc/ld.so.conf //在新的一行中加入库文件所在目录
 ldconfig //更新/etc/ld.so.cache文件

2、临时解决方案(关闭终端需要重新配置)

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH 

本文先采用——————临时解决方案
在这里插入图片描述
在这里插入图片描述

可能是前两次添加的环境变量路径有误,重新添加下面的环境变量成功!!!!

export LD_LIBRARY_PATH=/usr/local/lib

解决cannot find trajectory file at ./examples/trajectory.txt

找不到.txt文件位置,只需在.cpp文件中进行修改文件路径即可。
在这里插入图片描述
打开KDevelop在plotTrajectory.cpp修改.txt文件位置。如下图所示:
在这里插入图片描述
注意也可以改为相对路径

string trajectory_file = "../trajectory.txt"

注意修改完后进行保存
在这里插入图片描述
进行重新编译运行!!!!!
切换到plotTrajectory所在目录

mkdir build
cd build
cmake ..
make

最终结果

在这里插入图片描述

五、ch3_3.7.2显示相机位姿(P69)

错误

报了一大堆错如下:

/usr/local/include/sigslot/signal.hpp: In member function ‘void sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::clean(sigslot::detail::slot_state*):
/usr/local/include/sigslot/signal.hpp:1504:46: error: ‘m_slots’ was not declared in this scope
         for (auto &group : detail::cow_write(m_slots)) {
                                              ^~~~~~~
/usr/local/include/sigslot/signal.hpp:1504:46: note: suggested alternative: ‘m_block’
         for (auto &group : detail::cow_write(m_slots)) {
                                              ^~~~~~~
                                              m_block
/usr/local/include/sigslot/signal.hpp: In member function ‘void sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::add_slot(sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::slot_ptr&&):
/usr/local/include/sigslot/signal.hpp:1538:42: error: ‘m_slots’ was not declared in this scope
         auto &groups = detail::cow_write(m_slots);
                                          ^~~~~~~
/usr/local/include/sigslot/signal.hpp:1538:42: note: suggested alternative: ‘m_block’
         auto &groups = detail::cow_write(m_slots);
                                          ^~~~~~~
                                          m_block
/usr/local/include/sigslot/signal.hpp: In member function ‘size_t sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::disconnect_if(Cond&&):
/usr/local/include/sigslot/signal.hpp:1560:42: error: ‘m_slots’ was not declared in this scope
         auto &groups = detail::cow_write(m_slots);
                                          ^~~~~~~
/usr/local/include/sigslot/signal.hpp:1560:42: note: suggested alternative: ‘m_block’
         auto &groups = detail::cow_write(m_slots);
                                          ^~~~~~~
                                          m_block
/usr/local/include/sigslot/signal.hpp:1564:28: error: range-based ‘for’ expression of type ‘auto’ has incomplete type
         for (auto &group : groups) {
                            ^~~~~~
/usr/local/include/sigslot/signal.hpp: In member function ‘void sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::clear():
/usr/local/include/sigslot/signal.hpp:1584:27: error: ‘m_slots’ was not declared in this scope
         detail::cow_write(m_slots).clear();
                           ^~~~~~~
/usr/local/include/sigslot/signal.hpp:1584:27: note: suggested alternative: ‘m_block’
         detail::cow_write(m_slots).clear();
                           ^~~~~~~
                           m_block
/usr/local/include/sigslot/signal.hpp: In instantiation of ‘void sigslot::signal_base< <template-parameter-1-1>, <template-parameter-1-2> >::operator()(U&& ...) [with U = {pangolin::VarState::Event}; Lockable = std::mutex; T = {pangolin::VarState::Event}]:
/usr/local/include/pangolin/var/varstate.h:264:23:   required from ‘std::map<std::__cxx11::basic_string<char>, std::shared_ptr<pangolin::VarValueGeneric> >::iterator pangolin::VarState::AddUpgradedVar(const std::shared_ptr<pangolin::VarValue<T> >&, const iterator&, bool) [with T = bool; std::map<std::__cxx11::basic_string<char>, std::shared_ptr<pangolin::VarValueGeneric> >::iterator = std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<pangolin::VarValueGeneric> > >]/usr/local/include/pangolin/var/varstate.h:205:13:   required from ‘std::shared_ptr<pangolin::VarValueGeneric> pangolin::VarState::GetOrCreateVar(const T&, const pangolin::VarMeta&) [with T = bool]/usr/local/include/pangolin/var/var.h:83:50:   required from ‘pangolin::Var<T>::Var(const T&, const pangolin::VarMeta&) [with T = bool]/usr/local/include/pangolin/var/var.h:88:35:   required from ‘pangolin::Var<T>::Var(const string&, const T&) [with T = bool; std::__cxx11::string = std::__cxx11::basic_string<char>]/usr/local/include/pangolin/display/widgets.h:153:50:   required from here
/usr/local/include/sigslot/signal.hpp:1180:65: error: ‘slots_reference’ was not declared in this scope
         cow_copy_type<list_type, Lockable> ref = slots_reference();
                                                  ~~~~~~~~~~~~~~~^~
CMakeFiles/visualizeGeometry.dir/build.make:81: recipe for target 'CMakeFiles/visualizeGeometry.dir/visualizeGeometry.cpp.o' failed
make[2]: *** [CMakeFiles/visualizeGeometry.dir/visualizeGeometry.cpp.o] Error 1
CMakeFiles/Makefile2:94: recipe for target 'CMakeFiles/visualizeGeometry.dir/all' failed
make[1]: *** [CMakeFiles/visualizeGeometry.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2

原因

原因是安装Pangolin时直接

git clone https://github.com/stevenlovegrove/Pangolin.git

此方法下载的是最新版本的Pangolin(目前是Pangolin0.6)而Pangolin0.6用的是C++17标准编译。而ORB_SLAM2 和 slambook2 的代码用的还是C++11,因此报了一大堆不明error(具体为什么恐怕得等去深入了解下C++17和C++11的区别才能说明)

解决方法

解决方法是:去https://github.com/stevenlovegrove/Pangolin找到0.5版本的Pangolin 把源码下载下来或者去进入文件夹slambook2/3rdparty安装,然后再:

解压

cd Pangolin
mkdir build && cd build
cmake ..
make -j2
sudo make install