OpenCV a library for object recognition in images and cameras

openCV

OpenCV is a free library of cross-platform machine vision (existing versions for GNU / Linux, Mac OS X, Windows and Android) that was originally developed by Intel and used in countless applicationsfrom security systems with motion detection, to process control applications where object recognition is required. This is because its publication is given under the BSD license, which allows it to be used freely for commercial and research purposes with the conditions expressed therein.

Open CV contains more than 500 functions covering a wide range of areas in the vision process, such as object recognition (facial recognition), camera calibration, stereo vision, robotic vision, classify actions in video, convert images, extract 3D models, create 3D space from a stereo camera image creating high quality images by combining images low quality.

Also offers the ability to search for images of similar objects to the set of elements presented by applying machine learning methods, organizing markers, identifying common elements in different images, automatically eliminating defects such as red eyes.

OpenCV provides more than 2500 algorithms, both classic and reflective of the latest achievements in the field of computer vision and machine learning systems. The library code is written in C ++ and distributed under the BSD license.

About the new version OpenCV 4.2

Today the library is in its OpenCV 4.2 versionIn which in the DNN module (Deep neural network) with the implementation of machine learning algorithms based on neural networks, added a backend to use CUDA and experimental support for the nGraph OpenVINO API was implemented.

In addition to using SIMD instructions, we optimize code performance for stereo output (StereoBM / StereoSGBM), resize, mask, rotate, calculate missing color components, and many other operations.

In the G-API module (opencv_gapi), which acts as an engine for processing efficient imaging using graphics-based algorithms, supports more complex hybrid algorithms for computer vision and deep machine learning. Provides support for the Intel Inference Engine. Added support for video stream processing to the execution model.

Vulnerabilities (CVE-2019-5063, CVE-2019-5064) that could lead to the execution of attack code by processing unverified data in XML, YAML and JSON formats were also fixed. If a character with a null code is found during JSON parsing, the entire value is copied to the buffer, but without proper verification of the limits of the allocated memory area.

Of the other changes presented in this new version:

  • Added multithreaded implementation of the pyrDown function.
  • Added the ability to extract video streams from media containers (demuxing) using the FFmpeg-based video backend.
  • Added an algorithm for fast frequency selective reconstruction of damaged FSR (Frequency Selective Reconstruction) images.
  • Added RIC method for interpolation of typical blank areas.
  • Added LOGOS deviation normalization method.

How to install OpenCV 4.2?

For those interested in being able to install this library, can get the new version as well as consult the information related to the use and even find tutorials from its official website.

The link is this.

In this article We will provide the steps to be able to implement the library on a Raspberry pi.

To install OpenCV on a Raspberry Pi must have your system, which is Raspbian.

From the vWe are going to open a terminal and in it we are going to type the following commands to install dependencies, developer tools, image packages among other extra libraries:

sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libfontconfig1-dev libcairo2-dev libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran libhdf5-dev libhdf5-serial-dev libhdf5-103 libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5

Lastly, let's install the python 3 header files so that we can compile OpenCV:

sudo apt-get install python3-dev

Now let's create a Python environment with the following commands, this in order to have an isolated site:

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo python3 get-pip.py
sudo rm -rf ~/.cache/pip

We are going to install virtualenv and virtualenvwrapper:

sudo pip install virtualenv virtualenvwrapper
nano ~/.bashrc

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc
mkvirtualenv cv -p python3
pip install "picamera[array]"

Done this now we are going to compile openCV with:

cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.2.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.2.0.zip
unzip opencv.zip
unzip opencv_contrib.zip
mv opencv-4.2.0 opencv
mv opencv_contrib-4.2.0 opencv_contrib

Now we are going to increase the swap in our system since if we leave it as it is by default the system can hang:

sudo nano /etc/dphys-swapfile

And we are going to edit the CONF_SWAPSIZE variable:

CONF_SWAPSIZE=1024

We save and close with ctrl + o and ctrl + x. Then we type:

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

Now we are going to proceed to compile:

workon cv
pip install numpy
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D BUILD_EXAMPLES=OFF ..
make -j4
sudo make install
sudo ldconfig
cd /usr/local/lib/python3.7/site-packages/cv2/python-3.7
sudo mv cv2.cpython-37m-arm-linux-gnueabihf.so cv2.so
cd ~/.virtualenvs/cv/lib/python3.7/site-packages/
ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.so cv2.so

And ready.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.