YouTube Icon

Code Playground.

How to Install OpenCV on CentOS 7

CFG

How to Install OpenCV on CentOS 7

OpenCV (Open Source Computer Vision Library) is an open-source PC vision library with ties for C++, Python, and Java and supports all major working frameworks. It can exploit multi-center preparing and highlights GPU quickening for continuous activity. 

OpenCV is utilized for a wide scope of uses, including clinical picture examination, sewing road see pictures, reconnaissance video, identifying and perceiving faces, following moving items, extricating 3D models, and significantly more. 

In this instructional exercise, we will tell the best way to introduce OpenCV on CentOS 7. 

Install OpenCV from the CentOS Repository

The OpenCV bundle is accessible from the CentOS 7 standard stores, yet is it pretty obsolete. On the off chance that you need to introduce the most recent stable rendition of OpenCV from source, look down to the Installing OpenCV from the Source segment of this instructional exercise. 

At the hour of composing, the variant in the vaults is 2.4.5. 

Introduce the OpenCV bundles by composing: 

sudo yum install opencv opencv-devel opencv-python

When the establishment is finished you can check it by running: 

pkg-config --modversion opencv
2.4.5

Or on the other hand by bringing in the Python cv2 module and print the OpenCV rendition: 

python -c "import cv2; print(cv2.__version__)"
2.4.5

Installing OpenCV from the Source

Building the OpenCV library from the source permits you to have the most recent accessible variant. It will be improved for your specific framework, and you will have full oversight over the manufacture choices. 

To introduce the most recent OpenCV adaptation from the source, follow these means: 

Introduce the required and discretionary conditions: 

sudo yum install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel \
    python python-devel python-pip cmake python-devel python34-numpy \
    gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel \
    libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel numpy \
    eigen3-devel gstreamer-plugins-base-devel freeglut-devel mesa-libGL \
    mesa-libGL-devel boost boost-thread boost-devel libv4l-devel
mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

At the hour of composing, the default rendition in the github storehouses is variant 4.2.0. In the event that you need to introduce a more established variant of OpenCV, cd to both opencv and opencv_contrib catalogs and run git checkout <opencv-version> 

Design the OpenCV work with the accompanying CMake order: 

cd ~/opencv_build/opencv && mkdir build && cd 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 ..

When the CMake manufacture framework is settled, you will see something like beneath: 

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

Start the accumulation cycle by running the accompanying order: 

make -j8

Change the - j banner as indicated by your processor. In the event that you don't have the foggiest idea about the quantity of centers your processor, you can discover it by composing nproc. 

The aggregation may take a few minutes or more, contingent upon your framework design. At the point when finished, you will see something like this: 

[100%] Built target example_tutorial_Threshold_inRange
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python2

Introduce OpenCV with: 

sudo make install

Make symlink opencv4.pc document to the/usr/share/pkgconfig registry and run ldconfig to modify the libraries store. 

sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/
sudo ldconfig

Check the OpenCV variant by composing: 

pkg-config --modversion opencv4
4.2.0

To empower the Python cv2 module run: 

sudo ln -s /usr/local/lib/python2.7/site-packages/cv2  /usr/lib/python2.7/site-packages/

Import the module and confirm the establishment by printing the OpenCV variant: 

python -c "import cv2; print(cv2.__version__)"
4.2.0-dev

Conclusion

We have demonstrated both of you various approaches to introduce OpenCV on your CentOS 7 worker. The strategy you pick relies upon your prerequisites and inclinations. Despite the fact that introducing the bundled variant from the CentOS store is simpler, building OpenCV from source gives you greater adaptability, and it should be your first alternative when introducing OpenCV. 

On the off chance that you have any inquiries or input, don't hesitate to remark underneath.




CFG