1.下载opencv4.0.1及contribute模块
https://github.com/opencv/opencv/releases/tag/4.0.1
https://github.com/opencv/opencv_contrib/releases/tag/4.0.1
2.更换国内源 //不更换也可以
使用 ubuntu 原生源下载速度,可替换为国内源,提升下载速度
备份 ubuntu 原生源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
使用gedit编辑sources.list文件
sudo gedit /etc/apt/sources.list
将sources.list文件中的内容替换为以下内容,更换为阿里源
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
以上内容仅支持 ubuntu16 ,其他ubuntu版本可自行百度
命令行输入 sudo apt-get update 进行更新
3.安装cmake及依赖环境//cmake需要3.5以上apt-get是2.8
cmake卸载和安装 https://blog.csdn.net/KID___/article/details/105633644
sudo apt-get install git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen pylint libvtk6-dev
3.将contrib解压到opencv目录
4.按照下面链接修改
https://www.cnblogs.com/chay/p/10384942.html#_label2
Operation System --- arm-himix200-linux-gcc
gcc ---- /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc
g++ ---- /opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++
复制.cache文件夹到opencv-4.1.0opencv源码目录 https://www.cnblogs.com/huluwa508/p/10142718.html
(注意:cofigure过程中会从github下载一些依赖文件,没有的话会下载失败,我参照cmakedownload.txt下载对应文件改名后放到opencv源码文件夹下的.cache(该文件夹为隐藏文件夹)怕麻烦的可以直接从csdn下载https://download.csdn.net/download/KID___/12343185)
找到3rdparty/protobuf/src/google/protobuf/common.cc文件,添加宏定义#define HAVE_PTHREAD
配置CMAKE_EXE_LINKER_FLAGS:-lpthread -lrt -ldl
OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
CMAKE_CXX_FLAGS 设置为 -fpermissive
freetype和1394那个我勾了会报错,我就取消了
可选:勾选opencv_world 最后生成的库就只有一个
4.make -j4
sudo make install
5.支持pkg
在命令行中输入 gedit ~/.bashrc 打开 ~/.bashrc 文件
在 ~/.bashrc 文件中添加下面一行内容
路径位自己opencv安装路径
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
使环境变量生效
输入以下内容
source ~/.bashrc
sudo ldconfig
使用 pkg-config 进行测试验证
pkg-config --libs --cflags opencv4