Exploring OpenCV

OpenCV (Open-Source Computer Vision) is an OS computer vision & ML  library which has 2500+ optimized algorithms. These algorithms have wide variety of applications including face recognition & detection, classifying human actions from videos, tracking eye movements, object identification, moving object tracking, image stitching to supply high-resolution image of the whole scene etc.

It supports OS platforms like Android, Linux, MacOS & Windows and provides interfaces in C++, Python, JAVA, and MATLAB. Mostly the applications of OpenCV are aligned to real-time vision taking advantage of Matrix Math Extensions(MMX) and Streaming SIMD Extensions(SSE) instructions when available. The Modular structure of OpenCV, which is developed using C++, are:

  • core – comprises of basic data structures that all other modules are referenced from.
  • videoio – interface to video codecs and video capturing
  • highgui – interface for simple GUI’s
  • imgproc – handles image processing like non-linear & linear image filtering, histograms, geometrical image transformations (generic table-based remapping, affine & perspective warping, resize), color space conversion etc.
  • video – handles video analysis like object tracking, background subtraction, motion estimation
  • calib3d – algorithms like stereo correspondence & basic multiple-view geometry, elements of 3D reconstruction & object pose estimation.
  • features2d – salient feature detectors, descriptors and descriptor matchers
  • objdetect – object detection and also provides predefined classes for people, cars, eyes, faces etc.
  • and few modules like Google test wrappers & FLANN , Python bindings etc.

A sample python code for recognizing sign plate from an image is given below:

import cv2
from matplotlib import pyplot as plot

# Load sample image
test_image = cv2.imread("image.jpg")

# By default OpenCV loads images as BRG
# gray scale version for object detection
gray_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
# rgb version for ploting the result
rgb_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2RGB)

# Load the haar classifier
stop_haar = cv2.CascadeClassifier('stop_data.xml')

# Find parts in image matching the classifier
signs_found = stop_haar.detectMultiScale(gray_image, minSize =(20, 20))
count = len(signs_found)
if count != 0:
    for (h, w, width, height) in signs_found:
        # A rectangle drawn where sign is recognized
        cv2.rectangle(rgb_image, (h, w),
                    (h + height, w + width),
                    (0, 255, 0), 5)       

# Plot the result
plot.subplot(1, 1, 1)
plot.imshow(rgb_image)
plot.show()

which gives below given result:

The xml stop_data.xml is a Haar cascade classifier. Haar cascade is an approach to train a classifier using lots of positive and negative images.

OpenCV is extensively used by well-established companies like Google, Microsoft, Intel, IBM, Honda, Toyota, Sony along with startups like Applied Minds, VideoSurf, and Zeitera.

Deployed usage of OpenCV span the range from drowning accident detection in swimming pool in Europe, street-view image stitching, mine equipment monitoring in China, intrusion detection in surveillance video in Israel, checking runways for debris in Turkey to rapid face detection in Japan.

Author Details

Jewel Jacob

He is a Technology Lead at Infosys - Digital Experience IP Platforms specialized in Angular. He also have skills in cloud development in AWS and Azure. He is contributing to IP solutions provided by Live Enterprise. He will be focusing on the emerging technologies mainly Artificial Intelligence and server less computing.

Leave a Comment

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