ubuntu20.04安装opencv教程
1、安装构建工具和所有依赖软件包
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \ libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \ gfortran openexr libatlas-base-dev python3-dev python3-numpy \ libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \ libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
2、下载opencv和opencv_contrib源
https://opencv.org/releases/
3、在opencv文件夹中新建build文件夹并进入
cd opencv
mkdir -p build && cd build
4、使用cmake命令配置opencv构建
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON
-D OPENCV_ENABLE_NONFREE =ON
-D OPENCV_EXTRA_MODULES_PATH 为opencv_contrib中modules文件的路径
这一步也可以通过cmake_gui可视化实现,具体可参考https://blog.csdn.net/wuyu1125/article/details/112291576
记得一定要勾选OPENCV_ENABLE_NONFREE不然编译的时候可能出现专利问题
5、编译
make j8
根据你的处理器修改-f值。如果你不知道你的处理器核心数,你可以输入nproc找到。
6、安装
sudo make install
7、配置环境
我再将opencv导入qt时,一直报错
error while loading shared libraies :libopencv_core_so.3.4:cannot open shared object
解决方法:
在
sudo gedit /etc/bash.bashrc
中添加
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
再执行:
source /etc/bash.bashrc
参考博客:https://www.jianshu.com/p/3c15a1ad3ec6
https://www.cnblogs.com/chay/p/10287503.html