1 安装相关依赖
安装opencv前,需要先准备好编译器、相关依赖
sudo apt-get install gcc g++ cmake vim
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
若没有安装sudo,则
apt-get update
apt-get install sudo
2 下载
git clone https://gitcode.net/opencv/opencv
3 配置
cd opencv
mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. -D OPENCV_GENERATE_PKGCONFIG=ON
这块要注意的是要设置“-D OPENCV_GENERATE_PKGCONFIG=ON”,否则在输入以下指令时会报错,
pkg-config --cflags opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
4 编译
sudo make -j[线程数],如
sudo make -j8
5 安装
sudo make install
6 环境配置
修改/etc/ld.so.conf
sudo vim /etc/ld.so.conf
打开文件后,在末端添加
include /usr/local/lib
输入以下指令来更新系统共享链接库
sudo ldconfig
修改/etc/bash.bashrc
sudo vim /etc/bash.bashrc
打开文件后,在末端添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
激活配置文件
source /etc/bash.bashrc
7 查看版本
pkg-config opencv4 --modversion