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 apt–get package manager to refresh and upgrade and pre-installed packages/libraries:
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:
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:
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.
# virtualenv and virtualenvwrapper
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:
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
cmake ../opencv-3.3.0 -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local
make # make -j4表示开4个线程来进行编译
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:
- Open up a new terminal.
- Execute the workon command to access the cv Python virtual environment.
- Attempt to import the Python + OpenCV bindings.
I have demonstrated how to perform these steps below: