A python script implementing Haar Cascade for Face Detection on Images, Videos and WebCam feed.
Welcome to the ReadMe file for the Face Detection using Python project.
Index:
1. Introduction
This project on Face Detection has been done with the implementation of Haar Cascade in Python scripts.
There are three scripts in this project.
‘face_detect_static.py’ is the script for Face Detection on Image files as supplied by the User.
‘face_detect_video.py’ is the script for Face Detection on Video files as supplied by the User.
‘face_detect_webcam.py’ is the script for Face Detection from the Webcam of the host machine the script is executed on.
---End of Section One---
2. FAQs
Haar-like features are digital image features used in object recognition. They owe their name to their intuitive similarity with Haar wavelets and were used in the first real-time face detector. Historically, working with only image intensities (i.e., the RGB pixel values at each and every pixel of image) made the task of feature calculation computationally expensive. A publication by Papageorgiou et al. discussed working with an alternate feature set based on Haar wavelets instead of the usual image intensities. Viola and Jones adapted the idea of using Haar wavelets and developed the so-called Haar-like features. A Haar-like feature considers adjacent rectangular regions at a specific location in a detection window, sums up the pixel intensities in each region and calculates the difference between these sums. This difference is then used to categorize subsections of an image.
For example, let us say we have an image database with human faces. It is a common observation that among all faces the region of the eyes is darker than the region of the cheeks. Therefore a common Haar feature for face detection is a set of two adjacent rectangles that lie above the eye and the cheek region. The position of these rectangles is defined relative to a detection window that acts like a bounding box to the target object (the face in this case).
~Wikipedia
A Haar Cascade is basically 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. Better results are obtained by using high quality images and increasing the amount of stages for which the classifier is trained. One can also used predefined Haar Cascades which are available on GitHub.
Haar Cascade for frontal face (default) detection was used in this project. It was downloaded from Github. from this link. The OpenCV documentation for Face Detection using Haar Cascades is here.
The performance of the script is strictly based upon the Hardware of the system on which it is run and the quality of files provided. For the webcam, the performance dependency on hardware is not much of a factor but for videos it is, as FFmpeg is decoding the video frame by frame as the script is run.
We converted the input into Gray-Scale to simplify the job of the Haar Cascade algorithm. It would be able to work faster to determine edges and give out positive or negative results on images or frames.
The following Python packages are required to run the scripts.
a) imutils : A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours, detecting edges, and much more easier with OpenCV and both Python 2.7 and Python 3.
b) opencv2 : OpenCV (Open Source Computer Vision Library: http://opencv.org) is an open-source BSD-licensed library that includes several hundreds of computer vision algorithms.
c) ffmepg : FFmpeg is a free software project, the product of which is a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams. At its core is the FFmpeg program itself, designed for command-line-based processing of video and audio files, widely used for format transcoding, basic editing (trimming and concatenation), video scaling, video post-production effects, and standards compliance (SMPTE, ITU).
[Source: Internet]
# Draw a rectangle around the Faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
---End of Section Three---
4. Sample Outputs
---End of Section Four---
5. Credits
---End of Section Five---