首页 Orb_slam2_rgbd_dense_map Ubuntu20.04编译运行
文章
取消

Orb_slam2_rgbd_dense_map Ubuntu20.04编译运行

运行环境:ubuntu20.04 pangolin 0.5(强烈推荐) eigen3.3.7(没装 就装3.2的) opencv4.6

代码下载

https://github.com/xiaobainixi/ORB-SLAM2_RGBD_DENSE_MAP.git

需要到原来的仓库 下载 Vocabulary/ 下的 ORBvoc.txt.tar.gz,下载下来解压,最好也是放在同样的路径。

相关环境

Pangolin 0.5

1
git clone -b v0.5 https://github.com/stevenlovegrove/Pangolin.git

需要修改的内容,参考 https://blog.csdn.net/weixin_54347747/article/details/126659089

1.error: ‘AV_PIX_FMT_XVMC_MPEG2_MC’ was not declared in this scope

参考:https://github.com/stevenlovegrove/Pangolin/pull/318/files?diff=split&w=0

解决办法:在/Pangolin/CMakeModules/FindFFMPEG.cmake中63,64行

1
2
3
4
sizeof(AVFormatContext::max_analyze_duration2);
}" HAVE_FFMPEG_MAX_ANALYZE_DURATION2换成
sizeof(AVFormatContext::max_analyze_duration);
}" HAVE_FFMPEG_MAX_ANALYZE_DURATION

/Pangolin/src/video/drivers/ffmpeg.cpp中第37行 namespace pangolin上面加上

#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER 第78,79行 TEST_PIX_FMT_RETURN(XVMC_MPEG2_MC); TEST_PIX_FMT_RETURN(XVMC_MPEG2_IDCT);

改为

1
2
3
4
#ifdef FF_API_XVMC
    TEST_PIX_FMT_RETURN(XVMC_MPEG2_MC);
    TEST_PIX_FMT_RETURN(XVMC_MPEG2_IDCT);
#endif

101-105行改为

1
2
3
4
5
6
7
#ifdef FF_API_VDPAU
    TEST_PIX_FMT_RETURN(VDPAU_H264);
    TEST_PIX_FMT_RETURN(VDPAU_MPEG1);
    TEST_PIX_FMT_RETURN(VDPAU_MPEG2);
    TEST_PIX_FMT_RETURN(VDPAU_WMV3);
    TEST_PIX_FMT_RETURN(VDPAU_VC1);
#endif

127行改为

1
2
3
#ifdef FF_API_VDPAU
    TEST_PIX_FMT_RETURN(VDPAU_MPEG4);
#endif

2.error: ‘AVFMT_RAWPICTURE’ was not declared in this scope

解决办法,在Pangolin/include/pangolin/video/drivers/ffmpeg.h开头加上

1
2
3
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

参考: https://www.jianshu.com/p/da49a712410f

Opencv 3.4

编译安装略

Eigen 3.3.3

这个版本好像无所谓 网上说要3.2.10 不过3.3.3的最后也成功了

pcl 1.10

一开始用的1.13,后来还是用1.10了

卸载1.13 locate pcl-1.13 所有相关的文件夹删了即可

1
sudo apt install libpcl-dev pcl-tools

ubuntu20 装的是1.10

用了1.10 好像cmakelists中要加上ADD_COMPILE_OPTIONS(-std=c++14 )

报错问题

解决segamentation fault 相关的修改

  1. ORBSLAM的Cmakelists中的 -march=native 以及 g2o 的cmakelists中的 -march=native 删了
  2. 将include下的pointcloudmapping.h文件中bool loopbusy修改为bool loopbusy=false // 可以解决点云viewer只有坐标的问题
  3. 找到点云相关的两个文件 pointcloudmapping.hpointcloudmapping.cc 修改内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    PointCloudMapping::PointCloudMapping(double resolution_)
    {
        this->resolution = resolution_;
        voxel.setLeafSize( resolution, resolution, resolution);
        globalMap = boost::make_shared< PointCloud >( );//初始化失败 需要修改初始化内容
       
        viewerThread = make_shared<thread>( bind(&PointCloudMapping::viewer, this ) );
    }
       
    void PointCloudMapping::viewer(){
    //...
    while(1){
    //...
        for ( size_t i=lastKeyframeSize; i<N ; i++ ){  
             PointCloud::Ptr p = generatePointCloud( keyframes[i], colorImgs[i], depthImgs[i] );          
             *globalMap += *p; //内存溢出   
        }
        PointCloud::Ptr tmp(new PointCloud());//请注释掉
        voxel.setInputCloud( globalMap );//请注释掉
        voxel.filter( *tmp );//请注释掉
        globalMap->swap( *tmp );//请注释掉
        viewer.showCloud( globalMap );
    }
    }
    

    出错原因是 ` *globalMap += *p` 这一步内存溢出了

    在cc文件中 注释掉globalMap = boost::make_shared< PointCloud >( );

    在h文件中直接初始化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    class PointCloudMapping
    {
    public:
     //...
       
    protected:
     //...
        PointCloud::Ptr globalMap=PointCloud::Ptr(new PointCloud);//直接初始化
    };
    

报错:std::map must have the same value_type as its allocator

loopclosing.h中修改:

1
2
3
typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
        Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;

改成:

1
2
3
    typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
            Eigen::aligned_allocator<std::pair<KeyFrame* const, g2o::Sim3> > > KeyFrameAndPose;

编译运行

给予 build.sh 执行权限

1
chmod +x  build.sh

也可以自己分别在 Thirdparty下 先编译 DBoW2 再编译 g2o, 最后在根目录编译orb-slam2,之前的修改过后,应该就没啥问题了

运行: 执行文件 orbvoc.txt TUMX.yaml 数据集文件夹 associations.txt

1
./bin/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml ~/CODE/Datasets/rgbd_dataset_freiburg1_360 Examples/RGB-D/associations.txt 

数据集随便下载的一个 tum http://vision.in.tum.de/data/datasets/rgbd-dataset/download rgbd_dataset_freiburg1_360

image-20221125094845386

tum1.yuml 对应的是 数据集名称中 freibug1;

associations.txt是通过examples/rgb-d下的python脚本生成的

1
python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt

这里的python脚本好像会报一个 dict对象没有 remove,加个list转换即可。

1
2
    first_keys = list(first_list.keys())
    second_keys = list(second_list.keys())

稠密点云结果

image-20221125095414145

RK3588小车

用mobaxterm远程连接RK3588小车,测试数据集,可以正常得到点云图,最后保存pcd文件

虚拟机上基本不会出现segmentation fault,小车上还是会偶尔出现,但多试几次就成功了,暂时没找到解决方案

image-20230103110123210

三维点云地图转为三维栅格地图

用于路径规划

先下载 代码 :

1
2
3
4
5
6
git clone https://github.com/OctoMap/octomap
cd octomap
mkdir build
cd build
cmake ..
make

Binaries and libs will end up in the directories bin and lib of the top-level directory where you started the build.

再下载简单易用的工具代码: https://github.com/gaoxiang12/octomap_tutor

再修改:cmake_modules/octomap-config.cmake 里面的 路径 就刚下的那个,修改完后 ./build.sh 编译一下;

原文件:

1
2
3
4
5
6
7
8
9
set(OCTOMAP_INCLUDE_DIRS "/home/zero/Documents/code/octomap/octomap/include")
set(OCTOMAP_LIBRARY_DIRS "/home/zero/Documents/code/octomap/lib")
 

# Set library names as absolute paths:
set(OCTOMAP_LIBRARIES
  "/home/zero/Documents/code/octomap/lib/liboctomap.so"
  "/home/zero/Documents/code/octomap/lib/liboctomath.so"
)

依葫芦画瓢,改一下路径就行

使用:

1
Usage: bin/pcd2octomap bin/pcd2colorOctomap bin/joinmap

Example: bin/pcd2octomap data/sample.pcd data/sample.bt -convert the sample pcd file to octomap file bin/pcd2colorOctomap data/sample.pcd data/sample.bt -convert the sample pcd file to color octomap file bin/joinmap - join the maps defined in data/keyframe.txt

使用结果:

1
./bin/pcd2colorOctomap result.pcd result.ot // 将有的pcd文件转化为 指定的 result.ot文件

通过 octovis (在之前那个bin里面有个可执行文件)来查看 // ot是彩色的 bt是纯色的

image-20221125102808319

三维点云转为二维栅格地图

git代码,放到工作空间ros_ws/src下

git clone -b develop  https://github.com/Hinson-A/pcd2pgm_package
cd ..
catkin_make

修改launch中run.launch 存放pcd文件的路径 pcd文件名称, 选取范围,这里的数据集 选了-3到3 (目前还不太清楚这里的单位是什么…)

安装map_server

sudo apt-get install ros-noetic-map-server

启动转换程序

roslaunch pcd2pgm run.launch

这时 可以查看 rviz 订阅 map话题 查看地图 // 这里换了个数据集,换了个地板的数据集进行测试rgbd_dataset_freiburg1_floor

img

保存地图

rosrun map_server map_saver

遇到的问题

如果只有opencv4 会报找不到opencv

将报错的cmakelists中 find_package(OpenCV 3.0 QUIET)

DBoW2和最外面的两个cmakelists文件

改成:

1
2
set(OpenCV_DIR  /opt/opencv-4.6.0/build)
find_package(OpenCV REQUIRED)

不过建议用opencv3,不然后续要改的文件挺多的

vtk相关的问题

1
2
3
The imported target "vtk" references the file
   "/usr/bin/vtk"
but this file does not exist

会报一些 vtk相关的问题,这里只处理了该问题,创建了一个软链接 sudo ln -s /usr/bin/vtk7 /usr/bin/vtk,这些警告好像不处理也没有关系。

opencv4和orb-slam2的一些命名冲突

一开始用的是opencv4,照着改最终可以通过编译运行,简单些,直接用opencv3

原文链接:https://blog.csdn.net/weixin_51404664/article/details/124184774


错误:‘CvMat’ has not been declared/‘CV_GRAY2BGR’ was not declared in this scope error: ‘CV_RGB2GRAY’ was not declared in this scope 方法:添加 #include <opencv2/imgproc/types_c.h> 修改文件: sim3Solver.cc PnPsolver.h FrameDrawer.cc


1
2
没有那个文件或目录 26 | #include <opencv/cv.h>
方法: ORBextractor.h中 #include <opencv/cv.h>改为#include <opencv2/imgproc.hpp>

1
2
错误 ‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope119 | imLeft = cv::imread(vstrImageLeft[ni],CV_LOAD_IMAGE_UNCHANGED);
解决办法:往指定文件添加头文件 #include "opencv2/imgcodecs/legacy/constants_c.h"

要加的文件有 stereo_euroc.cc mono_kitti.cc mono_tum.cc mono_euroc.cc stereo_kitti.cc rgbd_tum.cc

octomap_tutor 报错 error: #error PCL requires C++14 or above

cmakelists 中:

1
2
SET(CMAKE_CXX_FLAGS -std=c++11) // 下面加一行代码
set(CMAKE_CXX_STANDARD 14)
本文由作者按照 CC BY 4.0 进行授权

Rk3588 Arm架构安装opencv4 Unable to locate libjasper Dev

安装多版本eigen3以及切换