You are on page 1of 7

DEC40092 COMPUTER VISION PROGRAMMING

MINI PROJECT REPORT


SESI II : 2022/2023

PROJECT NAME:
REAL-TIME FACE DETECTION

No STUDENT NAME NO.MATRIC


1. MOHD AZAM BIN MOHAMAD ARIFF 10DTK21F1055
2. NUR FARAH IZZATI BINTI MOHD FATHIL 10DTK21F1004
3. LIM HOOI PENG 10DTK21F1041
4. SARVIYN A/L DHAYALAN 10DTK20F2031

LECTURE’S NAME: AMIR BIN ABU BAKAR


1. Title of system project
Real-Time Face Detection
2. Introduction of the project
Real-time face detection refers to the ability to detect and locate human faces in a continuous
and uninterrupted stream of data or video in real-time. It involves the use of computer vision
algorithms and techniques to analyze the incoming data and identify the presence and
position of faces.

Real-time face detection systems are designed to operate in real-time scenarios where there is
a need for immediate and time-critical processing, such as video surveillance, facial
recognition systems, or interactive applications. These systems typically aim to achieve high
detection accuracy while maintaining fast processing speeds to handle the incoming data
stream in real-time.

The process of real-time face detection generally involves the following steps:
Preprocessing: The input data or video frames are preprocessed to enhance the quality and
optimize them for face detection. This may include resizing, normalization, or applying
filters.
Feature Extraction: Computer vision algorithms analyze the preprocessed data to extract
relevant features that are characteristic of human faces. These features may include the shape,
texture, color, or edges of the face.
Face Detection: Using the extracted features, the algorithm searches for patterns that indicate
the presence of a face in the data. This can involve applying machine learning models or
cascades of classifiers to determine whether a region of the data contains a face.
Localization: Once a face is detected, the algorithm determines the position and boundary of
the face within the data or video frame. This information is usually represented as a bounding
box that surrounds the face.
Tracking: In real-time scenarios, face detection systems often incorporate tracking
mechanisms to follow the detected faces across consecutive frames. This allows for
consistent identification and monitoring of faces as they move or change position in the video
stream.
Real-time face detection is an essential component in various applications, including video
surveillance, biometric identification, facial expression analysis, augmented reality, and many
more. Advances in computer vision algorithms and hardware acceleration have significantly
improved the speed and accuracy of real-time face detection systems, making them
increasingly effective and widely deployed in diverse domains.
3. Background theory
Real-time face detection relies on computer vision and machine learning methods,
incorporating various theories and algorithms to identify human faces in real-time video or
image streams. The following are essential background theories involved in real-time face
detection:

1. Haar-like Features: Haar-like features are simple rectangular features that capture local
intensity differences in an image. These features calculate the contrast between white and
black regions, making them efficient and effective for detecting basic facial characteristics.
2. Viola-Jones Algorithm: The Viola-Jones algorithm is a widely-used approach for real-time
face detection. It combines Haar-like features with the AdaBoost learning algorithm to create
a strong classifier. This algorithm uses a cascade of weak classifiers to progressively refine
the face detection process, focusing on regions that are more likely to contain faces, resulting
in fast and efficient detection.
3. Machine Learning: Real-time face detection often involves machine learning techniques.
Training a face detection model requires a dataset with positive examples (annotated faces)
and negative examples (non-face regions). Machine learning algorithms like Support Vector
Machines (SVM) or Convolutional Neural Networks (CNN) can learn facial patterns and
features from these datasets.
4. Feature Extraction: Feature extraction plays a crucial role in real-time face detection. It
involves analyzing image or video frames to extract discriminative features that represent
facial characteristics. Principal Component Analysis (PCA), Local Binary Patterns (LBP),
Histogram of Oriented Gradients (HOG), and deep learning-based methods using CNNs are
commonly used feature extraction techniques.
5. Object Localization: Object localization refers to determining the precise location and
extent of an object within an image or video frame. In face detection, object localization
algorithms identify the boundaries of detected faces, typically represented as bounding boxes.
Techniques like template matching, sliding windows, or region-based methods are employed
for accurate face localization.
6. Real-Time Optimization: Achieving real-time face detection requires optimization
techniques to ensure fast and efficient processing. These optimizations include parallel
computing on GPUs, hardware acceleration, algorithmic improvements, and model
compression. These strategies aim to reduce computational complexity and enable real-time
processing on resource-constrained devices.
It is important to note that real-time face detection is a rapidly evolving field, and new
techniques and algorithms are continuously developed to enhance accuracy, speed, and
robustness. The aforementioned background theories provide a foundation for understanding
the principles behind real-time face detection, but the field constantly advances with
developments in machine learning, deep learning, and computer vision.
4. Methodology
Problem Statement:
This project's purpose is to create a real-time face detection system using Python and
OpenCV. The system must be capable of capturing footage from a camera, detecting faces in
the video stream, and drawing rectangles around the found faces.

Data Collection:
The system will use video frames captured from the webcam as the input data. The OpenCV
library provides functions to access and process video streams. The video stream will be
continuously read frame by frame to perform real-time face detection.

Real-Time Face Detection:


The main loop of the program continuously reads video frames from the webcam using
‘video_capture.read()’. Each frame is converted to grayscale, and then the
‘detectMultiScale()’ function is applied to the grayscale image to detect faces. The
‘detectMultiScale()’ function uses the Haar cascade classifier model to detect faces in the
image.

Drawing Rectangles:
For each detected face, a rectangle is drawn around it using the ‘cv2.rectangle()’ function.
The rectangle is defined by the coordinates of the top-left and bottom-right corners of the
face region. This helps visually indicate the detected faces in the video stream.

Displaying the Video Stream:


The processed frames with the detected faces are displayed in a separate window using
‘cv2.imshow()’. This enables real-time visualisation of the face detection the results.

User Interaction and Programme Exit:


The programme will continue to run until the user taps the 'q' key. The cv2.waitKey()
function is used to wait for a keyboard event, and if the pushed key is 'q', the programme will
exit the main loop and end.
5. Block Diagram/ Flow Chart
6. Python Programming
CODING
import cv2

# Initialize the face detection model using pre-trained Haar cascades


face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml')

# Open the webcam video stream


video_capture = cv2.VideoCapture(0)

while True:
# Capture a frame from the video stream
ret, frame = video_capture.read()

# Convert the frame to grayscale for face detection


gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect faces in the grayscale frame


faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3,
minNeighbors=5)

# Draw a rectangle around each detected face


for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

# Display the video stream with detected faces


cv2.imshow('Face Detection', frame)

# Exit the program if the user presses the 'q' key


if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Release the video capture resources and close all windows


video_capture.release()
cv2.destroyAllWindows()

RESULT
7. Discussion
The real-time face detection system created using Python and OpenCV shows promising
results in recognizing faces from webcam video streams. To identify facial regions in video
frames, the system employs the Haar cascade classification technique. The rectangles created
around the recognized faces provide an intuitive visual indication of the system's
performance.
One aspect worth considering is the accuracy of face detection. The Haar cascade classifier is
a widely used algorithm for face detection, but it can occasionally produce false positives or
miss some faces, especially in challenging lighting conditions or when faces are partially
occluded. Fine-tuning the parameters of the algorithm, such as scale factor and minimum
neighbors, may improve accuracy by reducing false detections and increasing detection rates.
Experimenting with different parameter values and evaluating the results is valuable for
improving system performance.
The real-time nature of the system is an advantage, as it can feed face detection instantly
while streaming video from the webcam. However, the performance of the system may be
affected by the processing power of the computer running the code. If the system experiences
lag or delay when detecting faces, explore optimizing the code or consider hardware upgrades
to enhance real-time capabilities.

8. Conclusion
In conclusion, the developed real-time face detection system showcases effective utilization
of Python and OpenCV libraries for face detection in a webcam video stream. While accuracy
and real-time performance could be improved, the system serves as a good foundation for
future improvements. By refining the parameters of the face detection algorithm and
considering hardware optimizations, the system can be strengthened to provide more reliable
and efficient real-time face detection capabilities for various applications such as security
systems, human-computer interaction, and facial recognition technologies.

References
Ai (2022), A Complete Guide on Real-Time Face Detection,
https://www.hyperverge.co/blog/what-is-real-time-face-detection
Gaudenz Boesch (2023), Face Detection: Real-Time Deep Learning Applications,
https://viso.ai/deep-learning/face-detection-overview/
Marcelo Rovai (2018), Real-Time Face Recognition: An End-To-End Project,
https://towardsdatascience.com/real-time-face-recognition-an-end-to-end-project-
b738bb0f7348
Rokas Balsys (2022), CPU Real-time Face Detection With Python,
https://towardsai.net/p/l/cpu-real-time-face-detection-with-python?amp=1
Yoloface (2022), real-time-face-detection,
https://github.com/topics/real-time-face-detection

You might also like