红联Linux门户
Linux帮助

ubuntu14/16安装python3-opencv3

发布时间:2017-03-08 09:39:33来源:linux网站作者:凹凸曼_style
今天尝试在ubuntu16.04 LTS安装opencv3和python3-opencv扩展,看了很多教程都是复杂而繁琐。这里的教程简单而实用,亲测有效!
 
由于ubuntu14.04/16.04都自带了python2.7和python3.5,所以无需在安装python。
检查python是否安装:
~ whereis python
ubuntu14/16安装python3-opencv3
 
首先需要的是 pip:
~ sudo apt-get install python3-setuptools python3-dev sudo easy_install3 pip
然后是 numpy:
~ pip3 install numpy
安装依赖:
~ sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
 
安装opencv3:
~ wget https://codeload.github.com/opencv/opencv/zip/3.2.0
~ unzip 3.2.0 && cd 3.2.0
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local  PYTHON3_EXECUTABLE=/usr/bin/python3 PYTHON_INCLUDE_DIR=/usr/include/python3.4 PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.4/dist-packages/numpy/core/include ..
~ make -j4
~ sudo make install
 
测试一下:
python3.5
>>> import cv2
>>> cv2.__version__
'3.2.0'
>>>
恭喜您,现在可以在python3.5中调用opencv3了!
ubuntu14/16安装python3-opencv3
 
本文永久更新地址:http://www.linuxdiyf.com/linux/28998.html