CentOSLinuxUbuntu

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

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

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 the 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!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button