How To Install OpenCV on AlmaLinux 8

Install OpenCV on AlmaLinux 8

In this tutorial, we will show you how to install OpenCV on AlmaLinux 8. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is open-source software with bindings for C++, Python, and Java. OpenCV provides a real-time optimized Computer Vision library, tools, and hardware. It also supports model execution for Machine Learning (ML) and Artificial Intelligence (AI).

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the OpenCV on AlmaLinux 8. You can follow the same instructions for CentOS and Rocky Linux.

Install OpenCV on AlmaLinux 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf update
sudo dnf install epel-release
sudo dnf install opencv opencv-devel opencv-python

Step 2. Installing Dependencies.

Now we install the necessary tools and dependencies to your system:

sudo dnf install 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

Step 2. Installing OpenCV on AlmaLinux 8.

Once dependencies are installed, now clone the OpenCV contrib and OpenCV repository with the following command below:

mkdir -p ~/opencv_build && cd ~/opencv_build 
git clone https ://github.com/opencv/opencv.git 
git clone https ://github.com/opencv/opencv_contrib.git

Next, create a directory temporary build, and go to that directory:

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

After that, configure the OpenCV build with the following CMake command:

cmake3 -D CMAKE_BUILD_TYPE=RELEASE \ 
-D CMAKE_INSTALL_PREFIX=/usr/local \ 
-D INSTALL_C_EXAMPLES=ON \ 
-D INSTALL_PYTHON_EXAMPLES=ON \ 
-D OPENCV_GENERATE_PKGCONFIG=ON \ 
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ 
-D BUILD_EXAMPLES=ON ..

Start the compilation process by using the following command:

make -j8 
sudo make install

Finally, we create a symlink file opencv4.pc to the directory /usr/share/pkgconfig and run ldconfig to rebuild the library’s cache.

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

You can verify the OpenCV successfully installed in your system by checking the version of installed OpenCV:

pkg-config --modversion openc

To enable Python modules cv2 run the following command below:

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

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing the OpenCV (Open Source Computer Vision Library) on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official OpenCV website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!