How to Install and Configure OpenCV on Rocky Linux 8.4

Install and Configure OpenCV on Rocky Linux 8.4
How to Install and Configure OpenCV on Rocky Linux 8.4

Today we learn To install and Configure OpenCV on Rocky Linux 8.4, AlmaLinux 8.4 and CentOS 8OpenCV (Open Source Computer Vision Library) is open-source software with bindings for C++, Python, and Java. OpenCV is used for a variety of applications, including medical image analysis, creating street scene images, surveillance video, detecting and recognizing faces, tracking moving objects, extracting 3D models, and more.

OpenCV can take advantage of multi-core processing and GPU acceleration features for real-time operations.

This tutorial, shows how to install and Configure OpenCV on Rocky Linux 8.4, Alma Linux 8.4 and CentOS 8. The easiest way to install OpenCV on Rocky Linux and CentOS is to install it directly from the Rocky Linux and CentOS repository. If you want to install the latest stable version of OpenCV from source, scroll down on this tutorial page.

Choose one of the installation options that suits you best.

Install OpenCV from Rocky Linux and CentOS Repository

The OpenCV module is available from the standard Rocky Linux 8.4 and CentOS repository. To install the OpenCV module, enter the command:

sudo dnf install opencv opencv-devel opencv-python 

Once the installation is complete, you can verify it by running:

pkg-config --modversion opencv 

Install and Configure OpenCV on Rocky Linux 8.4 and CentOS from Source

Building the OpenCV library from source is the recommended way to install OpenCV. It will be optimized for your particular system, and you will have complete control over the build options.

To install the latest version of OpenCV from source, perform the following steps:

1) Install the necessary tools and dependencies:

sudo dnf install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python3 python3-devel python3-pip cmake python3-devel python3-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel tbb-devel libv4l-devel eigen3-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel gstreamer1-plugins-base

2) Clone the OpenCV contrib and OpenCV repository with the following command:

mkdir -p ~/opencv_build && cd ~/opencv_build 
git clone https :// 
git clone https :// 

At the time of writing, the default version in the github repository is version 4.2.0. If you want to install an older version of OpenCV, do the command cd to the directory opencvand opencv_contriband run git checkout <versi_opencv_lain>

3) Once the download is complete, create a directory temporary build , and go to that directory :

cd ~/opencv_build/opencv && mkdir build && cd build 

Configure the OpenCV build with the following CMake command:

-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ 

When the CMake build system is complete, you will see an output like below

— Configuring done

— Generating done

— Build files have been written to: /home/vagrant/opencv_build/opencv/build

4) Start the compilation process with:

make -j8 

Change the flag -j according to your processor core. If you don’t know the number of cores on your processor, you can find it by typing the command nproc.

The Compilation process may take a few minutes or more, depending on your system configuration.

5) Install the OpenCV libraries by typing:

sudo make install

6) Create a symlink file opencv4.pc to the directory /usr/share/pkgconfig and run ldconfig to rebuild the libraries cache.

sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/ sudo ldconfig 

Check the OpenCV version by typing:

pkg-config --modversion openc
v4 4.3.0

7) To enable Python modules cv2 run:

python3 -c "import cv2; print(cv2.__version__)" 




In this advanced Linux guide we’ve shown you two different ways to install OpenCV and Configure on Rocky Linux 8.4, AlmaLinux 8.4 and CentOS 8 server. The method you choose depends on your needs and preferences.

While to Install and Configure OpenCV on Rocky Linux 8.4 a packaged version from the Rocky Linux, AlmaLinux and CentOS repository is easier, building OpenCV from source gives you more flexibility.

Related Tutorials and OS Download links :

Rocky Linux 8.4 Stable Version Download

AlmaLinux OS 8.4 Update Available to Download

How to Add EPEL Repository on Rocky Linux, AlmaLinux and CentOS

How to Install and Configure Ansible AWX on Rocky Linux 8.3 and CentOS 8

How to install Snap Store in Linux Mint 20 / Linux Mint 20.1

How to Fix recovering journal Error on Ubuntu boot up

Be the first to comment

Leave a Reply

Your email address will not be published.