Linux

How to Install the Open Source Computer Vision Library (OpenCV) on CentOS 8

How to Install the Open Source Computer Vision Library (OpenCV) on CentOS 8

OpenCV is short for “Open Source Computer Vision Library” is a library of open-source cross-platform computer vision algorithms that can be used in all types of visual processing areas, such as face recognition, gesture recognition and movement tracking. It was specifically designed to utilize multi-core processing and GPU acceleration features for real-time operations. It can be installed on several operating systems, including Windows, Linux, Android, iOS, etc.

In this tutorial, we will explain how to install OpenCV on CentOS 8.

Precondition

  • Server running CentOS 8.
  • The root password is set on your server.

Install the Required Package

By default, OpenCV is not available in the CentOS 8 default repository. So you need to compile it from its source. To compile OpenCV, you must install the dependencies needed on your system. You can install everything with the following command:

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

After all packages have been installed, you can proceed to the next step.

Install OpenCV

First, create a build directory for OpenCV with the following command:

mkdir -p ~/opencv_build

Next, change the directory to opencv_build and download the latest version of OpenCV and source the contribution of OpenCV with the following command:

cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

Next, change the directory to open and create a temporary build directory with the following command:

cd opencv
mkdir build

Next, change the directory to the build directory and configure OpenCV with the following command:

cmake -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 ..

You should get the following screen:

1

Next, start compiling with the following command:

make -j4

You should get the following screen:

2

Finally, install OpenCV with the following command:

make install

You should get the following screen:

3

Next, create the symbolic link opencv4.pc to the / usr / share / pkgconfig directory:

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

Next, rebuild the library cache with the following command:

ldconfig

Next, you can verify the version of OpenCV with the following command:

pkg-config --modversion opencv4

You should get the following output:

4.3.0

You can also verify the Python cv2 module with the following command:

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

You should get the following output:

4.3.0-dev

Conclusion

Congratulations! You have successfully installed OpenCV from its source. For more information about OpenCV, you can visit the official OpenCV website directly.

Related posts

How to Install KVM on Ubuntu 20.04 LTS

Linux

How Linux makes data recovery easy

Linux

How to Install Nextcloud with Nginx and Let’s Encrypt SSL on Ubuntu 20.04 LTS

Linux

How to delete a Terminal on Ubuntu and other Linux distributions

Linux

How to Install Vagrant on Ubuntu 20.04

Linux

How to Install Anaconda on Ubuntu 20.04

Linux

How to Install Joomla with Apache2 and Let’s Encrypt on Ubuntu 20.04

Linux

How to Install Sensu Monitoring on Ubuntu 20.04

Linux

How to Install the Rudder System Audit Tool on Ubuntu 20.04

Linux