How To Install OpenCV on CentOS 8

Install OpenCV on CentOS 8

In this tutorial, we will show you how to install OpenCV on CentOS 8. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is an open-source, highly optimized computer library mainly used in applications for image processing. It has a variety of inbuilt images processing functions helping you to get started easily. It runs on Linux, Windows, Mac OS, iOS, and Android.

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 through the step by step installation OpenCV on a CentOS 8 server.

Install OpenCV on CentOS 8

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

sudo dnf clean all
sudo dnf update

Step 2. Installing OpenCV on CentOS 8.

  • Install OpenCV from the CentOS Repository:
sudo dnf install opencv opencv-devel opencv-python

Now verify that OpenCV library exists by running:

pkg-config --modversion opencv
  • Install OpenCV from the Source:
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

Next, clone both OpenCV’s and OpenCV contrib repositories:

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

Once the download is completed, create a temporary build directory, and switch it:

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

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

Next, create symlink opencv4.pc file to the /usr/share/pkgconfig directory and run ldconfig to rebuild the libraries cache:

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

Now we check the OpenCV version:

pkg-config --modversion opencv4

To verify the Python cv2 module run:

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

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing OpenCV on CentOS 8 system. For additional help or useful information, we recommend you to 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!