【分享】解决多个运行《视觉SLAM十四讲》第5.4.2节 RGB-D视觉中的点云拼接时的错误。

2022-03-23 10:09:11 浏览数 (1)

运行《视觉SLAM十四讲》第5.4.2节 RGB-D视觉中的点云拼接

最近需要用到点云显示的代码。 在Ubuntu 18.04编译《视觉SLAM十四讲》(第二版)中第5.4.2节 RGB-D视觉中的点云拼接代码时遇到了多个错误。

所有相关软件版本

Ubuntu 18.04 FFMpeg n4.2.5 opencv-3.4.16 Pangolin v0.6 Sophus v0.9.5 fmt 6.2.1

找不到opencv.hpp

第一个错误是找不到opencv.hpp。错误信息如下。

代码语言:javascript复制
~/proj/slam/slambook2/ch5/rgbd/build$ make -j
Scanning dependencies of target joinMap
[ 50%] Building CXX object CMakeFiles/joinMap.dir/joinMap.o
/home/hankf/proj/slam/slambook2/ch5/rgbd/joinMap.cpp:3:10: fatal error: opencv2/opencv.hpp: No such file or directory
 #include <opencv2/opencv.hpp>
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/joinMap.dir/build.make:62: recipe for target 'CMakeFiles/joinMap.dir/joinMap.o' failed
make[2]: *** [CMakeFiles/joinMap.dir/joinMap.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

编译并安装FFMpeg n4.2.5、opencv-3.4.16、Pangolin v0.6,并在CMakeLists.txt添加下列句子后,解决这个问题。

代码语言:javascript复制
find_package(OpenCV 3 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

找不到fmt/core.h

第一个错误是找不到fmt/core.h。错误信息如下。

代码语言:javascript复制
~/proj/slam/slambook2/ch5/rgbd/build$ make -j
Scanning dependencies of target joinMap
[ 50%] Building CXX object CMakeFiles/joinMap.dir/joinMap.o
In file included from /usr/local/include/sophus/types.hpp:8:0,
                 from /usr/local/include/sophus/rotation_matrix.hpp:10,
                 from /usr/local/include/sophus/so3.hpp:7,
                 from /usr/local/include/sophus/se3.hpp:7,
                 from /home/hankf/proj/slam/slambook2/ch5/rgbd/joinMap.cpp:5:
/usr/local/include/sophus/common.hpp:42:10: fatal error: fmt/core.h: No such file or directory
 #include <fmt/core.h>
          ^~~~~~~~~~~~
compilation terminated.
CMakeFiles/joinMap.dir/build.make:62: recipe for target 'CMakeFiles/joinMap.dir/joinMap.o' failed
make[2]: *** [CMakeFiles/joinMap.dir/joinMap.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

从https://github.com/fmtlib/fmt下载fmt。安装 libeigen3-dev (3.3.4)、编译并安装Sophus 0.9.5、fmt 6.2.1,并在CMakeLists.txt添加下列句子后,解决这个问题。

代码语言:javascript复制
find_package(fmt REQUIRED)
include_directories(${fmt_INCLUDE_DIRS})

找不到函数assert_fail

部分错误信息如下:

代码语言:javascript复制
~/proj/slam/slambook2/ch5/rgbd/build$ make -j 16
Scanning dependencies of target joinMap
[ 50%] Building CXX object CMakeFiles/joinMap.dir/joinMap.o
[100%] Linking CXX executable joinMap
CMakeFiles/joinMap.dir/joinMap.o: In function `std::make_unsigned<long>::type fmt::v8::detail::to_unsigned<long>(long)':
joinMap.cpp:(.text._ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_] 0x21): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
CMakeFiles/joinMap.dir/joinMap.o: In function `Sophus::SO3Base<Sophus::SO3<double, 0> >::normalize()':
joinMap.cpp:(.text._ZN6Sophus7SO3BaseINS_3SO3IdLi0EEEE9normalizeEv[_ZN6Sophus7SO3BaseINS_3SO3IdLi0EEEE9normalizeEv] 0x13a): undefined reference to `fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)'
CMakeFiles/joinMap.dir/joinMap.o: In function `fmt::v8::basic_format_parse_context<char, fmt::v8::detail::error_handler>::on_error(char const*)':
joinMap.cpp:(.text._ZN3fmt2v826basic_format_parse_contextIcNS0_6detail13error_handlerEE8on_errorEPKc[_ZN3fmt2v826basic_format_parse_contextIcNS0_6detail13error_handlerEE8on_errorEPKc] 0x5): undefined reference to `fmt::v8::detail::error_handler::on_error(char const*)'
CMakeFiles/joinMap.dir/joinMap.o: In function `fmt::v8::detail::fill_t<char>::operator=(fmt::v8::basic_string_view<char>)':
joinMap.cpp:(.text._ZN3fmt2v86detail6fill_tIcEaSENS0_17basic_string_viewIcEE[_ZN3fmt2v86detail6fill_tIcEaSENS0_17basic_string_viewIcEE] 0x56): undefined reference to `fmt::v8::detail::throw_format_error(char const*)'
collect2: error: ld returned 1 exit status
CMakeFiles/joinMap.dir/build.make:141: recipe for target 'joinMap' failed
make[2]: *** [joinMap] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/joinMap.dir/all' failed
make[1]: *** [CMakeFiles/joinMap.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

在CMakeLists.txt添加下列句子后,解决这个问题。

代码语言:javascript复制
set(FMT_LIBRARIES fmt::fmt)

找不到libavcodec.so.58

错误信息如下:

代码语言:javascript复制
~/proj/slam/slambook2/ch5/rgbd/build$ ./joinMap
./joinMap: error while loading shared libraries: libavcodec.so.58: cannot open shared object file: No such file or directory

在目录“/usr/local”下查找到libavcodec.so.58,于是在/etc/ld.so.conf添加它的路径”/usr/local/lib/”,再执行“sudo ldconfig”更新动态库。之后可以运行joinMap。

代码语言:javascript复制
/usr/local$ find -name libavcodec.*
./share/man/man3/libavcodec.3
./share/doc/ffmpeg/libavcodec.html
./lib/libavcodec.so.59.20.100
./lib/libavcodec.so.58
./lib/pkgconfig/libavcodec.pc
./lib/libavcodec.a
./lib/libavcodec.so.59
./lib/libavcodec.so.58.54.100
./lib/libavcodec.so

文件“ /etc/ld.so.conf”最后的内容如下。

代码语言:javascript复制
~/proj/slam/slambook2/ch5/rgbd/build$ cat /etc/ld.so.conf

include /etc/ld.so.conf.d/*.conf

/usr/local/lib/

Pangolin 报告错误“Unable to retrieve framebuffer options”

运行joinMap,得到下列错误。

代码语言:javascript复制
转换图像中: 1
转换图像中: 2
转换图像中: 3
转换图像中: 4
转换图像中: 5
点云共有1081843个点
terminate called after throwing an instance of 'std::runtime_error'
  what():  Pangolin X11: Unable to retrieve framebuffer options

桌面系统是远程桌面。为了提高性能,使用了xfce4。回到Ubuntu 18.04本地桌面,再执行joinMap,结果正常,能显示点云图片。

0 人点赞