Install Opencv3.2 on Ununtu 16.04

Opencv3.2 在 Ununtu 16.04 上的编译安装

参考自Ubuntu 16.04编译安装OpenCV(Python) – WTF Daily Blog,不过这位博主装的是3.1版本,而且有些问题。

安装OpenCV依赖

1
2
3
4
5
6
7
8
9
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3.5-dev

下载OpenCV源码

这里下载 3.2.0

1
2
3
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
$ unzip opencv.zip

下载和OpenCV版本对应的opencv_contrib(一些扩展功能和non-free代码):

1
2
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.2.0.zip
$ unzip opencv_contrib.zip

编译安装

1
2
3
$ cd ~/opencv-3.2.0/
$ mkdir build
$ cd build
1
2
3
4
5
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH=/root/Downloads/opencv_contrib-3.2.0/modules -D PYTHON_EXECUTABLE=/root/miniconda3/bin/python ..

其中OPENCV_EXTRA_MODULES_PATH是opencv_contrib的解压后的地址,PYTHON_EXECUTABLE是# 你的python 解释器地址 可用witch python 查看。
若出现,需要下载ippicv_linux_20151201.tgz的长时间等待,可在此opencv_3rdparty/ippicv at ippicv/master_20151201 · opencv/opencv_3rdparty手动下载对应文件,并放在对应位置如Put the ippicv_linux…tgz under
<…>/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/, 参考自incorrect hash in cmake ippicv when installing · Issue #5973 · opencv/opencv

编译:

$ make

安装:

1
2
$ sudo make install
$ sudo ldconfig

pip install opencv即可😎