• 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.11 on Debian 11

    How to Install Python on Debian 11

    January 25, 2023
  • How to Install Php 8 on CentOS 8

    How to Install PHP 8 on CentOS 8

    January 27, 2021
  • How to Install Python 3.9 on CentOS 8

    How to Install Python 3.9 on CentOS 8

    December 31, 2020

1 Comment

  1. Aravindh Reply
    June 10, 2021 at 5:53 pm

    Hi, I am using CentOS 8 stream. I new to linux itself. I want cv2 for programming. I tried the above mentioned method. I could not install cmake3. But I tried installing with cmake. But at the end, when I run pkg-config –modversion opencv4 command, I am getting the error stating that the cv2 module does not exist. Can you clear me this doubt?

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 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