• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install OpenCV on CentOS 8 Server

Written by Admin, Updated On May 28, 2020
centos, opencv, python
How to Install OpenCV on CentOS 8

OpenCV (Open Source Computer Vision Library) is an open source computer vision library with bindings for C++, Python, and Java and supports all major operating systems. In this tutorial, we will show you how to install OpenCV on CentOS 8 system.

OpenCV can be deployed on various platforms, including Windows, Linux, Android, iOS, etc. The OpenCV installation is quite simple.

Prerequisites#

Before you start to install OpenCV on CentOS machine, you must logged in as root or sudo user.

Install OpenCV from the CentOS Repository#

By default, CentOS 8 standard repositories includes OpenCV package. Run the following command to install the OpenCV packages:

sudo dnf install opencv opencv-devel opencv-python

Verify OpenCV installation by checking version, type:

pkg-config --modversion opencv
3.4.1

Install OpenCV from the Source#

If you would prefer the latest version of OpenCV library, you can get it directly from the source. Perform the following steps to install the latest OpenCV version from the source:

1. Install dependencies#

Run the following command to install required dependencies:

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

2. Clone repositories#

Next, clone OpenCV and OpenCV contrib repositories using following commands:

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

Currently, while writing this tutorial, the latest stable version is 4.3.0.

3. Create build directory#

Now, create a temporary build directory and navigate to inside it:

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

Use the CMake command to configure the 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 ..

It should return output as below:

-- Configuring done
-- Generating done
-- Build files have been written to: /home/vagrant/opencv_build/opencv/build

4. Start compilation#

Execute the below command to start the compilation process:

make -j4

Ensure that here in -j option you should provide number of processor as per your system. You can find number of processor by typing nproc.

Depending on your system resources, compilation process may take few minutes.

5. Install OpenCV libraries#

To install OpenCV libraries, type:

sudo make install

6. Create symlink#

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

7. Verify installation#

pkg-config --modversion opencv4
4.3.0

Conclusion#

You successfully learned multiple ways to install OpenCV on your CentOS 8 server.

If you have any questions or feedback, feel free to comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Anaconda on Ubuntu 20.04
Next Article   How to Install Node.js on Ubuntu 20.04 LTS

Related Posts

  • How to Install Python 3.9 on CentOS 8

    How to Install Python 3.9 on CentOS 8

    December 31, 2020
  • How to Install GIMP 2.10 on CentOS 8

    How to Install GIMP 2.10 on CentOS 8

    December 30, 2020
  • How to Install Notepad++ on CentOS 8

    How to Install Notepad++ on CentOS 8

    December 26, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on Debian 10
    How to Install Python 3.9 on Debian 10 December 25, 2020
  • How to Install Python 3.9 on Ubuntu 20.04
    How to Install Python 3.9 on Ubuntu 20.04 December 21, 2020
  • How to Install GIMP on Ubuntu 20.04
    How to Install GIMP 2.10 on Ubuntu 20.04 December 22, 2020
  • How to Install Notepad++ on Debian 10
    How to Install Notepad++ on Debian 10 December 23, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook