视觉SLAM十四讲——ch13的实践操作及避坑
- 1. 实践操作前的准备工作
- 2. 实践过程
- 2.1 运行测试程序
- 2.2 运行00数据集
- 2.3 更改代码画出运动轨迹
- 3. 遇到的问题及解决办法
- 3.1 cmake ..时出现的问题
- 3.2 make时出现的问题
- 3.3 头文件下红色报错
1. 实践操作前的准备工作
- 下载Kitti数据集,下载网址:https://www.cvlibs.net/datasets/kitti/eval_odometry.php
它的odometry数据大约有22GB.下载解压后可以得到若干个视频段,本次我们使用第0段进行实践。 - 在终端中进入ch13文件夹下,顺序执行以下命令进行编译。
mkdir build
cd build
cmake ..
//注意,j8还是其他主要看自己的电脑情况
make -j8
- 在ch13文件下的bin文件中进行运行。
注意: 在make过程中,将错误改正后,依然会出现warning,但是对我们此实践的过程几乎没有影响。 - 将config目录下default.yaml文件中的文件路径进行更改,将路径更改为自己数据所在的路径下面是我的更改:
# 更改前
dataset_dir: /mnt/1A9286BD92869CBF/Dataset/Kitti/dataset/sequences/05
# 更改后
dataset_dir: /home/fighter/slam/slambook2/ch13/00
- 同样的,我们也需要将run_kitti_stereo.cpp文件中的文件引用路径,更改前后如下所示:
//更改前
DEFINE_string(config_file, "./config/default.yaml", "config file path");
//更改后
DEFINE_string(config_file, "/home/fighter/slam/slambook2/ch15/config/default.yaml", "config file path");
//更改原因:绝对路径可以避免一些后期不必要的麻烦,记得重新make。
- (可选)在VSCode中打开ch13工作空间,可以在很多文件中看到include头文件下面有红色波浪线报错,但是按照之前配置好的,工作环境直接运行也没问题。调整后的includePath主要包含:
"${workspaceFolder}/**",
"/usr/include/eigen3",
"/usr/include/opencv4",
"/usr/include/suitesparse"
2. 实践过程
2.1 运行测试程序
运行语句:
在ch13文件中,进入到bin文件夹下,执行以下语句:
./test_triangulation
运行结果:
2.2 运行00数据集
运行语句:
./run_kitti_stereo
运行结果:
可视化结果:
https://download.csdn.net/download/qq_44164791/87934968
第一段视频是ch13中原本的代码,经过更改一些错误之后,能够正常运行程序。
终端输出部分示例:
I0620 16:27:00.055335 13144 visual_odometry.cpp:65] VO cost time: 0.0070335 seconds.
I0620 16:27:00.055406 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.076495 13144 frontend.cpp:269] Find 128 in the last image.
I0620 16:27:00.077795 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 18/87
I0620 16:27:00.077836 13144 frontend.cpp:220] Current Pose =
00.888545 -0.427115 -0.167511 0-35.5003
00.393009 00.896979 -0.202415 0-462.659
00.236708 00.114022 00.964867 0-247.216
000000000 000000000 000000000 000000001
I0620 16:27:00.081686 13144 visual_odometry.cpp:65] VO cost time: 0.005869 seconds.
I0620 16:27:00.081735 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.113430 13144 frontend.cpp:269] Find 112 in the last image.
I0620 16:27:00.115217 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 13/67
I0620 16:27:00.115278 13144 frontend.cpp:220] Current Pose =
00.890851 -0.421528 -0.169406 0-38.2629
000.38627 00.899102 0-0.20594 0-461.247
00.239123 00.118026 000.96379 0-250.589
000000000 000000000 000000000 000000001
I0620 16:27:00.115438 13144 map.cpp:79] remove keyframe 932
I0620 16:27:00.115639 13144 map.cpp:110] Removed 113 active landmarks
I0620 16:27:00.115675 13144 frontend.cpp:81] Set frame 4535 as keyframe 939
I0620 16:27:00.123732 13144 frontend.cpp:308] Detect 100 new features
I0620 16:27:00.124994 13144 frontend.cpp:350] Find 201 in the right image.
I0620 16:27:00.125965 13144 frontend.cpp:139] new landmarks: 123
I0620 16:27:00.144817 13144 visual_odometry.cpp:65] VO cost time: 0.0355153 seconds.
I0620 16:27:00.144896 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.153093 13151 backend.cpp:163] Outlier/Inlier in optimization: 0/2147
I0620 16:27:00.186288 13144 frontend.cpp:269] Find 172 in the last image.
I0620 16:27:00.188879 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 22/137
I0620 16:27:00.188935 13144 frontend.cpp:220] Current Pose =
00.888264 -0.427094 -0.169049 0-35.2398
00.390936 00.896157 -0.209933 0-460.647
00.241156 00.120388 000.96299 0-253.153
000000000 000000000 000000000 000000001
I0620 16:27:00.192497 13144 visual_odometry.cpp:65] VO cost time: 0.0075273 seconds.
I0620 16:27:00.192548 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.204964 13144 frontend.cpp:269] Find 132 in the last image.
I0620 16:27:00.206867 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 15/102
I0620 16:27:00.206925 13144 frontend.cpp:220] Current Pose =
00.889966 0-0.42294 -0.170536 0-37.2853
00.387267 00.898407 -0.207097 0-461.014
0000.2408 00.118266 00.963342 0-253.325
000000000 000000000 000000000 000000001
I0620 16:27:00.221396 13144 visual_odometry.cpp:65] VO cost time: 0.017146 seconds.
I0620 16:27:00.221469 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.251788 13144 frontend.cpp:269] Find 119 in the last image.
I0620 16:27:00.253571 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 16/80
I0620 16:27:00.253782 13144 frontend.cpp:220] Current Pose =
000.89121 -0.419695 -0.172049 0-38.7982
00.384802 00.900376 -0.203104 0-461.756
00.240151 00.114803 00.963923 0-252.879
000000000 000000000 000000000 000000001
I0620 16:27:00.268241 13144 visual_odometry.cpp:65] VO cost time: 0.017168 seconds.
I0620 16:27:00.268343 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.318046 13144 frontend.cpp:269] Find 111 in the last image.
I0620 16:27:00.322237 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 4/72
I0620 16:27:00.322328 13144 frontend.cpp:220] Current Pose =
00.891961 -0.417701 -0.173005 0-39.7112
00.383965 000.90189 -0.197902 0-462.921
00.238695 00.110093 00.964834 0-251.737
000000000 000000000 000000000 000000001
I0620 16:27:00.322566 13144 map.cpp:79] remove keyframe 933
I0620 16:27:00.322924 13144 map.cpp:110] Removed 114 active landmarks
I0620 16:27:00.322980 13144 frontend.cpp:81] Set frame 4539 as keyframe 940
I0620 16:27:00.330118 13144 frontend.cpp:308] Detect 103 new features
I0620 16:27:00.333930 13144 frontend.cpp:350] Find 193 in the right image.
I0620 16:27:00.335049 13144 frontend.cpp:139] new landmarks: 110
I0620 16:27:00.350602 13144 visual_odometry.cpp:65] VO cost time: 0.0332755 seconds.
I0620 16:27:00.350790 13144 visual_odometry.cpp:44] VO is running
I0620 16:27:00.362143 13151 backend.cpp:163] Outlier/Inlier in optimization: 0/2135
I0620 16:27:00.378190 13144 frontend.cpp:269] Find 169 in the last image.
I0620 16:27:00.380698 13144 frontend.cpp:215] Outlier/Inlier in pose estimating: 17/144
I0620 16:27:00.380779 13144 frontend.cpp:220] Current Pose =
00.887592 -0.427112 -0.172499 0-34.5528
00.394054 00.897983 -0.195827 0-464.253
00.238541 00.105841 00.965347 0-251.064
000000000 000000000 000000000 000000001
I0620 16:27:00.383298 13144 visual_odometry.cpp:65] VO cost time: 0.0060374 seconds.
I0620 16:27:00.383389 13144 visual_odometry.cpp:44] VO is running
W0620 16:27:00.425977 13144 dataset.cpp:61] cannot find images at index 4541
I0620 16:27:00.451663 13151 backend.cpp:163] Outlier/Inlier in optimization: 0/2135
I0620 16:27:00.463881 13152 viewer.cpp:78] Stop viewer
I0620 16:27:00.468593 13144 visual_odometry.cpp:53] VO exit
2.3 更改代码画出运动轨迹
运行语句:
./run_kitti_stereo
运行结果:
可视化结果:
https://download.csdn.net/download/qq_44164791/87934968
第二段视频是经过更改可视化的代码,将相机的运动轨迹绘画出来,但是根据视频可以看出来,轨迹效果并不好
第三段视频是在第二段视频的运行代码上,将后端优化的部分给注释掉后,通过轨迹可以看出来效果比较好,可能因为优化时矫正过度的原因。
由于没有更改输出信息,因此终端输出和2.2相同。
3. 遇到的问题及解决办法
3.1 cmake …时出现的问题
- 出现的问题:
CMake Error at CMakeLists.txt:18 (find_package):
Could not find a configuration file for package "OpenCV" that is compatible
with requested version "3.1".
The following configuration files were considered but not accepted:
/usr/local/lib/cmake/opencv4/OpenCVConfig.cmake, version: 4.5.0
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake, version: 4.2.0
/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake, version: 4.2.0
-- Configuring incomplete, errors occurred!
See also "/home/fighter/slam/slambook2/ch15/build/CMakeFiles/CMakeOutput.log".
原因:
这还是我们之前遇到过好多次的opencv版本的问题,和之前一样更改即可。
处理办法:
直接和之前的解决办法一样,更改CMakeLists.txt文件中的opencv版本即可。
//更改前:
find_package(OpenCV 3.1 REQUIRED)
//更改后:
find_package(OpenCV REQUIRED)
3.2 make时出现的问题
- 出现的问题:
原因:
这个编译错误是因为您在使用 OpenCV 库时,使用了在较早版本中定义的已弃用的常量 CV_FILLED。在 OpenCV 版本 4.x 中,该常量已被重命名为 cv::FILLED。
解决办法:
// 在frontend.cpp文件中添加头文件
#include <opencv2/imgproc/imgproc_c.h>
//在viewer.cpp文件中添加头文件
#include <opencv2/imgproc/types_c.h>
有关opencv错误可参考:
https://blog.csdn.net/qq_44164791/article/details/131210608?spm=1001.2014.3001.5501
3.3 头文件下红色报错
例:
解决办法,直接点击第一个选项,添加工作空间的工具包的路径。
最终在文件c_cpp_properties.json中内容h如下所示:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/eigen3",
"/usr/include/opencv4",
"/usr/include/suitesparse"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
本文章仅仅是代码实践过程中,没有进行代码详读,代码祥读在后面的文章会有。