How to install OpenCV on Ubuntu 20.04?
Overview
OpenCV is a Machine Learning software library. OpenCV aims to speed up the use of computer vision in commercial products. The software provides interfaces for different programming languages supporting various operating systems.
Prerequisites
There are certain prerequisites that need to be met before you begin.
A server running Ubuntu version 20.04.
Non-root sudo privileges.
Get Started
We can install OpenCV using any of the two methods outlined below:
Method 1 - Installing OpenCV from the Ubuntu Repository
Update the existing Ubuntu packages.
To install OpenCV run the command given below:
To confirm the successful installation of OpenCV, import the cv2 module and display the version of OpenCV.
Method 2 - Installing OpenCV from the Source
To obtain the latest version of the OpenCV library, building it directly from the source code is advisable. This method is highly recommended for installing OpenCV.
Follow the steps given below to install OpenCV (latest version):
Set up the required build tools and dependencies.
Create a new directory named opencv_build in the user's home directory and change the current directory to opencv_build.
Clone the repositories of OpenCV.
Clone the repositories of OpenCV contrib.
Create a temporary build directory.
Configure the OpenCV build using CMake:
The resulting output should resemble the following:
Determine the number of processing units (or CPU cores) available on the system.
Commence the compilation process:
Adjust the value of the -j
flag to match the number of processing units (or CPU cores) available on the system.
Install OpenCV from its source code.
To confirm the successful installation, enter the following commands, and you should observe the version of OpenCV being displayed.
Conclusion
We have successfully demonstrated how to install OpenCV on Ubuntu 20.04.
Last updated