Blogs about Deep Learning, Machine Learning, AI, NLP, Security, Oracle Traffic Director,Oracle iPlanet WebServer

Cat face detection using OpenCV

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.

Download haar-cascade xml files from  link here. Read license terms before downloading, copying, installing or using. You can create your own haar cascade files by looking at the videos here.

 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


·       https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html#face-detection

·       https://opencv.org/

·       https://www.quora.com/What-is-haar-cascade

·        https://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html

·       https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/

·       https://github.com/opencv/opencv/tree/master/data/haarcascades

This site is also posted in my personal blog here.


Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.