Easy Guide To Install OpenCV on AlmaLinux 9

This tutorial intends to teach you to Install OpenCV on AlmaLinux 9. OpenCV is a great tool for image processing and performing computer vision tasks. It is an open-source library that can be used to perform tasks like face detection, objection tracking, landmark detection, and much more. It supports multiple languages including Python, java, and C++. 

You can now proceed to the following steps provided by the Orcacore website to Install OpenCV on AlmaLinux 9 from the dnf repository and the source.

Steps To Install OpenCV on AlmaLinux 9

To complete this guide, log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 9.

You can now follow the guide steps to Install OpenCV on AlmaLinux 9 from the available repository or build it from the source.

OpenCV Setup on AlmaLinux 9

Step 1 – Install OpenCV from the AlmaLinux DNF Repository

At this point, you can easily install your OpenCV from the AlmaLinux 9 repository.

First, update your local package index with the command below:

sudo dnf update -y

Next, install the Epel repository on your server :

sudo dnf install epel-release -y

Enable PowerTools by using the command below:

sudo dnf config-manager --set-enabled crb

Then, use the command below to install OpenCV:

sudo dnf install opencv opencv-devel -y

This command will install all packages necessary to run OpenCV.

You can verify your installation with the following command:

pkg-config --modversion opencv 
Output
4.6.0

Step 2 – Install OpenCV from Source on AlmaLinux 9

It’s recommended to use this way to Install OpenCV on AlmaLinux 9.  It will be optimized for your particular system, and you will have complete control over the build options.

To install the latest and stable version of OpenCV from the source follow the steps below.

First, update your local package index with the following command:

sudo dnf update -y

Then, you need to install the dependencies with the following command:

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

Now create a directory for OpenCV on AlmaLinux 9 and switch to it with the following command:

# sudo mkdir ~/opencv_build 
# sudo cd ~/opencv_build

Clone OpenCV Repositories

Next, you need to clone the OpenCV and opencv_contrib repositories with the following commands:

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

When your download is completed, create a temporary build directory and switch to it with the following command:

# sudo cd ~/opencv_build/opencv
# sudo mkdir build
# sudo cd build

Compile and Build OpenCV

Here you need to set up OpenCV build with CMake on AlmaLinux 9:

sudo cmake ../

In your output you will see:

Output
-- Configuring done
-- Generating done
-- Build files have been written to: /root/opencv_build/opencv/build

Now start the compilation process:

make -j2

Note: Modify the -j flag according to your processor. If you do not know the number of cores in your processor, you can find it by typing nproc.

This will take some minutes or more to complete.

In your output you will see:

Output
...
[100%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/util/variant_tests.cpp.o
[100%] Linking CXX executable ../../bin/opencv_test_gapi
[100%] Built target opencv_test_gapi

Now you can Install OpenCV on AlmaLinux 9 with the following command:

sudo make install

Finally, 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

To enable Python modules cv2 run the following command below:

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

That’s it you have successfully installed OpenCV on AlmaLinux 9.

Conclusion

At this point, you have learned to install OpenCV from the source, and also you can install it from the AlmaLinux repository. It is recommended to build and install OpenCV on AlmaLinux 9 from the source to have more control over it.

Hope you enjoy it. You may also like these articles:

Install and Configure OpenNMS on AlmaLinux 9

Install and Use Arpwatch on AlmaLinux 9

Create a Bootable USB Without Rufus: Top 5 Alternatives

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!