opencv 3.3.0 安装

For detailed info, please refer to

Step #1: Install OpenCV dependencies on Ubuntu 16.04

Most (in fact, all) steps in this tutorial will be accomplished by using your terminal. To start, open up your command line and update the aptget  package manager to refresh and upgrade and pre-installed packages/libraries:

$ sudo aptget update
$ sudo aptget upgrade
$ sudo aptget install buildessential cmake pkgconfig
$ sudo aptget install libjpeg8dev libtiff5dev libjasperdev libpng12dev
$ sudo aptget install libavcodecdev libavformatdev libswscaledev libv4ldev
$ sudo aptget install libxvidcoredev libx264dev
$ sudo aptget install libgtk3dev
$ sudo aptget install libatlasbasedev gfortran
$ sudo aptget install python2.7dev python3.5dev

Step #2: Download the OpenCV source

At the time of this article’s publication, the most recent version of OpenCV is 3.1.0 , which we download a .zip  of and unarchive using the following commands:

$ cd ~
$ wget O
$ unzip
$ wget O
$ unzip

Step #3: Setup your Python environment — Python 2.7 or Python 3

We are now ready to start configuring our Python development environment for the build. The first step is to install pip , a Python package manager:

$ cd ~
$ wget
$ sudo python

In short, using these packages allows you to solve the “Project X depends on version 1.x, but Project Y needs 4.x dilemma. A fantastic side effect of using Python virtual environments is that you can keep your system Python neat, tidy, and free from clutter.

While you can certainly install OpenCV with Python bindings without Python virtual environments, I highly recommend you use them as other PyImageSearch tutorials leverage Python virtual environments. I’ll also be assuming that you have both virtualenv  and virtualenvwrapper  installed throughout the remainder of this guide.

$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm rf ~/ ~/.cache/pip
Once we have virtualenv  and virtualenvwrapper  installed, we need to update our~/.bashrc  file to include the following lines at the bottom of the file:

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/

$ source ~/.bashrc

Creating your Python virtual environment

If you decide to use Python 2.7, use the following command to create a Python 2.7 virtual environment:

$ mkvirtualenv cv p python2
(optional)mkvirtualenv cv p python3
$ pip install numpy

Step #4: Configuring and compiling OpenCV on Ubuntu 16.04


tar -xzvf opencv-3.3.0.tar.gz cd opencv-3.3.0/
cd .. mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 ..

make # make -j4表示开4个线程来进行编译
make install


cd /usr/local/lib/python3.5/site-packages/
sudo mv

Step #6: Testing your OpenCV install

Congratulations, you now have OpenCV 3 installed on your Ubuntu 16.04 system!

To verify that your installation is working:

  1. Open up a new terminal.
  2. Execute the workon  command to access the cv  Python virtual environment.
  3. Attempt to import the Python + OpenCV bindings.

I have demonstrated how to perform these steps below:

$ cd ~
$ workon cv
$ python
Python 3.5.2 (default, Jul  5 2016, 12:43:10)
[GCC 5.4.0 20160609] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
>>> cv2.__version__
非虚拟环境配置Python3 + opencv3
cmake -D BUILD_opencv_python3=YES -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 (自定义安装目录) -D OPENCV_EXTRA_MODULES=../../opencv_contrib/modules -D PYTHON3_LIBRARIES=/usr/lib/x86_64-linux-gnu/ -D PYTHON3_NUMPY_INCLUDE_DIRS=/home/chienshu/.local/lib/python3.5/site-packages/numpy/core/include/ ..
各个 = 之间不能有空格

Share this to:


电子邮件地址不会被公开。 必填项已用*标注