OpenCV (Open Source Computer Vision Library) is open source software that contains links to C ++, Python, and Java. OpenCV is used in a wide variety of applications, including medical image analysis, street scene image creation, surveillance video, face detection and recognition, tracking of moving objects, 3D model extraction, and more.
OpenCV can take advantage of multi-core processing features and GPU acceleration for real-time operations.
This tutorial shows how to install OpenCV on CentOS 8. The easiest way to install OpenCV on CentOS is to install it directly from the CentOS repository. If you want to install the latest stable version of OpenCV from the source, scroll down on this tutorial page.
Choose one of the installation options that suits you.
Install OpenCV from the CentOS repository
OpenCV modules are available from standard CentOS repositories. To install the OpenCV module, enter the command:
sudo dnf install opencv opencv-devel opencv-python
After the installation is complete, you can check this by running:
pkg-config --modversion opencv
3.4.1
Install OpenCV from the source
Building an OpenCV library from source is the recommended way to install OpenCV. It will be optimized for your own system, and you will have complete control over building options.
To install the latest version of OpenCV from the source, do the following steps:
- Install the necessary tools and 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 the OpenCV contribution and the OpenCV repository with the following command:
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 the time of writing, the default version in the Github repository is version 4.2.0. If you want to install an older version of OpenCV, run the command
cd
To the directoryopencv
And theopencv_contrib
And run awaygit checkout <versi_opencv_lain>
- After the download is complete, create a temporary create directory, and enter that directory:
cd ~/opencv_build/opencv && mkdir build && cd build
Create OpenCV build with the following 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 ..
When the CMake build system is complete, you will see the output like below
-- Configuring done -- Generating done -- Build files have been written to: /home/vagrant/opencv_build/opencv/build
- Begin the assembly process by:
make -j8
Change the flag
-j
According to the processor core. If you don’t know how many cores are on your processor, you can find it by typing a commandnproc
.The translation process may take several minutes or more, depending on your system configuration.
- Install OpenCV libraries by typing:
sudo make install
- Associate the file with the icon
opencv4.pc
To the directory/usr/share/pkgconfig
And run awayldconfig
To rebuild the cache libraries.sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/ sudo ldconfig
Check the OpenCV version by typing:
pkg-config --modversion opencv4
4.3.0
- To activate the Python console
cv2
Running:python3 -c "import cv2; print(cv2.__version__)"
Output
4.3.0-dev
Conclusion
We showed you two different ways to install OpenCV on your CentOS 8 server. The method you choose depends on your needs and preferences.
While installing the packed version of CentOS repository, creating an OpenCV from source gives you more flexibility.
.
Originally posted 2020-11-17 06:39:46.