系统:Ubuntu18.04
版本:OpenCV+contrib 4.5.1
已经配置好的:https://pan.baidu.com/s/1Dl3ePy6dG5AQca37I7FFeg zlaf
安装OpenCV + contrib
安装相关依赖包:
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev # 处理图像
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg
上网找到资源,并且把contrib添加到opencv-4.5.1文件中。
编译与配置文件(理论版本)
理论版是理论上会完成。但是,成功是留给有耐心的人。所以,如果遇到了什么问题,请看下面的错误修改!
执行命令
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON_DEFAULT_EXECUTABLE=$(which python3) -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.1/modules -D WITH_TBB=ON -D WITH_EIGEN=ON ..
注意其中的OPENCV_EXTRA_MODULES_PATH
地址,修改为contrib的地址
接着执行
sudo make -j12(看电脑配置)
sudo make install
接着,我们需要创建配置文件:
sudo gedit /etc/ld.so.conf.d/opencv.conf
加入
/usr/local/lib
接着执行
sudo ldconfig
再打开
sudo gedit /etc/bash.bashrc
在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
最后执行
source /etc/bash.bashrc
sudo updatedb
错误修改
错误1:出现fatal error: boostdesc_bgm.i: No such file or directory
下载并添加到OpenCV源码文件根目录中的隐藏文件夹 opencv_contrib/modules/xfeatures2d/src 下
地址:https://pan.baidu.com/s/1BeYF8kqEZLAJYQj-MvxpmA 密码:e1wc
错误2:出现所有的关于xfeatures2d的错误,一律把源文件中的#include的全部替换为绝对路径
最后,直接把文件打包送进百度网盘,以备不时之需!
自动补全
按下Ctrl+Shift+P:查找Edit configuartion,通过此打开c_cpp_properties.json
文件形如此:
其中,在includePath中添加地址。很多很多都是在/usr/include
中。
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/home/a/Offboard/devel/include",
"/home/a/Prometheus/devel/include",
"/opt/ros/melodic/include", // ros
"/home/a/ROS_Demo/src/cv_pkg/include",
"/home/a/ROS_Demo/src/wpr_simulation/include",
"/usr/include",
"/usr/include/pcl-1.8",
"/home/a/opencv-4.5.1/include" // opencv
],
"name": "Linux",
"intelliSenseMode": "linux-gcc-x64",
"compilerPath": "/opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14"
}
],
"version": 4
}
参考资料:
主要参考的教程:https://blog.csdn.net/gj295983859/article/details/95182810
错误修改:https://www.it610.com/article/1279176287591612416.htm
错误修改两件套:
https://download.csdn.net/download/u011736771/12152001
https://blog.csdn.net/xiewenrui1996/article/details/108683866
自动补全:https://blog.csdn.net/cbc000/article/details/80670413