How to Install OpenCV in Ubuntu?
Last Updated :
09 May, 2024
OpenCV is a powerful and versatile library widely used for real-time computer vision tasks. It's commonly used in applications like image and video processing, object detection, facial recognition, and more. Recent versions of Ubuntu come with pre-built OpenCV packages available through the apt package manager.
For some reason, if you prefer a different version than what's available in the repositories, or you're using an older version of Ubuntu that doesn't have OpenCV pre-built in it's repository, in this article we will discuss two methods for installing OpenCV in Ubuntu.
1. Install OpenCV in Ubuntu using APT package manager
Step 1 : Update Package List
To make sure we are getting the latest version of OpenCV, update the package list using apt update command.
sudo apt update -y
updating packagesStep 2: Install OpenCV
Once repositories are up to date, we will install opencv using apt install command.
sudo apt install python3-opencv
installing opencv using APT Package manager Step 3 : Verify installation
Once, installation is done, verify installation using print(cv2.__version__) command in python shell.
To open python shell, first type python3 in your terminal.
python3
Once python3 shell is opened, print version number of opencv using following command.
Python
import cv2
print(cv2.__version__)
verifying installation2. Install OpenCV in Ubuntu by Compiling from sources
Step 1 : Installing dependencies
In order to install opencv from github source, we will need to download required dependencies using apt install command as follows
sudo apt install build-essential cmake wget unzip git -y
installing build dependenciesStep 2 : download opencv source
In this step, we will download official source code from opencv github page using git clone command.
git clone https://github.com/opencv/opencv.git
cloning opencv sources from githubStep 3 : Navigate to opencv directory and making configuration
Once repo is cloned, navigate to cloned directory using cd command.
cd opencv
Now create build directory for compiling sources using mkdir command and navigate to it using cd command.
mkdir build
cd build
creating and navigating to build directoryStep 4: Compiling and building packages for installation
Once we are in build directory, use cmake command to start compiling build files for installation.
cmake ../
compiling source codeOnce compilation is done, we will make build packages using make command.
make
building package using "make"Step 5: Installing openCV
After packages are built, install it using make install command.
sudo make install
installing opencv using make install commandStep 6 : Verify installation
Once, installation is done, verify installation using print(cv2.__version__) command in python shell.
To open python shell, first type python3 in your terminal.
python3
Once python3 shell is opened, print version number of opencv using following command.
Python
import cv2
print(cv2.__version__)
verifying installation Conclusion
In this article, we've discussed two methods for installing OpenCV on Ubuntu. For most users, the recommended approach is to use the Ubuntu repositories (using APT package manager) due to its ease of installation, compatibility with system, and access to regular security updates. However, if you require a specific version not available in the repositories, or need to install a latest development version, compiling OpenCV from source can be a suitable alternative.
Similar Reads
How to Install OpenShot in Ubuntu
For Windows, macOS, Linux, and Chrome OS, OpenShot Video Editor is a free and open-source video editor. Jonathan Thomas launched the project in August 2008 with the goal of creating a reliable, free, and user-friendly video editor. Since version 2.1.0, the software has supported Windows, macOS, and
2 min read
How to install make on Ubuntu
The "make" program in Linux is used to compile and manage a set of source code applications and files. It allows developers to install and gather a range of apps via the terminal. It also controls and cuts down on the amount of time necessary for compilation. The basic objective of the make command
3 min read
How to Install opencv in C++ on Linux?
OpenCV stands for open-source Computer Vision Library. It is a library that provides infrastructure for computer vision and machine learning applications. It has more than 2500 Computer vision and machine learning algorithms. They can be used to track objects, recognize faces and objects, stitch ima
3 min read
How to Install OpenCV for Python in Linux?
Prerequisite: Python Language Introduction OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in todayâs systems. By using it, one can process images and videos to identify ob
2 min read
How to Install Pixeluvo package on Ubuntu?
Pixeluvo is a gorgeous picture and photo editor for Linux and Windows that supports Hi-DPI displays, new camera RAW formats, and other capabilities. A commercial license is required to utilize it, and a license for Pixeluvo full version costs $34 and includes all future upgrades for that major versi
1 min read
How to Install OpenJDK in Linux
If you have started Java learning, you must have the Java Development Kit (JDK) installed on your system. OpenJDK is a free and open-source version of Java that provides everything you need to develop and run Java applications. Itâs a popular choice for developers because itâs easy to install and wo
4 min read
How to install OpenCV Contrib Python
OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. It provides various tools and algorithms for image and video processing, object detection, feature extraction, and more. OpenCV Contrib is an extension module that includes a
2 min read
How to install OpenCV latest Version?
OpenCV, an open-source computer vision and machine learning software library, is widely used for various image and video processing tasks. Keeping it up-to-date ensures access to the latest features and enhancements. In this article, we will see how we can upgrade the latest Opencv Version in Python
1 min read
How to Install OpenCV Python Headless?
OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. It enables developers to access a wide range of algorithms for various computer vision tasks. In this article, we will see how to install OpenCV Python Headless. What is Open
2 min read
How to Install Opencv 4 on MacOS?
In this article, we will learn how to install Opencv 4 in Python on MacOS. OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. Installation:Method 1: Using pip to install Opencv 4 Package Follow the below steps to install the
2 min read