How to install OpenCV on CentOS 8

OpenCV (Open Source Computer Vision Library) is an open source computer vision library that supports C++, Python, and Java on all major operating systems. It can play multi-core processes and GPU acceleration for real-time operation.

OpenCV has a wide range of applications, including medical image analysis, street view image processing, surveillance video, detection and recognition of faces, tracking moving objects, extracting 3D models, and so on.

This article describes how to install OpenCV on CentOS 8. To install the latest stable version of OpenCV, scroll to the section Installing OpenCV from source. Please choose the installation method that suits you best.

1. Install OpenCV from CentOS source repository

The OpenCV package is available in the CentOS 8 standard software source, but there is no Python version.

Install the OpenCV package, enter:

sudo dnf install opencv opencv-devel opencv-python

Once the installation is complete, verify that OpenCV exists and enter:

pkg-config --modversion opencv
3.4.1

2. Install OpenCV from source code

Installing OpenCV from source code allows you to install the latest available version. It will also be optimized for your specific system, and you have complete control over all build options.

Perform the following steps to install the latest OpenCV version from the source code:

  1. Install necessary and optional dependent packages:
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
  1. Clone all OpenCV and OpenCV contrib sources:
mkdir -p ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

At this time, the version in the github source repository is 4.2.0. If you want to install the old version of OpenCV, navigate to the opencv and opencv_contrib directories, and run git checkout<opencv-version> .

  1. Once the download is complete, create a temporary build directory and switch to this directory:
cd ~/opencv_build/opencv && mkdir build && cd build

Use CMake command to configure OpenCV build:

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

The output will be as follows:

- - Configuring done
- - Generating done
- - Build files have been written to:/home/vagrant/opencv_build/opencv/build
  1. Run the following command to start compilation:
make -j8

Modify the value of -f according to your processor. If you don't know the number of your processor cores, you can find it by typing nproc.

  1. Install OpenCV library
sudo make install
  1. Create a link file opencv4.pc to point to the /usr/share/pkgconfig directory, and run ldconfig to rebuild the library cache:
sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/
sudo ldconfig

To check the OpenCV version, enter:

pkg-config --modversion opencv4
4.3.0
  1. To verify the Python cv2 module, run:
python3 -c "import cv2; print(cv2.__version__)"
4.3.0- dev

Three, summary##

We have shown two different ways to install OpenCV on CentOS 8 server. Your first choice depends on your requirements and preferences.

Even though it is easy to install packages directly from CentOS source, building and installing OpenCV from source will give you more flexibility, and it should be your first choice for installing OpenCV.

Recommended Posts

How to install OpenCV on CentOS 8
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install opencv3.0.0 on ubuntu14.04
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Apache on CentOS 8
How to install OpenCV on Ubuntu 20.04
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&amp;D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to install and configure VNC on CentOS 8
How to install and use Composer on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos
How to install and configure Redmine on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04