Insight: How To Install OpenCV On CentOS 8
OpenCV or Open Source Computer Vision Library is an open-source computer vision library. In this tutorial post, we are going to show you the process of installing OpenCV on CentOS 8.
How To Install OpenCV On CentOS 8
Install OpenCV from the CentOS Repository
The OpenCV packages are available from the CentOS 8 standard repositories. Run the following command to install the OpenCV packages by typing:
sudo dnf install opencv opencv-devel opencv-python
Now verify that OpenCV library exists by running:
pkg-config --modversion opencv
Installing OpenCV from the Source
Install the required and optional 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
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
Create a temporary build directory, and switch to it:
cd ~/opencv_build/opencv && mkdir build && cd build
Run the 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 ..
Compile using the following command:
make -j8
note: Modify the -j
flag according to your processor.
Install the OpenCV libraries with:
sudo make install
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