build orb-slam3 on raspberry pi
地窖上的松 Lv1

经过小一个月的努力,终于能够在最新的树莓派 5 系统上编译通过 orb-slam3,留档一下过程

环境概述

  • 树莓派 5 系统, aikit 配件 Linux raspberrypi 6.6.31+rpt-tpi-v8 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
  • gcc 版本 12.2.0 (Debian 12.2.0-14)
  • ffmpeg 版本 5.1.6-0+deb12u1+rpt1
  • libpng-dev 版本 1.6.39-2

编译前置依赖库

OpenCV

尝试了 3.4.16, 4.2.0, 4.6.0 几个版本,最终使用4.6.0版本

在源码文件夹外新建build文件夹,使用 cmake 指令

折叠代码块 复制代码
1
cmake -D CMAKE_BUILD_TYPE=Release –D CMAKE_INSTALL_PREFIX=/home/rbpi/cpp/opencv/opencv-4.6.0/install -D WITH_FFMPEG=OFF ../opencv-4.6.0
  • error: ‘CODEC_ID_H264’ was not declared in this scope等一堆报错

    原因是 ffmpeg 版本太高,但是要降版本好像很麻烦。
    解决方法:cmake 时使用-D WITH_FFMPEG=OFF关闭 ffmpeg,会导致无法读取视频,解决方法在这

  • error: comparing the result of pointer addition ‘(src + ((sizetype)off))’ and NULL [-Werror=address]问题

    原因不明,怀疑与 gcc 版本有关
    解决方法:从报错路径找对应的flags.make文件,直接把其中的-Werror=address字段删掉,使其忽略此报错。我当时的路径是opencv-3.4.16/build/modules/core/CMakeFiles/opencv_core.dir/flags.make

image

  • error: unrecognized command-line option ‘--param=ipcp-unit-growth=100000’; did you mean ‘--param=ipa-cp-unit-growth=’?问题
    似乎和 gcc 版本有关。
    解决方法:将3rdparty/carotene/CMakeLists.txt3rdparty/carotene/hal/CMakeLists.txt中的ipcp-unit-growth全部替换成ipa-cp-unit-growth
    参考链接

  • error: ‘sleep_for’ is not a member of ‘std::this_thread’问题
    好像还是和 gcc 版本有关。
    解决方法:往报错路径文件中增加一行#include <thread>
    参考链接

  • 编译到 99%后冒出来一大堆类似error: ‘GInferListOutputs’ does not name a type GAPI_EXPORTS_W inline GInferListOutputs infer2的报错
    把 build 文件夹建在源码里面就可能会出现的神秘报错,不过 install 文件夹倒好像不影响
    解决方法: 把 build 文件夹建到 opencv 文件夹之外。
    参考链接

Eigen3

选择3.1.0版本后报错找不到 eigen,换成3.3.0版本解决,编译未出现问题。

Pangolin

一定要在 eigen3 编译完后编译,选择0.6版本,未出现问题。

  • 出现一堆找不到x264相关定义的报错
折叠代码块 复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `BZ2_bzDecompress'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_default'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_apply_profile'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_headers'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_cleanup'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_maximum_delayed_frames'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_encode'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `BZ2_bzDecompressEnd'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `BZ2_bzDecompressInit'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_reconfig'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_apply_fastfirstpass'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_delayed_frames'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_parse'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_levels'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_picture_init'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_close'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_param_default_preset'
/usr/bin/ld: ../../src/libpangolin.so: undefined reference to `x264_encoder_open_164'

原因不明,但是和用了交叉编译的ffmpeg有关。
解决方法:把交叉编译的ffmpeg删了,在文件夹里sudo make uninstall

  • error: pybind11/pybind11.h: No such file or directory问题

找不到pybind11,解决方法是自己编译一个。

折叠代码块 复制代码
1
2
3
4
5
6
7
8
git clone https://github.com/pybind/pybind11.git

cd pybind11
mkdir build
cd build
cmake ..
sudo make -j4
sudo make install
  • error: ‘numeric_limits’ is not a member of ‘std’问题

和 qt 版本有关。
解决方法:在报错对应的文件里面加上一行#include <limits>

DBoW2 和 g2o

二者都包含在 orb-slam3 源码的三方库文件夹中,编译未出现问题。

sophus

包含在源码三方库文件夹中。

  • error: array subscript ‘__Float32x4_t[0]’ is partly outside array bounds of ‘Sophus::Vector3<float> [1]’问题

    原因是 gcc 版本过高,尝试回退 gcc 至 4.8 但未起效。
    解决方法:给/usr/lib/gcc/aarch64-linux-gnu/12/include/arm_neon.h下的源码增加一行预编译指令#pragma GCC diagnostic ignored "-Warray-bounds"使其忽略此报错

编译 ORB-SLAM3

  • Cannot find -lboost_serialization问题
    缺库,sudo apt install libboost-serialization-dev

  • fatal error: openssl/md5.h: No such file or directory问题
    缺库,sudo apt install libssl-dev

运行测试视频

使用 kitti 数据集跑 demo

折叠代码块 复制代码
1
./Examples/Monocular/mono_kitti Vocabulary/ORBvoc.txt Examples/Monocular/KITTI00-02.yaml /home/raspi/cpp/dataset/data_odometry_gray/dataset/sequences/00

这是我把 kitti 数据集扔 cpp/dataset 下了

  • libpng warning: iCCP: known incorrect sRGB profile问题,读不了图片和视频
    怀疑是 libpng 与 OpenCV 版本不兼容导致。
    解决方法:使用4.6.0版本 OpenCV。

  • 出现:

    折叠代码块 复制代码
    1
    2
    3
    4
    5
    Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support
    ...
    巴拉巴拉
    ...
    If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

    解决方法:字面意思,apt install libgtk2.0-dev pkg-config 然后重新编译 OpenCV

成功运行。

也许其他还有些简单的一搜就能搜到解决方法的报错,已经不记得了