Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install OpenCV 3.0 with Python 3.4 on OSX & Ubuntu #18

Open
rainyear opened this issue Sep 14, 2015 · 5 comments
Open

Install OpenCV 3.0 with Python 3.4 on OSX & Ubuntu #18

rainyear opened this issue Sep 14, 2015 · 5 comments
Assignees

Comments

@rainyear
Copy link
Owner

OpenCV 已经发布到了3.0版本,最近Python也发布了3.5,之前的应用都还是基于 OpenCV 2.X 和 Python 2.7。

Ubuntu 14.04 64bit

Python3.4 应该已经像2.7一样是标配了。首先需要的是 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

下载 OpenCV 3.0,编译安装:

wget https://github.com/Itseez/opencv/archive/3.0.0.zip

unzip 3.0.0.zip && cd 3.0.0
mkdir build && cd build

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
import cv2

OSX 10.10.3

开发环境比较乱,一般使用独立的虚拟环境,以往一般用virtualenv,Python3 已经内置了该功能模块:

// python3 -m venv <virtualenv-dir>
python3 -m venv venv3
source venv3/bin/activate
pip install numpy

然后是编译安装 OpenCV,和 Ubuntu 基本一致,只是一些参数路径稍有差别:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON3_EXECUTABLE=/path/to/venv3/bin/python \
-D PYTHON3_PACKAGES_PATH=/path/to/venv3/lib/python3.4/site-packages \
-D PYTHON3_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib \
-D PYTHON3_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/Users/rainy/Projects/Vision/venv3/lib/python3.4/site-packages/numpy/core/include \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

cmake 结果中Python 3部分如下:
Python 3:

make -j8
make install

测试一下:

import cv2
cv2.__version__
#=> '3.0.0'

参考

  1. Installation in Linux
  2. Install OpenCV 3.0 and Python 3.4+ on OSX
@rainyear rainyear self-assigned this Sep 14, 2015
@rainyear rainyear changed the title install OpenCV 3.0 with Python 3.4 on OSX & Ubuntu Install OpenCV 3.0 with Python 3.4 on OSX & Ubuntu Sep 14, 2015
@acgtyrant
Copy link

OpenCV 3 终于支持 Python 3 了啊……

@rrrrrr8
Copy link

rrrrrr8 commented Dec 2, 2016

简洁明了,感谢!

@mengmengmengqiang
Copy link

步骤清晰,非常感谢.

@boyden
Copy link

boyden commented Sep 6, 2017

CMake Error: The source directory "/home/***" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
请问这个问题是什么原因?
电脑版本:Ubuntu 14.04 LTS
python版本:3.4

@mengmengmengqiang
Copy link

mengmengmengqiang commented Sep 6, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants