Introduction

OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. This tutorial will guide you through the process of installing OpenCV on Ubuntu 22.04.

Prerequisites

Before you begin, ensure you have:

  1. An Ubuntu 22.04 system
  2. Root or sudo privileges

Step 1: Update System Packages

Update the package index and upgrade the system packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Dependencies

Install dependencies required for building OpenCV:

sudo apt install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

Step 3: Download OpenCV Source Code

Clone the OpenCV and OpenCV-contrib repositories from GitHub:

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

Step 4: Build OpenCV

Create a build directory and navigate into it:

mkdir -p ~/opencv/build
cd ~/opencv/build

Generate the Makefile using CMake:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..

Build OpenCV using the generated Makefile:

make -j$(nproc)

Step 5: Install OpenCV

Install OpenCV:

sudo make install

Step 6: Verify Installation

Verify the installation by checking the OpenCV version:

pkg-config --modversion opencv4

Conclusion

Congratulations! You have successfully installed OpenCV (Open Source Computer Vision Library) on Ubuntu 22.04. You can now start using OpenCV for computer vision and machine learning tasks.

Was this answer helpful? 0 Users Found This Useful (0 Votes)