一、安装依赖
sudo apt install build-essential cmake libtbb2 libttb-dev libgtk-3-dev
sudo apt install python3 python3-dev pkg-config
sudo apt install libjpeg-dev libpng-dev libtiff-dev libjasper-dev
sudo apt install zlib1g zlibe1g-dev libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev libdc1394-22-dev
sudo apt install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt install gfortran openexr libopenexr-dev
二、下载opencv和opencv_contrib安装包
1.opencv:https://link.csdn.net/?target=https%3A%2F%2Fgithub.com%2Fopencv%2Fopencv
2.opencv_contrib:mirrors / opencv / opencv_contrib · GitCode
(注:opencv和opencv_contrib版本应一致)
三、编译opencv和opencv_contrib
将opencv_contrib解压后放到opencv文件夹内,在opencv文件夹内新建build文件
通过这个下载镜像下载:boostdesc_bgm.i,vgg_generated_48.i等.rar (提取码:p50x),放在 opencv_contrib/modules/xfeatures2d/src/ 路径下。
进入build文件,首先进行预编译
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
CMAKE_BUILD_TYPE:编译类型
CMAKE_INSTALL_PREFIX:安装路径
OPENCV_GENERATE_PKGCONFIG:生成opencv.pc文件
OPENCV_EXTRA_MODULES_PATH:opencv_ccontrib编译
其次进行编译
make -j6
在编译过程中会出现两种问题:
1.问题:fatal error: features2d/test/test_detectors_regression.impl.hpp: 没有那个文件或目录
解决方案:将opencv / modules / features2d复制,然后粘贴到build目录中。
2.问题:fatal error: opencv2/xfeatures2d.hpp: 没有那个文件或目录
解决方案:将opencv_contrib/modules/xfeatures2d/include/opencv2中的xfeatures2d文件夹和 xfeatures2d.hpp文件复制到opencv/build/opencv2路径下
重新make,编译成功后,进行安装
sudo make install
四、测试
查看opencv的版本:opencv_version
————————————————
版权声明:本文为CSDN博主「优秀?」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_63441172/article/details/130343727