Ubuntu runs through ORB_SLAM2 and its ORBSLAM2_with_pointcloud dense mapping from zero to one

Table of contents

foreword

1 Install ubuntu18.04.6

1.1 Questions

①After the successful installation of ubuntu, the window interface will not match, and the problem of copying and pasting between Ubuntu and windows will appear

②swapon: /swapfile: Failed to read swap header

2 cmake and compilation basic environment installation

3 Install Eigen 3.2.10

4 Install Pangolin 0.5   

5 Install OpenCV 3.4.7

5.1 Questions

① Error: fatal error: Eigen/Core: No such file or directory

6 Run ORB_SLAM2

6.1 Questions

① Error: c++: internal compiler error: killed (program cc1plus)

② error: ‘usleep’ was not declared in this scope

7 Install and run Dr. Gao Xiang's dense map ORBSLAM2_with_pointcloud_ map version

7.1 Questions

①报错:error: no matching function for call to ‘g2o::SE2::setRotation (Eigen::Rotation2D::Scalar

②error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_ TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

③error: static assertion failed: FLOATING_POINT_ARGUMENT_PASSED__ INTEGER_WAS_EXPECTED’ is not a member of ‘Eigen::internal::static_asse

④Could not find a configuration file for package "OpenCV" that is compatible with requested version "2.4.3"

⑤Could not find a package configuration file provided by "Qt5X11Extras" with any of the following names:

⑥Could not find a package configuration file provided by "Qt5UiPlugin" with a

⑦error while loading shared libraries: libvtkgl2ps-7.1.so.1: cannot open shared object file: No such file or directory

⑧double free or corruption (out) Abandoned (core dumped)

8 summary

reference blog


foreword

        Although the ORB_SLAM2 algorithm is classic, the environment deployment is very troublesome. I used the Ubuntu20.04 version installed on the virtual machine to suffer a lot, and finally ran through ORB_SLAM2, and also solved all the compilation errors of the ORB_SLAM2 dense map version, but finally fell in Fixed a segfault when running the dense mapping ORBSLAM2_with_pointcloud version. Segmentation error, it is difficult to solve without understanding the code (the solutions mentioned on the Internet are almost the same), I am too good, and I want to see the effect of running first, so I have no choice but to reinstall the system and use Ubuntu18.04 Try it out and try to keep all libraries and packages consistent with the relevant tutorials. However, I feel that configuring the environment is not a one-time success, so I will make a record. The next time the environment is configured, it will be faster, and I will also serve as a reference for everyone.

        Unfortunately, there was still a segfault in the end, and the Eigen version was changed to 3.2.10 before it succeeded. In fact, the issue on github has already suggested that eigen3.2.10 should be installed, but I have been obsessed with online blogs, which caused my eyes to be dazzled. If other ubuntu versions encounter segment errors, you can try to replace the eigen version with 3.2.10

1 Install ubuntu18.04.6

         ubuntu mirror source (the webpage display may have problems when downloading, but the download speed is fast but not displayed) : Index of /ubuntu-releases/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

        There is basically no problem with this part, just follow the tutorials on the Internet step by step to ensure that the network is smooth. Pay attention to the following points during the process.

        ①In order to obtain Chinese support conveniently, it is recommended to choose custom installation

        ②The hard disk space should be larger (more than 50G is recommended, I set 80G), and then you need to set up swap space and install various libraries and software packages

        ③Network selection NAT mode

        ④In the installation process, keep the network unblocked, do not click skip to skip, the system will crash (don’t ask me why I know..)

        ⑤ Change the source ( you can copy and paste after solving the problem ① , otherwise it will be very troublesome), there are many sources on the Internet, I suggest you try them all, and find the fastest one. The fastest one I tested is from the University of Science and Technology of China. source

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup #备份

sudo gedit /etc/apt/sources.list #打开之后,复制镜像源

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

sudo apt-get update #查看更新快不快,有没有报错,有的话,再换镜像源

       ⑥Increase the swap space, there are many online tutorials, but there are always almost less. . .

        (1) Enter the root directory first, and then close all swap spaces

cd / #进入根目录
sudo swapoff -a

        (2) Add 8G to 16G swap space (the 8G compiled dense map version collapsed)

sudo dd if=/dev/zero of=/swapfile bs=1G count=16

        (3) Set /swapfile permissions

sudo chmod 600 /swapfile

        (4) Format swap space

sudo mkswap /swapfile

        (5) Activation of the swap space is complete

sudo swapon /swapfile

        (6) View the size of the swap space

free -h

1.1 Questions

①After the successful installation of ubuntu, the window interface will not match, and the problem of copying and pasting between Ubuntu and windows will appear

         Solution: Enter the following command in the terminal to download vm-tool to solve

sudo apt-get update #不更新软件列表,无法下载软件

sudo apt-get install open-vm-tools -y

sudo apt-get install open-vm-tools-desktop -y

sudo reboot #重启

②swapon: /swapfile: Failed to read swap header

        Solution: format /swapfile first, then activate /swapfile

sudo mkswap /swapfile #格式化
sudo swapon /swapfile #激活

2 cmake and compilation basic environment installation

        ①Install gcc g++

sudo apt-get install gcc g++

        ②Install cmake, it is too troublesome to download the source code installation, I choose the command line installation, although it is a bit old, but it is suitable for the compilation of ORB_SLAM2 algorithm related packages

sudo apt-get install cmake

3 Install Eigen 3.2.10

        Error demonstration:

       ①Install Eigen, the online tutorial says to install 3.1~3.2 from the source code, but I tried it in ubuntu20 version, changing the version can not solve the problem of segmentation error, so save trouble, install it directly from the command line  

         ②Set soft link

          At the end of the run, I found that there was still a segment error, and I still needed to install version 3.2.10 from the source code.

        Correct example:

        Download address:  Eigen    

         ① After downloading and decompressing, enter the source code folder

mkdir build
cd build
cmake..
sudo make install
sudo cp -r /usr/local/include/eigen3 /usr/include

        ②View the current version

pkg-config --modversion eigen3

4 Install Pangolin 0.5   

       Source address: https://github.com/stevenlovegrove/Pangolin/releases/tag/v0.5

        ① Install dependencies

sudo apt-get install libglew-dev libpython2.7-dev

        ②The terminal enters the source code folder, and then the old

mkdir build
cd build
cmake ..
make -j4
sudo make install

5 Install OpenCV 3.4.7

        Source address: https://github.com/opencv/opencv  If you choose a lower version, there will be fewer errors

        ① Install dependencies

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran

       ②The terminal enters the source code folder and installs opencv

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j4 
sudo make install

        ③(1) Configure the environment and modify the configuration file

sudo gedit /etc/ld.so.conf.d/opencv.conf

         (2) It may be an empty file, but don’t worry, just fill in /usr/local/lib in it

 /usr/local/lib

        (3) Execute ldconfig to update the configuration

sudo ldconfig 

        ④ (1) configure bash

sudo gedit /etc/bash.bashrc

          (2) Add the following statement at the end of the file content, save and exit

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

          (3) update bash

source /etc/bash.bashrc

        ⑤ Enter opencv-3.4.7/samples/cpp/example_cmake, compile the routine test, get hello opencv, then the installation is successful

cmake .
make
./opencv_example

5.1 Questions

① Error: fatal error: Eigen/Core: No such file or directory

        Solution: Install eigen, if installed, set a soft link

sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen

6 Run ORB_SLAM2

        Source address: You can directly git clone to download GitHub - raulmur/ORB_SLAM2: Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities

        ①The terminal enters the source code folder and checks whether build.sh has executable permissions. I am rude and directly give all permissions to 777

chmod 777 ./build.sh

        ② Execute build.sh, install ORB_SLAM2 related dependencies, and generate executable files mono_tum, etc.

./build.sh

        ③ Run TUM's f1_xyz data set, easy to get 

TUM dataset: Computer Vision Group - Dataset Download

KITTI Dataset: The KITTI Vision Benchmark Suite

EuRoC dataset: kmavvisualinertialdatasets – ASL Datasets

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml data/rgbd_dataset_freiburg1_xyz/

6.1 Questions

① Error: c++: internal compiler error: killed (program cc1plus)

        Solution: Insufficient running memory needs to increase the swap space. For specific steps, see ⑥ in article 1 : Increase the swap space.

② error: ‘usleep’ was not declared in this scope

        Solution: Add #include <unistd.h> to the header file of the error program , add it one by one, this is the only way (but I don’t know why, I only added it in system.h, and all the error reports are gone up)

#include <unistd.h>

7 Install and run Dr. Gao Xiang's dense map ORBSLAM2_with_pointcloud_ map version

        Source address: GitHub - gaoxiang12/ORBSLAM2_with_pointcloud_map  , git is recommended

        This step is the most difficult step. I have been tossing for a long time on Ubuntu20. The main reason is that there is a segment error, which is very uncomfortable. The improved algorithm has more dense mapping, so you need to use the point cloud library PCL, and its supporting VTK visualization tool. There are different opinions on the choice of this version, some say to use the latest one, and some say to use the old 1.7, 1.8. In the end, I chose PCL1.8.1. I tried the command line installation for the first time, but it seemed that the version was too low, which caused the compilation to crash, so I checked it on the Internet. PCL1.8.1 corresponds to VTK version 7.1.1, and only the energy code can be used to install VTK. up

        ①Install VTK7.1.1

        Download address: https://www.vtk.org/files/release/7.1/VTK-7.1.1.zip

        (1) Install related dependencies

sudo apt-get install git build-essential linux-libc-dev cmake cmake-gui libusb-1.0-0-dev libusb-dev libudev-dev mpi-default-dev openmpi-bin openmpi-common libflann1.9 libflann-dev libeigen3-dev libboost-all-dev libvtk6.3-qt libvtk6.3 libvtk6-dev libqhull* libgtest-dev freeglut3-dev pkg-config libxmu-dev libxi-dev mono-complete openjdk-8-jdk openjdk-8-jre libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev

        (2) Install qt5 and its related tools (you know, I still like command line installation, and I will never turn back if there is no problem)

sudo apt-get install qt5-default qtcreator qttools5-dev libqt5x11extras5-dev

        (3) Enter the VTK source code folder and compile VTK

mkdir build && cd build
cmake ..
cmake-gui      ###操作见下面文字及图片###
make -j4
sudo make install

        Select the build folder path, then check "VTK_GROUP_QT", click Configure in the lower left corner, and an error is reported. Enter "VTK_QT_VERSION" = 5 in the error position, and then click Configure, Generate, and it will appear Configuring done,
Generating done

         (4) Configure environment variables (environment variables need to be added for source code installation disadvantages)

#sudo gedit /home/用户名/.bashrc
#简便方法,用~代替
sudo gedit ~/.bashrc
#添加下面的内容
#export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
#更新.bashrc
source ~/.bashrc

#添加环境变量
sudo sh -c "echo '/usr/lib/x86_64-linux-gnu' >> /etc/ld.so.conf"
#更新
sudo sh -c "ldconfig"

        ②Install PCL

Source address: https://github.com/PointCloudLibrary/pcl , select 1.8.1 tag to download

        (1) Install related dependencies. I integrated the dependencies of PCL and VTK. The step of installing VTK from the source code is unnecessary.

sudo apt-get install git build-essential linux-libc-dev cmake cmake-gui libusb-1.0-0-dev libusb-dev libudev-dev mpi-default-dev openmpi-bin openmpi-common libflann1.9 libflann-dev libeigen3-dev libboost-all-dev libvtk6.3-qt libvtk6.3 libvtk6-dev libqhull* libgtest-dev freeglut3-dev pkg-config libxmu-dev libxi-dev mono-complete openjdk-8-jdk openjdk-8-jre libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev

        (2) The terminal enters the PCL source code folder, compiles and installs

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr \ -DBUILD_GPU=ON-DBUILD_apps=ON -DBUILD_examples=ON \ -DCMAKE_INSTALL_PREFIX=/usr .. 
make -j4  
sudo make install

        (3) Install openni visualization library dependencies

sudo apt-get install libopenni-dev 
sudo apt-get install libopenni2-dev

        (4) Find a place to create a new folder, create main.cc and CMakeLists.txt in the folder, and perform cmake compilation test

        main.cc

#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
 
 
int main(int argc, char **argv) {
    std::cout << "Test PCL !!!" << std::endl;
    
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
    uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
      for (float angle(0.0); angle <= 360.0; angle += 5.0)
      {
	pcl::PointXYZRGB point;
	point.x = 0.5 * cosf (pcl::deg2rad(angle));
	point.y = sinf (pcl::deg2rad(angle));
	point.z = z;
	uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
		static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
	point.rgb = *reinterpret_cast<float*>(&rgb);
	point_cloud_ptr->points.push_back (point);
      }
      if (z < 0.0)
      {
	r -= 12;
	g += 12;
      }
      else
      {
	g -= 12;
	b += 12;
      }
    }
    point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
    point_cloud_ptr->height = 1;
    
    pcl::visualization::CloudViewer viewer ("test");
    viewer.showCloud(point_cloud_ptr);
    while (!viewer.wasStopped()){ };
    return 0;
}

        CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
project(pcl_test)
 
find_package(PCL 1.2 REQUIRED)
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
 
add_executable(pcl_test 
                main.cc)
 
target_link_libraries (pcl_test ${PCL_LIBRARIES})
 
install(TARGETS pcl_test RUNTIME DESTINATION bin)

        Enter ./pcl_test in the folder, if the following window appears, the pcl installation is successful

./pcl_test 

         ② Compile g2o_with_orbslam2

        In order not to increase the length of the article, please read the questions ①②③ and modify 9 in turn (you can also compile it directly, and modify it after the error is displayed) (dog head expression)

        then same old

mkdir build
cmake ..
make -j4
sudo make install

        ③Compile ORB_SLAM2_modified

        (1) Enter the ORB_SLAM2_modified folder and give build.sh executable permission

chmod 777 build.sh

        (2) Modify CmakeLists.txt

#将      12行,13行中的-march=native删掉,33行换掉opencv版本
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3   -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall   -O3   -march=native")

find_package(OpenCV 2.3.7 REQUIRED)

#改为
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3   -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall   -O3   -march=native")

find_package(OpenCV 3.4.7 REQUIRED)

        (3) Execute build.sh

./build.sh

        ④Run ORBSLAM2_with_pointcloud_map

        (1) In order to generate the corresponding executable file in Exmaple, because generating point cloud requires depth, it is necessary to generate a txt file combining rgb and depth, associate.py download address

#  PATH_TO_SEQUENCE为下载的TUM数据集路径,rgb.txt为数据集自带
python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt

        (2) Copy the dictionary, Dr. Gao Xiang's Vocabulary does not have ORBvoc.txt, you need to copy the ORB_SLAM2

         (3) Run the program

# PATH_TO_SEQUENCE_FOLDER 为数据集路径,我的为data/rgbd_dataset_freiburg1_xyz/
# ASSOCIATIONS_FILE为associate.py生成的txt文件路径
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUMX.yaml PATH_TO_SEQUENCE_FOLDER ASSOCIATIONS_FILE

        (4) End the flowers

       ⑤ Save the point cloud

        (1) Modify the ORB_SLAM2_modified/pointcloudmapping.cc file:
                  Add the header file #include <pcl/io/pcd_io.h>
                  in the file 126 lines void PointCloudMapping::viewer(), add two lines of code after the end of while (1)

pcl::io::savePCDFile("result.pcd", *globalMap);
cout << "Final result saved." << endl;

        (2) Recompile ORB_SLAM2_modified, and then run it to generate result.pcd

          (3) Terminal input commands to view point cloud files

pcl_viewer result.pcd 

7.1 Questions

①报错:error: no matching function for call to ‘g2o::SE2::setRotation (Eigen::Rotation2D<double>::Scalar

Solution: modify g2o_with_orbslam2/g2o/types/slam2d/edge_se2_pointxy_bearing.cpp, line 51

将
t.setRotation(t.rotation().angle()+_measurement);
改为
t.setRotation((Eigen::Rotation2Dd)(t.rotation().angle()+_measurement));

②error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_ TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

        Solution: Modify g2o_with_orbslam2/g2o/solvers/linear_solver_eigen.h, line 54

将
typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, SparseMatrix::Index> PermutationMatrix;
改为
typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> PermutationMatrix;

③error: static assertion failed: FLOATING_POINT_ARGUMENT_PASSED__ INTEGER_WAS_EXPECTED’ is not a member of ‘Eigen::internal::static_asse

        Solution: modify g2o_with_orbslam2/g2o/solvers/linear_solver_eigen.h, line 80

将
VectorXd probLimits(MO_NUM_ELEMS);
      for (int i = 0; i < probLimits.size(); ++i)
        probLimits[i] = (i + 1) / (double) MO_NUM_ELEMS;
改为
VectorXd probLimits;
      probLimits.resize(MO_NUM_ELEMS);
      for (int i = 0; i < probLimits.size(); ++i)
        probLimits[i] = (i + 1) / (double) MO_NUM_ELEMS;

④Could not find a configuration file for package "OpenCV" that is compatible with requested version "2.4.3"

        Solution: Modify find_package (OpenCV 2.4.3 REQUIRED) in CmakeLists.txt to your own version

⑤Could not find a package configuration file provided by "Qt5X11Extras" with any of the following names:

        Solution: sudo apt install libqt5x11extras5-dev

⑥Could not find a package configuration file provided by "Qt5UiPlugin" with a

        Solution: sudo apt-get install qttools5-dev

⑦error while loading shared libraries: libvtkgl2ps-7.1.so.1: cannot open shared object file: No such file or directory

        Solution: There are many problems with source code installation, you need to add it to the environment variable by yourself

⑧double free or corruption (out) Abandoned (core dumped)

        Solution: Change the eigen version to 3.2.1       

8 summary

        After going around and around, I finally started running. The enemy of segfaults for life, I still have to learn how to use the compilation tool to check the location of segfaults. In the latter case, after studying ROS in depth, try to use ROS to run ORB_SLAM2.

reference blog

orb_slam nanny-level environment installation and configuration tutorial from scratch - Quantum and Tai Chi - Blog Park

Ubuntu18.04 changes domestic mirror sources (Aliyun, Netease, Tsinghua University, University of Science and Technology of China)

Compile and install OpenCV on Ubuntu in one article (with a link to the network disk) - Programmer Sought

Installation and testing of pcl1.8 under ubuntu

https://www.jianshu.com/p/548234bb88fc

Uninstall and reinstall Eigen3

Guess you like

Origin blog.csdn.net/weixin_46596757/article/details/127528792