What is openCV?

OpenCV (Open Source Computer Vision) is a library of programming functions mainly which aims at real-time computer vision. It has C++, Python, Java and MATLAB interfaces and it supports Windows, Linux, Android and Mac OS.

It can detect and recognize faces, identify objects, identify human actions in videos, track camera movements, track moving objects, stitch images together to produce a high resolution image of an entire scene, find similar images from an image database, remove red eyes from images taken using flash, follow eye movements, etc.

How to install openCV?

1st Method

Install all packages with following command in terminal as root.(the screenshot aslo contains numpy, Please ignore it)

sudo dnf install opencv        # For C++


dnf

OR

You can also do this

dnf install python3-opencv        # For Python

dnf2

OR

2nd Method

Install from PyPi store

pip3 install opencv-python        # For Python x86

pip

3rd Method(From Source)

  • 1st we need to install the dependencies before we need to start, type this in you terminal:
    • sudo dnf install cmake-gui ffmpeg-devel libpng-devel libjpeg-turbo-devel jasper-devel libtiff-devel tbb-devel eigen3-devel
  • Now we need to download openCV
    • yum install git
    • git clone https://github.com/Itseez/opencv.git
  • Now change directory to the downloaded file(opencv) and Create a new build folder
    • mkdir build
    • cd build
  • Now, lets move to the most important part, the installation part. Installation has to be configured using cmake(specifies which modules are to be installed, installation path, which additional libraries to be used).
    • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • (optional) To install TBB and Eigen
    • cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..
  • To Enable documentation and disable tests and samples, type this
    • cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..
  • Let’s disable all GPU modules
    • cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
  • Now lets set the installation path and build type
    • cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • If all goes well you will get this,terminal
  • Now let’s build the files using make command and install it using make install command. make install should be executed as root(sudo).
    • make
    • su
    • make install
  • The installation process is over,  All files are installed in /usr/local/.

Configure openCV to run with python

  • Move the module to any folder in Python Path
    • su mv /usr/local/lib/python3.6/site-packages/cv2.so /usr/lib/python3.6/site-packages
  • Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH
    • export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.6/site-packages

Test the installation

Open up a terminal and type pythonand in the python interpreter type import cv2, it should import without any errors.

python3