我用的是ubuntu22.04,opencv是4.7,使用其他的库感觉就算版本不一样,也能跑。
一、运行build.sh能够产生可执行文件遇到的问题
1.由于opencv版本高带来的问题
这些问题怎么定位出现在哪些文件中,你通过命令行,运行下面三句话,然后看报的错的文件
cd ORB_SLAM2
chmod +x build.sh
./build.sh
问题1:找不到opencv/cv.h
由于我用的是cv4,代码用的cv3,而cv4没有opencv/cv.h,网上查了查用其他的库替代
替代方式:
如果还有类似的错就根据提示去查找问题的地方,然后进行修改。有两处需要多次修改的是当出现类似
问题2:出现类似error: ‘cvSolve’ was not declared in this scope
此时就在出错的文件里前面加上包含头文件:
注意这个错误出现过好多次,需要修改的地方比较多
问题3:未定义标识符“CV_BGR2GRAY“
-
错误原因:在新版本中,CV_BGR2GRAY被COLOR_BGR2GRAY替换。只需将CV改成COLOR就行。
在新版本中,CV基本都被COLOR替换。
问题4:error: ‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope
解决方案:CV_LOAD_IMAGE_UNCHANGED 改为 cv::IMREAD_UNCHANGED
2.c++ error: ‘decay_t’ is not a member of ‘std’
大概是c++版本的问题,在主目录下的CMakeLIists.txt上修改支持C++14标准
3.ORB_SLAM安装问题error: ‘std::chrono::monotonic_clock’ has not been declared
4.报错“没有规则可制作目标” 以及报opencv>2.4.3找不到的问题
修改CMakeList.txt
注意不只是修改一部分,还有那个thirdparty里面的CMakeList.txt也需要修改!!
我遇到的大体上是这些错误,遇到其他错误不要慌,找找总会有解决方法!
二、在vscode上配置第三方库
1. 首先是在c_cpp_properties.json增加库
{"configurations": [{"name": "Win32","includePath": ["${workspaceFolder}/**","/usr/local/include","/usr/include/eigen3","/usr/local/include/opencv4","/home/gallagher/cpp_all/slam/ORB_SLAM2/include","/usr/local/include/pangolin"],"defines": ["_DEBUG","UNICODE","_UNICODE"],"windowsSdkVersion": "10.0.18362.0","compilerPath": "/usr/bin/g++-11","cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "msvc-x64"}],"version": 4
}
运行任何一个Example里面的cc文件就会生成tasks.json和launch.json,其中tasks.json的配置如下(主要是-L和-I以及后面的连接库):
{"tasks": [{"type": "cppbuild","label": "C/C++: g++ 生成活动文件","command": "/usr/bin/g++","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}","-L","/usr/local/lib","-L","/usr/lib","-L","/home/gallagher/cpp_all/slam/ORB_SLAM2/lib","-I","/usr/include/eigen3","-I","${workspaceFolder}/","-I","/usr/local/include/","-I","/usr/local/include/opencv4/","-I","/usr/local/include/sophus/","-I","/usr/include/suitesparse","-I","/usr/local/include/pangolin/","-I","/home/gallagher/cpp_all/slam/ORB_SLAM2/include","/usr/local/lib/libpangolin.so","/usr/local/lib/libopencv_*","/usr/local/lib/libgstgl-1.0.so.0","/usr/local/lib/libSophus.so","/home/gallagher/cpp_all/slam/ORB_SLAM2/lib/libORB_SLAM2.so"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "调试器生成的任务。"},{"type": "cppbuild","label": "C/C++: g++-11 生成活动文件","command": "/usr/bin/g++-11","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": "build","detail": "调试器生成的任务。"}],"version": "2.0.0"
}
三、点击调试按钮遇到的问题
1.由于pangolin版本带来的问题
这个库版本太高会带来下图中类似的问题,一般安装这个版本会带来这个问题:
GitHub - stevenlovegrove/Pangolin: Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input.
但是如果安装低版本又会带来编译不通过的结果,即会报下面的错误:
于是我在github上找打了一个折中的版本:
GitHub - zzx2GH/Pangolin: It's a correct package.
但是也会遇到【视觉slam14讲】第三章 Ubuntu18.04安装pangolin出现的问题_-dcpp11_no_boosr=1_qin__han的博客-CSDN博客但是遇到的问题上面链接可以解决,最终总算是解决了这个库带来的问题
2.第三方库Eigen问题
这是因为eigen的版本太高所导致的,去Eigen下载3.2.1
安装完成后出现
但这个文件在目录中存在,这是因为你没有把工程文件下的libORB_SLAM2.so给移动到/usr/local/lib下面,运行下面的cp命令即可
最终看下能够调试的结果:
以及命令行跑一个测试集的效果