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.
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
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:
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
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>
.
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
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
.
sudo make install
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
cv2
module, run:python3 -c "import cv2; print(cv2.__version__)"
4.3.0- dev
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