下载opencv3.3.1及opencv-3.3.contrib
opencv3.3.1
https://github.com/opencv/opencv/releases/tag/3.3.1
选择source code(tar.gz)
opencv_contrib
https://github.com/opencv/opencv_contrib/releases/tag/3.3.1
选择source code(tar.gz)
安装相关依赖包
CTRL+T打开终端,在解压opencv之前输入以下命令,安装相关依赖包,一般装前三个命令就行,一定要确认GTK2.0已经装好
sudo apt-get install build-essential
sudo apt-get install cmake 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 openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
注意
这儿一定要确定pkg-config和libgtk2.0-dev已经装上,不然后续写程序用了imshow会报错,查了一下只能重装opencv才能解决咯
解压,编译
解压opencv3.3.1及opencv-3.3.contrib
并将opencv3.3.1放到opencv目录下,将opencv-3.3.contrib放到opencv-3.3.1目录下
最后在opencv3.3.1目录下创建一个build文件夹
cd opencv-3.3.1
sudo mkdir build #新建文件夹build
进入build目录
执行cmake生成makefile文件
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/opencv/opencv-3.3.1/opencv_contrib-3.3.1/modules/ ..
OPENCV_EXTRA_MODULES_PATH就是你 opencv_contrib-3.3.1下面的modules目录,且后面有两个…不能缺少
生成完毕之后,提示如下:
-- Install path: /usr/local
--
-- cvconfig.h is in: /home/user/opencv-3.3.1/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
--