Ubuntu16.04下在Python3.5安装OpenCV3.3.1(CPU)

Ubuntu16.04下在Python3.5安装OpenCV3.3.1

安装过程(官网安装教程  https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html):

1. 用Ctrl+Alt+T打开终端,输入下述命令,安装OpenCV3.3.1的依赖包

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

2. 安装OpenCV3.3.1

(1)下载opencv和opencv_contrib,在刚才的终端中输入:

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

会在home中发现有opencv和opencv_contrib两个文件夹,则下载成功

(2)用cmake配置属性(cpu版):

首先文件夹opencv新建一个build文件夹

cd ~/opencv
mkdir build
cd build   #打开build文件夹

配置编译opencv

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D PYTHON3_EXECUTABLE=/usr/bin/python3 -D PYTHON_INCLUDE_DIR=/usr/include/python3.5 -D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D PYTHON_EXECUTABLE=/usr/lib/python3 -D BUILD_EXAMPLES=ON ..

运行后显示:

Ubuntu16.04下在Python3.5安装OpenCV3.3.1(CPU)_第1张图片

该步成功,之后输入:

make -j7 # 7个任务并行,加快安装(亲测,如果输入的是make-j,电脑安装慢,还死机了,导致安装失败)

sudo make install

至此,安装完成

如想要查询安装的版本

输入:

python3

import cv2

cv2.__version__

可以得到:



参考链接:

1. Ubuntu16.04下安装OpenCV3.2.0 - Arkenstone - 博客园    http://www.cnblogs.com/arkenstone/p/6490017.html

2. OpenCV: Installation in Linux    https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

你可能感兴趣的:(Ubuntu,安装)