- 环境准备
- 操作系统(Ubuntu-18.04)
- opencv版本(4.5.5)
- 安装基础依赖
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
- cmake
sudo apt-get install cmake
- 安装opencv
解压安装包后进入文件夹
cd opencv-4.5.5
mkdir build
cd build
# opencv版本不同,这条命令是不一样的
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
修改配置:
# 修改两个文件
# first
sudo gedit /etc/ld.so.conf
-------------------------------
# 增加一句话
include /usr/local/lib
# 使配置生效
sudo ldconfig
# second
sudo gedit /etc/bash.bashrc
-------------------------------
# 在文件末尾加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
# 使配置生效
source /etc/bash.bashrc
- 检验
pkg-config opencv4 --modversion
- reference
ubuntu安装opencv的正确方法