- 下载依赖
sudo apt-get install cmake libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install 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 ffmpeg
# 可能需要安装的依赖
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
- cmake
# 2.1 cmake 过程中需要 ippicv,下载会很慢,所以先准备好, 下载地址:https://www.lanzous.com/i8qmxsh
# 2.2 打开源码中的 opencv/3rdparty/ippicv/ippicv.cmake 文件
# 找到: "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}ippicv/" # 在最后位置
# 修改为:"file:~/home/hb/桌面/ippicv" # 下载的 ippicv 目录
# 2.3 进入opencv源码目录,创建build 目录,cd build 运行
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/usr/local/opencv -D WITH_GTK=ON -D WITH_OPENMP=ON ..
# 3.3 解释每个含义
cmake -D CMAKE_BUILD_TYPE=Release # 选择发布
OPENCV_GENERATE_PKGCONFIG=YES # 创建 PKGCONFIG文件
CMAKE_INSTALL_PREFIX=/usr/local/opencv #安装路径
WITH_GTK=ON # ubuntu 上显示窗口必须加上这个
- 安装
make -j4
sudo make install
# 现在 opencv 已经安装好了
- 配置 vs code opencv 头文件
# 打开vs code,ctrl + shift + p 搜索:c_cpp_properties.json
# 在 includePath 下加入
"/usr/local/opencv/include/opencv4",
"/usr/local/opencv/include"
#include "opencv2/opencv.hpp" 这样引入就可以了