opencv 3.3.0 吐血安装

For detailed info, please refer to https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/

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 opencv.zip https://github.com/Itseez/opencv/archive/3.3.0.zip
$ unzip opencv.zip
$ wget O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.3.0.zip
$ unzip opencv_contrib.zip

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 https://bootstrap.pypa.io/getpip.py
$ sudo python getpip.py

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 ~/getpip.py ~/.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/virtualenvwrapper.sh

$ 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 ../opencv-3.3.0 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local
make # make -j4表示开4个线程来进行编译
make install

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__
‘3.1.0’
>>>

 

发表评论

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