In this blog I am going to explain object detection using OpenCV library.
OpenCV (Open Source Computer Vision Library: http://opencv.org) is an open-source BSD-licensed library that includes several hundreds of computer vision algorithms. It has modules like Image Processing, Video Analysis, Object Detection. OpenCV was designed for computational efficiency and with a strong focus on real-time applications.
A Haar Cascade is a classifier which is used to detect the object for which it has been trained for, from the source. The Haar Cascade is by superimposing the positive image over a set of negative images. The training is generally done on a server and on various stages.
I have downloaded two files 'haarcascade_frontalcatface.xml' and 'haarcascade_frontalcatface_extended.xml'
Set tunable parameters like scale factor and minimum neighbors.
I am reading 6 images of cats and 1 image dog. First convert the image to gray scale. Use the above two haar cascades to get coordinates of rectangles where cat front face is located (if any). Plot the rectangles.
When there are some errors retry with different scale factor and minimum neighbors parameters.
As you can see it plots the rectangles around 6 images of cats properly and doesn’t plot anything around the dog face as expected.
Code is in my github repository.
You can also look at yolo object detection blog https://www.pyimagesearch.com/2018/11/12/yolo-object-detection-with-opencv/
Thanks to my models : Alien, Princess, Boy and Lucky
This site is also posted in my personal blog here.