In this tutorial you will learn how to install OpenCV 4 on Ubuntu 18.04. The OpenCV4 is more further optimizations, C++11 support, more compact modules and many improvements to the Deep Neural Network(DNN) module.
1. Install OpenCV4 dependencies on Ubuntu:
First thing you need to do is openning your terminal. Alternatively, you may also SSH into your vps.
1 | # Update your system and clean it. |
1 | # Install the developer tools: |
Next, Install a handful of image and video I/O libraries.
1 | # These libraries enable us to load image from disk as well as read video file. |
Install GTK for our GUI backend.
1 | sudo apt-get install libgtk-3-dev |
Followed by installing two packages which contain mathematical optimizations for OpenCV:
1 | sudo apt-get install libatlas-base-dev gfortran python3-dev |
2. Download OpenCV4:
Download both OpenCV and OpenCV_contrib. You should be installing the OpenCV library with the additional contib modules as well.
1 | # OpenCV |
From there, let’s unzip the archives:
1 | unzip opencv.zip |
3. Configure Python3 for OpenCV 4:
Download the latest pip:
1 | wget https://bootstrap.pypa.io/get-pip.py |
4. CMake and compile OpenCV 4 for Ubuntu:
Now let’s run CMake to configure the OpenCV 4 build:
1 | cd opencv # the opencv path. |
Now ready to compile OpenCV 4:
1 | make -j8 |
Note: In the make
command above, the -j8
argument specifies that I have 8 cores cpu for compilation. You should update the command to use the number of cores on your environment for faster compile.
And from there, let’s install OpenCV :
1 | sudo make install |
5. Test your OpenCV install on Ubuntu:
1 | python |