0% found this document useful (0 votes)
11 views51 pages

Real-Time Face Detection For Public Safety: Kanimozhi.D Pavithra.P Rajalakshmi.R

The project report details the development of a real-time face detection and alert system aimed at enhancing public safety using Python, OpenCV, and an ESP32 microcontroller. The system captures live video, detects faces using the Haar Cascade algorithm, and triggers alerts through a buzzer and LCD display, providing a low-cost and efficient solution for security applications. Future enhancements may include features like face recognition and IoT capabilities.

Uploaded by

kanimozhii2709
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views51 pages

Real-Time Face Detection For Public Safety: Kanimozhi.D Pavithra.P Rajalakshmi.R

The project report details the development of a real-time face detection and alert system aimed at enhancing public safety using Python, OpenCV, and an ESP32 microcontroller. The system captures live video, detects faces using the Haar Cascade algorithm, and triggers alerts through a buzzer and LCD display, providing a low-cost and efficient solution for security applications. Future enhancements may include features like face recognition and IoT capabilities.

Uploaded by

kanimozhii2709
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

REAL-TIME FACE DETECTION FOR PUBLIC SAFETY

A PROJECT REPORT

Submitted by

Kanimozhi.D - 110821106310
Pavithra.P - 110821106313
Rajalakshmi.R - 110821106315

Inpartial fulfillment for the award of the degree of

BACHELOR OF ENGINEERING
in

ELECTRONICS AND COMMUNICATION ENGINEERING

JAYA ENGINEERING COLLEGE

ANNA UNIVERSITY : CHENNAI - 600025

APRIL 2026
ANNA UNIVERSITY: CHENNAI 600 025

BONAFIDE CERTIFICATE

Certified that this project report “REAL-TIME FACE DETECTION FOR PUBLIC SAFETY
Is the bonafide work of “Kanimozhi.D (110821106310), Pavithra.P (110821106313),

Rajalakshmi.R (110821106315 )”.Who carried out the project work under my supervision.

SIGNATURE SIGNATURE
Dr. A. SARAVANAN, Dr. R. MUTHALAGU,
M.E., HEAD OF THE DEPARTMENT, PROFESSOR,
Department of ECE, Department of ECE,
Jaya Engineering College, Jaya Engineering College,
Thiruninravur- 602 024. Thiruninravur- 602 024.

Submitted to project and viva-voce held on

INTERNAL EXAMINER EXTERNAL EXAMINER


ACKNOWLEDGEMENT

At the outset we express our deep sense of gratitude to our esteemed Chairman Prof.
A. KANAGARAJ, M.A., [Link]., of Jaya Educational Trust, Vice-Chairman Mr. K.
NAVARAJ, M., Tech. Ph.D., of Jaya Educational Trust, and Secretary Mrs. K.
VIJAYAKUMARI, M.A., [Link]., for their guidance and blessings.

We would like t o express our sincere thanks to our Principal Dr. V. SURESH
KUMAR, M.E., Ph.D., and our Vice-Principal Dr. S. RAJENDRAN, M.E., Ph.D., of Jaya
Engineering College for their incredible support towards the completion of our project.

Our deep sense of gratitude and heart full of thanks to our Head of Department and Project
Supervisor Dr. A. SARAVANAN, [Link]., Ph.D., of Jaya Engineering College for his extreme
guidance and valuable advice during the project. We would also want to thank our project
coordinator Mr. D. ANBARASU [Link]., [Link]., Ph.D., who gave us guidance and
ideas during the project.

We take this opportunity to extend our deep sense of gratitude to thank our Family
Members, Friends and Well-Wishers, for all that they meant to us during the crucial period of the
completion of our project.
ABSTRACT

Real-time face detection has become an important technology in modern security,


surveillance, and human–computer interaction systems. This project presents the design and
development of a real-time face detection and alert system using Python and OpenCV
integrated with an ESP32 micro-controller.

The system captures live video using a web camera and processes each frame to detect
human faces using the Haar Cascade algorithm. The use of grayscale image processing helps
reduce computational complexity while maintaining detection accuracy. Once a face is
detected, a signal is transmitted to the ESP32 through serial or wireless communication.

The ESP32 activates a buzzer to provide an immediate alert and displays system status
messages on a 16x2 Liquid Crystal Display. This integration of software-based detection and
hardware-based alerting ensures quick response and reliable operation. The ESP32 also
provides IoT capabilities through built-in Wi-Fi and Bluetooth support.

The system operates with minimal delay and performs effectively under normal lighting
conditions. It offers a low-cost, efficient, and scalable solution for applications such as
intrusion detection, access control, smart attendance systems, and public surveillance. The
design can be further enhanced by integrating features like face recognition, cloud
monitoring, and mobile notifications.

i
TITLE [Link]

CHAPTER NO
3.9 ARCHITECTURE SUMMARY FLOW
14
CHART
TABLE OF CONTENTS
4 HARDWARE REQUIREMENTS 15
4.1 HARDWARE COMPONENTS USED 15
CHAPTER NO TITLE [Link]
` 4.2 WEBCAM 16

4.3 ESP32 MICROCONTROLLER


ABSTRACT i16

LIST OF CONTENTS
4.4 LCD ii
17
LIST OF FEATURES ix
4.5 BUZZER 17
LIST OF ABBREVIATIONS x
4.6 POWER SUPPLY 18
1 INTRODUCTION 1
4.7 JUMPER WIRE INTERCONNECTION
1.1 GENERAL INTRODUCTION 119
1.2 PROBLEM STATEMENT 2
5 SOFTWARE REQUIREMENT 20
1.3 SCOPE OF THE PROJECT 3
5.1 SOFTWARE REQUIREMENTS
2 LITREATURE SURVEY 420
5.2LITERATURE
2.1 PYTHON PROGRAMMING
2022 4
LANGUAGE2024
2.2 LITERATURE 22
5
5.21 PYTHON SOURCE CODE
3 7
SYSTEM
5.3 OPEN ARCHITECTURE
CV LIBRARY 27
3.1 SYSTEM ARCHITECTURE 7
3.2 SYSTEM DESCRIPTION
5.3.1 OPENCV PROCESSING FLOW 728

[Link].1 ADVANTAGES
ALGORITHM 8
29
3.1.2 DISADVANTAGES 9
5.4 PYSERIAL LIBRARY 31
3.3 PROCESSING FLOW 9
[Link]
SERIAL COMMUNICATION
ARCHITECTURE SUMMARY 1132
3.5 HARDWARE COMPONENTS USED
11
5.5 DEVELOPMENTED ENVIRONMENT 34
3.6 SOFTWARE
11
3.7 SCHEMATIC
5.6 SYSTEM REQUIREMENT
DIAGRAM 1234

6 3.8 CIRCUIT
RESULTS DIAGRAM
AND ANALYSIS 1335

6.1 RESULTS AND ANALYSIS 35


ii

CHAPTER NO TITLE [Link]


6.1.1 RESULTS OBTAINED
36
LIST OF FIGURES

FIGURE NO TITLE [Link]

1.1 GENERAL INTRODUCTION 1

1.2 PROBLEM STATEMENT 2

SCOPE OF THE PROJECT 3


1.3

2.1 LITERATURE 2022 4

2.2 LITERATURE 2024 5

3.1 SYSTEM ARCHITECTURE 7

3.2 SYSTEM DESCRIPTION 7

3.3 PROCESSING FLOW 9

3.4 ARCHITECTURE SUMMARY 11

3.5 HARDWARE COMPONENTS USED 11

3.6 SOFTWARE 11

3.7 SCHEMATIC DIAGRAM 12

3.8 CIRCUIT DIAGRAM 13

3.9 ARCHITECTURE SUMMARY FLOW 14


CHART
4.1 HARDWARE COMPONENTS USED 15

4.2 WEBCAM 15

4.3 ESP32 MICROCONTROLLER 16

4.4 LCD (Liquid Crystal Display (16x2)) 17

4.5 BUZZER 17

iii
4.6 POWER SUPPLY 18
JUMPER WIRE INTERCONNECTION
4.7 19

SOFTWARE REQUIREMENTS
5.1 20
5.2 PYTHON PROGRAMMING 20
LANGUAGE

5.3 OPEN CV LIBRARY 27

5.4 PYSERIAL LIBRARY 31

5.5 DEVELOPMENTED ENVIRONMENT 34


5.6 SYSTEM REQUIREMENT 34
6.1 RESULTS AND ANALYSIS 35

6.2 OBSERVATION TABLE 38


6.3 ANALYSIS SUMMARY 38
7.1 CONCLUSION 39
8.1 FUTURE ENHANCEMENT 40
9.1 REFERENCES 41

iv
CHAPTER 1

INTRODUCTION

1.1 GENERAL INTROCTION

In recent years, the demand for advanced security systems has increased significantly
due to rising concerns about safety and unauthorized access. Conventional security
methods such as manual monitoring and basic alarm systems are often inefficient, time-
consuming, and lack real-time response capabilities. To overcome these limitations,
intelligent systems based on computer vision and embedded technologies are being
widely adopted.

Face detection is a fundamental application of computer vision that enables systems


to automatically identify the presence of human faces in images or video streams. It plays
a crucial role in modern security, surveillance, and human–computer interaction systems.
By integrating face detection with embedded hardware, it is possible to create efficient
and automated security solutions.

This project focuses on the design and implementation of a real-time face detection
and alert system using Python and OpenCV, along with an ESP32 microcontroller. The
system captures live video through a web camera and processes it using a Haar Cascade
classifier to detect human faces. When a face is detected, a signal is sent to the ESP32,
which activates a buzzer to generate an alert and displays the system status on an LCD.

The proposed system combines the advantages of software-based image processing


and hardware-based alert mechanisms, ensuring fast response and improved reliability.
Additionally, the use of ESP32 provides built-in Wi-Fi and Bluetooth capabilities,
making the system suitable for future expansion into IoT-based applications.
1
Overall, this project presents a low-cost, efficient, and scalable solution for real-time
security monitoring, with potential applications in homes, offices, restricted areas, and
smart surveillance systems.

1.2 PROBLEM STATEMENT

In today’s world, ensuring safety and security in homes, offices, and restricted areas
has become increasingly important. Traditional security systems such as CCTV
surveillance and manual monitoring require continuous human attention and often fail to
provide immediate response during critical situations. These systems are generally
passive, as they only record events rather than actively detecting and alerting users in real
time.

Moreover, many existing advanced security solutions are expensive and require
complex infrastructure, making them unsuitable for small-scale or low-budget
applications. There is a need for an efficient, low-cost, and automated system that can
detect potential intrusions and provide instant alerts without human intervention.

Face detection technology offers a promising solution by enabling systems to


automatically identify the presence of a person. However, integrating real-time face
detection with an effective alert mechanism in a simple and cost-efficient manner
remains a challenge.

Therefore, this project aims to address these limitations by developing a real-time


face detection and alert system using Python and OpenCV integrated with an ESP32
microcontroller. The system is designed to automatically detect human faces from live
video input and immediately trigger an alert through a buzzer and Liquid Crystal Display,
ensuring quick response and improved security.

2
1.3 SCOPE OF THE PROJECT

The scope of this project focuses on the design and development of a real-time face
detection and alert system using computer vision and embedded system technologies.
The system is intended to provide an efficient, low-cost, and automated solution for basic
security and monitoring applications.

The project includes the implementation of real-time video capture using a web
camera and processing of video frames using Python with OpenCV. The Haar Cascade
algorithm is used to detect human faces in the captured frames. Upon successful
detection, the system sends a signal to the ESP32 microcontroller, which activates a
buzzer and displays the system status on an Liquid Crystal Display.

The scope of this project is limited to face detection only, and it does not include
face recognition or identification of individuals. The system is designed to work
effectively under normal lighting conditions and within a limited range of the camera. It
is suitable for small-scale applications such as home security, office monitoring, and
restricted area surveillance.

Additionally, the project provides a foundation for future enhancements, such as


integrating face recognition, cloud-based monitoring, mobile notifications, and IoT-based
remote access. The modular design of the system allows easy expansion and adaptation
for more advanced security applications.

Overall, the project demonstrates the practical implementation of a real-time,


hardware-integrated face detection system within a defined and manageable scope.

3
CHAPTER 2
LITERATURE SURVEY

2.1 LITERATURE SURVEY

INTRODUCTION

Face detection and recognition technologies have been widely researched due to their
growing importance in security, surveillance, and human–computer interaction systems.
Various approaches have been developed ranging from traditional image processing
techniques to advanced deep learning models. This section reviews some of the key
research works and technologies related to real-time face detection systems.

2.2 LITERATURE 2022:

 A study on real-time face detection using deep Convolutional Neural Networks


(CNN) (IEEE, 2022) highlights the effectiveness of deep learning models in
achieving high accuracy and robustness under different environmental conditions.
These models outperform traditional algorithms but require high computational
power and advanced hardware, making them less suitable for low-cost embedded
systems.
 Research on embedded vision systems for surveillance (IEEE Sensors, 2022)
focuses on integrating vision-based detection with embedded devices for real-time
monitoring. These systems improve automation and reduce human effort but often
face challenges related to processing speed, power consumption, and hardware
limitations.
 Studies on facial recognition in policing and security emphasize the importance
of automated identification systems in enhancing public safety. While these

4
systems provide high-level security, they also raise concerns regarding privacy,
ethical issues, and data security.
 The OpenCV documentation provides a comprehensive framework for
implementing computer vision applications. It includes efficient algorithms such as
the Haar Cascade classifier, which enables real-time face detection with relatively
low computational requirements, making it suitable for this project.
 The ESP32 technical documentation describes a powerful and cost-effective
microcontroller with built-in Wi-Fi and Bluetooth capabilities. It is widely used in
IoT applications due to its low power consumption, processing ability, and ease of
integration with sensors and external devices.

2.3 LITERATURE 2024:

 Recent studies indicate that deep learning-based face detection and recognition
systems significantly outperform traditional methods in terms of accuracy and
robustness. A 2023 IEEE study demonstrated that CNN-based pipelines achieve
reliable performance under varying lighting and pose conditions, but their high
computational requirements limit direct deployment on low-cost embedded
platforms.
 In 2024, the IEEE ICME Grand Challenge emphasized low-power facial-landmark
detection, highlighting the use of knowledge distillation and model compression to
enable real-time inference on embedded hardware, reflecting a strong shift toward
edge-AI deployment.
 Research during 2023–2024 increasingly focuses on lightweight CNN
architectures optimized for embedded vision. Comparative studies show that
combining fast and accurate models can balance inference speed and recognition
accuracy on constrained devices such as Jetson Nano. Models like Edge Face and

5
optimized Mobile FaceNet variants demonstrate that quantization and architectural
simplification reduce memory and power consumption while maintaining
competitive accuracy.
 Edge-based vision systems using ESP32-class devices gained prominence with the
introduction of ESP32-S3 AI modules. Studies report that lightweight face
detection and tracking can be achieved on ESP32-CAM using Tiny ML and
TensorFlow Lite, enabling real-time, privacy-preserving, on-device inference.
Express if documentation further highlights hardware-level AI acceleration in
ESP32-S3 for low-power surveillance and access-control applications.
 Despite advances in deep learning, OpenCV-based classical algorithms such as
Haar Cascade remain relevant due to their low computational cost and suitability
for microcontrollers. Hybrid approaches combining classical detection with
lightweight CNN recognition improve efficiency and accuracy.
Recent 2024 literature also emphasizes ethical, privacy, and regulatory concerns,
reinforcing the preference for on-device processing over cloud-based systems.
 Research Gap: Deep CNNs offer high accuracy but are computationally
expensive, while lightweight edge-AI models remain constrained on ultra-low-cost
hardware, motivating optimized ESP32-based face-detection solutions.

6
CHAPTER 3

SYSTEM ARCHITECTURE

3.1 SYSTEM ARCHITECTURE

3.1.1 ARCHITECTURE TYPE

The proposed system follows a hybrid architecture, combining both software and
embedded hardware components. The software module is responsible for real-time image
acquisition, processing, and face detection, while the hardware module handles alert
generation and system indication. This combination ensures efficient processing, reduced
computational load on hardware, and improved system responsiveness.

3.2 SYSTEM DESCRIPTION

The system is designed to perform real-time face detection using a webcam and
generate an immediate alert using an ESP32 microcontroller. It integrates computer
vision techniques with embedded system control to achieve efficient, reliable, and low-
latency performance.

The software module, developed using Python and OpenCV, captures and processes
live video frames. It applies image processing techniques and a Haar Cascade classifier to
detect human faces. The hardware module, built around the ESP32 microcontroller,
receives detection signals and activates output devices such as a buzzer and Liquid
Crystal Display.

The ESP32 serves as an interface between the software and physical alert system,
ensuring quick execution of alert actions. Its built-in Wi-Fi and Bluetooth capabilities
also allow the system to be extended into IoT-based applications in the future.

7
3.2.1 ADVANTAGES

The proposed system offers several advantages due to its design and implementation:

1. Real-Time Detection:
The system processes video frames instantly, enabling quick detection and
response.
2. Low Cost:
Uses affordable components such as ESP32 and a standard webcam, making it
economical.
3. Easy Implementation:
Simple architecture and widely available software tools make the system easy to
develop and deploy.
4. Modular Design:
Software and hardware modules can be modified or upgraded independently.
5. Fast Response Time:
Immediate alert generation through buzzer and Liquid Crystal Display ensures
quick notification.
6. Scalability:
Can be extended with advanced features like face recognition, cloud integration,
and mobile alerts.
7. Low Power Consumption:
ESP32 consumes less power, making the system efficient for continuous operation.
8. IoT Compatibility:
Built-in Wi-Fi and Bluetooth support future integration with smart systems.

8
3.2.2 DISADVANTAGES

Despite its benefits, the system has some limitations:

1. Lighting Dependency:
Detection accuracy decreases in low-light or poor lighting conditions.
2. Limited Accuracy:
Haar Cascade algorithm may fail in detecting faces with occlusions or unusual
angles.
3. No Face Recognition:
The system can detect faces but cannot identify specific individuals.
4. Camera Dependency:
Performance depends on the quality and resolution of the webcam.
5. False Positives:
Sometimes non-face objects may be incorrectly detected as faces.

3.3 PROCESSING FLOW

Processing Flow

The working of the system is carried out in the following sequence:

1. Video Acquisition

A webcam continuously captures live video and converts it into individual frames for
processing. This ensures uninterrupted monitoring of the environment.

2. Image Processing

9
Each frame is processed using Python and OpenCV. The image is converted into
grayscale format to reduce computational complexity and increase processing speed
while maintaining acceptable detection accuracy.

3. Face Detection

The Haar Cascade classifier is applied to detect human faces within the frame. The
algorithm scans the image at multiple scales and identifies facial features such as eyes,
nose, and mouth patterns.

4. Decision Logic

The system evaluates the detection result:

 If no face is detected, the system continues processing the next frame.


 If a face is detected, the system triggers the alert mechanism.

5. Signal Transmission

When a face is detected, a signal is sent from the Python program to the ESP32
microcontroller via serial communication (USB) or wireless communication (Wi-Fi).

6. Hardware Response

The ESP32 processes the received signal and performs the following actions:

 Activates the buzzer to generate an audible alert


 Displays a message such as “Face Detected” or “Alert ON” on the Liquid Crystal
Display

10
7. Continuous Operation

The entire process runs continuously in a loop, ensuring real-time monitoring, quick
response, and uninterrupted operation.

 Limited Range:
Detection works effectively only within a certain distance from the camera.
 Basic Alert System:
Only buzzer and Liquid Crystal Display are used; no remote or mobile
notifications in the current version.

3.4 ARCHITECTURE SUMMARY

Webcam → Python (Opensource Computer Vision Library Processing) → Face


Detection → Signal to ESP32 → Buzzer Alert + Liquid Crystal Display

3.5 HARDWARE COMPONENTS USED

 Webcam
 ESP32 Microcontroller
 Liquid Crystal Display (LCD 16x2)
 Buzzer
 Power Supply
 Jumper Wire Interconnection

3.6 SOFTWARE

 OpenCV

11
3.7 SCHEMATIC DIAGRAM

Figure 3.7 SCHEMATIC DIAGRAM

12
3.8 CIRCUIT DIAGRAM

Figure 3.8 CIRCUIT DIAGRAM

13
3.9 ARCHITECTURE SUMMARY FLOW CHART

Figure 3.9 ARCHITECTURE SUMMARY FLOW CHART

14
CHAPTER 4

HARDWARE REQUIREMENT

4.1 HARDWARE COMPONENTS USED

The proposed system utilizes several hardware components to achieve real-time face
detection and alert functionality. Each component plays a crucial role in the overall
operation of the system by contributing to data acquisition, processing, communication,
and alert generation.

The hardware setup is designed to be simple, cost-effective, and efficient, making it


suitable for practical implementation. The components are carefully selected to ensure
compatibility, low power consumption, and reliable performance. The integration of
these components enables smooth communication between the software and hardware
modules.

The webcam acts as the primary input device, capturing real-time video data from the
environment. This data is processed by the software system, and the results are
communicated to the ESP32 microcontroller. The ESP32 serves as the central control
unit, which interprets the signals and activates the output devices accordingly.

Output components such as the Liquid Crystal Display and buzzer provide both visual
and audible feedback, ensuring that the user is immediately notified when a face is
detected. The power supply ensures stable operation of all components, while jumper
wires facilitate proper electrical connections within the system.

Overall, the combination of these hardware components creates a reliable and responsive
system capable of performing real-time monitoring and alert generation. The modular

15
nature of the hardware design also allows for easy expansion and integration of additional
features in future developments.
4.2 WEBCAM

The webcam is used to capture live video input from the surrounding environment. It
continuously streams video frames to the Python program for processing. The quality and
resolution of the webcam directly affect the accuracy of face detection. A standard USB
webcam is sufficient for this system, as it provides real-time video with adequate frame
rate for processing.

4.3 ESP32 MICROCONTROLLER

The ESP32 is the core hardware component responsible for controlling the alert system.
It receives signals from the Python program when a face is detected and executes the
corresponding actions. The ESP32 is chosen due to its high processing capability, low
power consumption, and built-in Wi-Fi and Bluetooth features. These features make it
suitable for IoT-based applications and future system expansion.

Figure 4.3 ESP32 MICROCONTROLLER

16
4.4 LCD (Liquid Crystal Display (16x2))

The 16x2 Liquid Crystal Display is used to provide visual feedback to the user. It
displays system status messages such as “Face Detected,” “No Face Detected,” or “Alert
ON.” The Liquid Crystal Display enhances user interaction by clearly indicating the
system’s current state. It is typically interfaced with the ESP32 using I2C
communication, which reduces wiring complexity.

Figure 4.4 LCD(Liquid Crystal Display (16×2))

4.5 BUZZER

The buzzer acts as an alert device that generates an audible signal when a face is
detected. It helps in providing immediate notification to the user or security personnel.
The buzzer is directly controlled by the ESP32 and is activated as soon as a detection
signal is received.
17
Figure 4.5
BUZZE R

4.6 POWER
SUPPLY

The system requires a stable power supply to operate efficiently. The ESP32 typically
operates at 3.3V, while other components like the Liquid Crystal Display may require
5V. A regulated power supply or USB power source is used to ensure consistent voltage
and prevent damage to components. Proper power management is essential for reliable
system performance.

Figure 4.6 POWER SUPPLY

18
4.7 JUMPER WIREINTERCONNECTION

Jumper wires are used to establish electrical connections between the ESP32
microcontroller and other hardware components such as the Liquid Crystal Display and
buzzer. Proper interconnection is essential for ensuring smooth communication and
reliable operation of the system.

The connections are made based on the pin configuration of the ESP32 and the
interfaced devices. The wiring is done carefully to avoid loose connections, short circuits,
or incorrect pin mapping.

Figure 4.7 JUMPER WIREINTERCONNECTION

19
CHAPTER 5

SOFTWARE REQUIREMENT

5.1 SOFTWARE REQUIREMENTS

The successful implementation of the proposed real-time face detection and alert system
depends on a combination of software tools, programming environments, and
communication libraries. These software components are responsible for video
acquisition, image processing, face detection, and communication with the hardware
module (ESP32). The selection of these tools ensures efficient performance, real-time
processing, and ease of development.

5.2 PYTHON PROGRAMMING LANGUAGE

Python is the primary programming language used in the development of the proposed
real-time face detection and alert system. It is a high-level, interpreted language known
for its simplicity, readability, and extensive library support. Python is widely used in
fields such as artificial intelligence, machine learning, and computer vision, making it an
ideal choice for this project.

One of the main advantages of Python is its ability to perform complex tasks with
simple and concise code. This reduces development time and makes the system easier to
understand and maintain. In this project, Python acts as the core software platform that
manages all major operations, including video processing, face detection, and
communication with the ESP32 microcontroller.

Python is used to capture live video from the webcam using the OpenCV library. The
video stream is divided into individual frames, and each frame is processed in real time.

20
Before applying the face detection algorithm, the frames are converted into grayscale
format. This reduces computational complexity and improves processing speed while
maintaining acceptable accuracy.

The face detection process is implemented using the Haar Cascade classifier available in
OpenCV. Python applies this algorithm to identify human faces by detecting specific
features such as eyes, nose, and mouth. When a face is detected, a bounding box is drawn
around the detected region for visualization.

Python also handles the decision-making logic of the system. It continuously checks
each frame to determine whether a face is present. If no face is detected, the system
continues monitoring. When a face is detected, Python sends a signal to the ESP32
microcontroller using the Py Serial library. This signal triggers the hardware components
such as the buzzer and Liquid Crystal Display

Another important feature of Python is its ability to communicate easily with external
hardware. Through serial communication, Python ensures real-time data transfer between
the software and the ESP32, enabling quick response and alert generation.

Python supports modular programming, allowing the system to be divided into smaller
sections such as video capture, processing, detection, and communication. This improves
code organization and makes future modifications easier.

Additionally, Python provides strong debugging and error-handling capabilities, which


help in identifying and resolving issues during development. Its cross-platform
compatibility allows the system to run on different operating systems such as Windows,
Linux, and macOS.

21
In conclusion, Python plays a crucial role in this project by managing real-time
processing, implementing face detection, and enabling communication with hardware
components. Its simplicity, flexibility, and powerful features make it a suitable and
efficient choice for developing a reliable real-time face detection and alert system.

The major functions performed by Python in this system include:

 Capturing live video from the webcam using OpenCV functions.


 Converting video streams into individual frames for processing.
 Performing image preprocessing techniques such as grayscale conversion.
 Implementing the Haar Cascade classifier for detecting human faces.
 Drawing bounding boxes around detected faces for visualization.
 Sending control signals to the ESP32 microcontroller via serial communication.
 Managing the overall system logic, including decision-making and continuous
looping
5.3 Python code with OpenCV & ESP32 buzzer/Liquid Crystal Display alert
import tkinter as tk
import threading
import sys
import os
import pickle
import cv2
import imutils
import face_recognition
import serial

# Hard-coded file paths — works both as script and PyInstaller --onefile exe
if getattr(sys, "frozen", False):
BASE_DIR = sys._MEIPASS
else:
22
BASE_DIR = [Link]([Link](__file__))

ENCODINGS_PATH = [Link](BASE_DIR, "[Link]")


CASCADE_PATH = [Link](BASE_DIR,
"haarcascade_frontalface_default.xml")

# Serial codes for each recognized class


NAME_CODE = {
"Child 1": "A",
"Child 2": "A",
"General Public 1": "B",
"General Public 2": "B",
"Crime Suspect": "C",
"Occuled Face 1": "C",
"Occuled Face 2": "C",
"Unknown": "X",
}

running = False
ser = None

def recognition_loop(com_port):
global running, ser

print("[INFO] loading encodings...")


data = [Link](open(ENCODINGS_PATH, "rb").read())

try:
ser = [Link](port=com_port, baudrate=9600, bytesize=8,
timeout=2, stopbits=serial.STOPBITS_ONE)
except Exception as e:
print(f"[ERROR] Could not open {com_port}: {e}")
running = False
status_label.config(text=f"Serial error: {e}", fg="red")

23
start_btn.config(state=[Link])
stop_btn.config(state=[Link])
return

print("[INFO] starting webcam...")


cap = [Link](0)

while running:
ret, frame = [Link]()
if not ret:
break

frame = [Link](frame, width=500)


rgb = [Link](frame, cv2.COLOR_BGR2RGB)

# Use face_recognition's own HOG detector — consistent with encoder


boxes = face_recognition.face_locations(rgb, model="hog")
encodings = face_recognition.face_encodings(rgb, boxes, num_jitters=1)
names = []

for encoding in encodings:


# Tolerance 0.5 = stricter matching, fewer false positives
matches = face_recognition.compare_faces(data["encodings"], encoding,
tolerance=0.5)
name = "Unknown"
if True in matches:
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
for i in matchedIdxs:
name = data["names"][i]
counts[name] = [Link](name, 0) + 1
name = max(counts, key=[Link])
[Link](name)

24
for name in names:
code = NAME_CODE.get(name, "X")
msg = "*" + code + "#"
[Link]([Link]())
print(msg)

for ((top, right, bottom, left), name) in zip(boxes, names):


[Link](frame, (left, top), (right, bottom), (0, 255, 0), 2)
y = top - 15 if top - 15 > 15 else top + 15
[Link](frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
0.75, (0, 255, 0), 2)

[Link]("Face Recognition", frame)


if [Link](1) & 0xFF == ord("q"):
running = False
break

[Link]()
[Link]()
if ser and ser.is_open:
[Link]()

start_btn.config(state=[Link])
stop_btn.config(state=[Link])
status_label.config(text="Stopped", fg="black")

def start_recognition():
global running
com_port = com_entry.get().strip()
if not com_port:
status_label.config(text="Enter a COM port", fg="red")
return
running = True
start_btn.config(state=[Link])
25
stop_btn.config(state=[Link])
status_label.config(text="Running...", fg="green")
t = [Link](target=recognition_loop, args=(com_port,), daemon=True)
[Link]()

def stop_recognition():
global running
running = False

# GUI
root = [Link]()
[Link]("Face Recognition")
[Link]("300x160")
[Link](False, False)

[Link](root, text="COM Port:").pack(pady=(20, 4))

com_entry = [Link](root, width=20, justify="center")


com_entry.insert(0, "COM13")
com_entry.pack()

btn_frame = [Link](root)
btn_frame.pack(pady=12)

start_btn = [Link](btn_frame, text="Start", width=10,


command=start_recognition)
start_btn.pack(side=[Link], padx=6)

stop_btn = [Link](btn_frame, text="Stop", width=10, state=[Link],


command=stop_recognition)
stop_btn.pack(side=[Link], padx=6)

status_label = [Link](root, text="Ready")


status_label.pack()

26
[Link]()

5.3 OPEN CV LIBRARY (Opensource Computer Vision Library)

OpenCV (Opensource Computer Vision Library) is a widely used open-source library


designed for real-time computer vision and image processing applications. It provides a
large number of optimized functions and algorithms that enable systems to process
images and videos efficiently. OpenCV supports multiple programming languages such
as Python, C++, and Java, but in this project, it is used with Python due to ease of
implementation.

In the proposed system, OpenCV plays a crucial role in handling video capture, image
processing, and face detection. It acts as the backbone of the software module by
providing tools to analyze and manipulate visual data in real time.

One of the primary functions of OpenCV in this project is video acquisition. It allows
the system to access the webcam and capture live video streams. The video stream is
divided into individual frames, and each frame is processed sequentially. This frame-by-
frame processing is essential for real-time face detection.

Another important function of OpenCV is image preprocessing. Before applying any


detection algorithm, the captured frames are converted into grayscale format. Grayscale
images contain only intensity values, which reduces the amount of data to be processed.
This improves the speed and efficiency of the system without significantly affecting
detection accuracy. OpenCV provides built-in functions to perform this conversion
quickly.

27
The most important role of OpenCV in this project is implementing the face detection
algorithm. It uses the Haar Cascade classifier, which is a machine learning-based
approach for object detection. The classifier is pre-trained to detect human faces by
identifying patterns such as edges, lines, and textures that correspond to facial features.
OpenCV applies this classifier to each frame and detects the presence of faces.

When a face is detected, OpenCV helps in drawing a rectangular bounding box around
the detected region. This visual representation makes it easier to verify the detection
results during testing and demonstration. It also enhances the user interface by clearly
showing where the face has been identified.

OpenCV is highly optimized for performance, which makes it suitable for real-time
applications. It uses efficient algorithms that minimize processing time and ensure
smooth operation. Even on systems with moderate hardware specifications, OpenCV can
process video frames quickly and accurately.

5.3.1 OPENCV (Opensource Computer Vision Library) PROCESSING FLOW

OpenCV (Opensource Computer Vision Library) is an open-source library used for


image processing and real-time computer vision applications. It provides optimized
functions for video capture, object detection, image enhancement, and feature extraction.

In this project, OpenCV forms the core of the face detection module. It enables the
system to access the webcam, process image frames, and detect human faces in real time.

The major functions performed by OpenCV include:

 Capturing live video through the webcam


 Dividing the video into frames for processing

28
 Converting images into grayscale format
 Applying the Haar Cascade classifier for face detection
 Drawing bounding boxes around detected faces
 Performing continuous frame-by-frame analysis

The Haar Cascade algorithm used in OpenCV is a machine learning-based detection


method trained to recognize facial features such as eyes, nose, and mouth. It provides fast
and efficient detection with relatively low computational requirements.

OpenCV is highly optimized for real-time applications, making it suitable for


surveillance and security systems. It also supports image enhancement techniques,
filtering methods, edge detection, segmentation, and advanced deep learning models.

Its flexibility allows future upgrades such as:

 Face recognition
 Motion detection
 Object tracking
 AI-based deep learning detection

OpenCV significantly improves the speed, accuracy, and reliability of the proposed
system.

5.3.2 ALGORITHM

The proposed system follows a step-by-step algorithm to perform real-time face


detection and generate alerts using the ESP32 microcontroller. The algorithm ensures
continuous monitoring, efficient processing, and immediate response when a face is
detected.

29
Algorithm for Real-Time Face Detection and Alert System

1. Start the System


Initialize the Python environment, webcam, and serial communication with the
ESP32 microcontroller.
2. Load Haar Cascade Classifier
Load the pre-trained Haar Cascade XML file for face detection using OpenCV.
3. Initialize Video Capture
Access the webcam using OpenCV and begin capturing live video.
4. Capture Frame
Read a frame from the video stream.
5. Convert to Grayscale
Convert the captured frame into grayscale format to reduce computational
complexity.
6. Detect Faces
Apply the Haar Cascade classifier to detect faces in the grayscale image.
7. Check Detection Condition

1. If no face is detected, go back to Step 4 and continue processing.

2. If a face is detected, proceed to the next step.

8. Draw Bounding Box


Draw a rectangular box around the detected face for visualization.
9. Send Signal to ESP32
Send a signal (e.g., HIGH or “1”) from Python to the ESP32 using serial
communication.
30
10. Activate Alert System
ESP32 receives the signal and:

 Turns ON the buzzer


 Displays “Face Detected” on the Liquid Crystal Display

11. Wait for Next Frame


Continue capturing and processing frames in a loop.
12. Stop Condition (Optional)
If a stop command (e.g., key press) is given, terminate the program and release
resources.
13. End the System
Close the video stream and serial communication properly.

5.4 PYSERIAL LIBRARY (Serial Communication)

Py Serial is a Python library used to enable serial communication between a computer


and external hardware devices such as microcontrollers. It provides a simple and efficient
method to send and receive data through serial ports like USB. In this project, PySerial
plays a crucial role in establishing communication between the Python-based face
detection system and the ESP32 microcontroller.

Serial communication is a method of transmitting data one bit at a time over a


communication channel. It is widely used in embedded systems due to its simplicity,
reliability, and low hardware requirements. Py Serial allows Python programs to interact
with serial ports, making it possible to control hardware devices directly from the
software.

In the proposed system, Py Serial acts as a communication bridge between the software
module (Python with OpenCV) and the hardware module (ESP32). When a face is
31
detected by the Python program, a signal is transmitted to the ESP32 through serial
communication. This signal is then used by the ESP32 to trigger hardware actions such as
activating the buzzer and updating the Liquid Crystal Display.

One of the primary functions of Py Serial in this project is to establish a connection


between the computer and the ESP32. This is done by specifying parameters such as the
serial port (COM port), baud rate (typically 9600 or 115200), and timeout settings. Once
the connection is established, data transmission becomes reliable and efficient.

Py Serial provides functions such as [Link] () to open the communication port and
write () to send data. In this system, Python sends simple commands such as “1” or “0” to
indicate whether a face is detected. These commands are received and processed by the
ESP32, which then performs the required actions.

Another important feature of Py Serial is its ability to support real-time communication.


It ensures that data is transmitted with minimal delay, allowing the system to respond
immediately when a face is detected. This is essential for applications like security
systems, where quick response time is critical.

5.4.1 SERIAL COMMUNICATION

Py Serial is a Python library used to establish communication between the computer and
the ESP32 microcontroller. It acts as a communication bridge between the software
module and the embedded hardware module.

When a face is detected by the Python program, Py Serial transmits a signal to the
ESP32 through serial communication. Based on the received signal, the ESP32 activates
the buzzer and displays status information on the Liquid Crystal Display.

Functions performed by Py Serial include:


32
 Establishing serial connection with ESP32
 Sending detection signals from Python to hardware
 Real-time data transmission
 Synchronizing software and hardware operations
 Supporting reliable communication with minimal delay

The communication setup typically includes parameters such as:

 COM Port Selection


 Baud Rate (9600 / 115200)
 Timeout Settings

Py Serial provides functions such as:

 [Link] () for opening communication


 write () for transmitting data
 read () and readline () for receiving data

The library is lightweight, efficient, and ideal for embedded system communication. It
ensures quick response time, which is essential in real-time security applications.

Py Serial also supports future wireless extensions using the ESP32’s built-in Wi-Fi and
Bluetooth modules.

33
5.5 DEVELOPMENTD ENVIRONMENT

The software was developed and tested using the following tools:

Tool Purpose
Python IDE / VS Code /
Coding and Debugging
PyCharm
Arduino IDE Programming ESP32

Command Prompt / Terminal Running Python Scripts

These tools provide a complete development environment for coding, testing, and
deployment.

5.6 SYSTEM REQUIREMENT

The minimum software and system requirements for running the project are:

Requirement Specification
Operating System Windows / Linux / macOS

Processor Intel i3 or above

RAM Minimum 4 GB

Storage 500 MB Free Space

Python Version Python 3.x

Webcam Support USB Camera

34
CHAPTER 6

RESULT & ANALYSIS

HARDWARE COMPLETION

6.1 RESULTS AND ANALYSIS

The proposed real-time face detection and alert system was successfully implemented
and tested under various conditions to evaluate its performance, accuracy, and reliability.
The system integrates Python-based face detection using OpenCV with an ESP32
microcontroller for alert generation.

35
Figure 6.1 HARDWARE COMPLETION

6.1.1 Results Obtained

The system was able to detect human faces in real time using a webcam and trigger the
alert mechanism effectively. Upon detecting a face, the Python program sent a signal to
the ESP32, which immediately activated the buzzer and displayed a message on the
Liquid Crystal Display. The system demonstrated stable performance with minimal delay
between detection and alert generation.

The face detection process was accurate under normal lighting conditions, and the system
successfully identified faces at different angles and distances within a reasonable range.
The Liquid Crystal Display displayed appropriate status messages such as “Face
Detected,” while the buzzer provided an audible alert, ensuring effective notification.

36
Figure 6.1.1 Results Obtained

6.1.2 Performance Analysis

The system performance was analyzed based on several key parameters:

1. Detection Accuracy

The Haar Cascade classifier provided satisfactory accuracy for detecting frontal human
faces. The system performed well when the face was clearly visible and properly
illuminated. However, detection accuracy decreased under poor lighting conditions or
when the face was partially covered.

2. Response Time

The system exhibited fast response time, with detection and alert generation occurring
almost instantly (within milliseconds). This makes the system suitable for real-time
applications where quick action is required.

3. Lighting Conditions

The system performed best under adequate lighting. In low-light or high-shadow


conditions, the detection rate decreased, highlighting a limitation of the Haar Cascade
algorithm.

4. Multiple Face Detection

37
The system was capable of detecting multiple faces simultaneously and triggering alerts
accordingly. However, performance depended on lighting and camera resolution.

5. System Stability

The system operated continuously without major interruptions or crashes. The


integration between Python and ESP32 using serial communication was stable and
reliable.

6.2 OBSERVATION TABLE

Test Condition Observation


Good Lighting High accuracy and stable detection

Low Lighting Reduced detection accuracy

No Face No alert triggered


Single Face Accurate detection and alert
Multiple Faces Detected with slight delay
Partial Face Detection may fail

6.3 ANALYSIS SUMMARY

The system demonstrates efficient real-time performance with a good balance between
accuracy and speed. The integration of software and hardware components ensures
immediate alert generation, making the system reliable for basic security applications.

38
However, the system has certain limitations, such as dependency on lighting conditions
and lack of advanced recognition capabilities. These limitations can be addressed in
future improvements by incorporating deep learning techniques and advanced image
processing methods.

39
CHAPTER 7

CONCLUSION

7.1 CONCLUSION

The proposed project successfully demonstrates the design and implementation of a real-
time face detection and alert system using Python, OpenCV, and the ESP32
microcontroller. The system is capable of capturing live video, processing frames in real
time, and detecting human faces using the Haar Cascade algorithm with satisfactory
accuracy. Upon detection, the system effectively communicates with the ESP32 to trigger
hardware components such as a buzzer and Liquid Crystal Display, providing immediate
audible and visual alerts.

The integration of software-based image processing with embedded hardware ensures


fast response time, reliability, and efficient system performance. One of the key
achievements of this project is its low-cost and simple architecture, making it suitable for
practical deployment in small-scale security applications such as homes, offices, and
restricted areas. The modular design allows easy maintenance and future upgrades
without major modifications.

Although the system performs well under normal lighting conditions, it has certain
limitations such as reduced accuracy in low-light environments and lack of face
recognition capability. Despite these limitations, the project meets its objectives and
demonstrates the feasibility of implementing a real-time, hardware-integrated face
detection system Overall, the system provides a strong foundation for developing
advanced smart security solutions and highlights the effective use of computer vision and
embedded systems in real-world applications.

40
CHAPTER 8

FUTURE ENHANCEMENT

8.1 FUTURE ENHANCEMENT

The proposed system can be further enhanced and extended with advanced features to
improve its functionality, accuracy, and usability. Some possible future improvements
include:

1. Face Recognition:
Upgrade the system to identify specific individuals instead of only detecting faces.
2. Mobile Application Integration:
Send real-time notifications or alerts to users through a mobile application.
3. Cloud-Based Monitoring:
Store and access data remotely using cloud platforms for better monitoring and
analysis.
4. Smart Door Lock Integration:
Automate door access by unlocking only for authorized individuals.
5. Multi-Camera Support:
Expand the system to monitor multiple locations simultaneously using multiple
cameras.
6. AI-Based Deep Learning Models:
Replace the Haar Cascade algorithm with advanced deep learning models for
higher accuracy and better performance under varying conditions.

41
CHAPTER 9

REFERENCES

9.1 REFERENCES

1. Viola, P., & Jones, M., “Rapid Object Detection using a Boosted Cascade of

Simple Features,” IEEE Conference on Computer Vision and Pattern Recognition,


2001.
2. Zhang, K., Zhang, Z., Li, Z., & Qiao, Y., “Joint Face Detection and Alignment

using Multi-task Cascaded Convolutional Networks,” IEEE Signal Processing


Letters, 2016.
3. Real-Time Face Detection using Deep CNN, IEEE, 2022.

4. Embedded Vision Systems for Surveillance, IEEE Sensors Journal, 2022.

5. Facial Recognition in Policing and Security Studies, Journal of Security Research.

6. OpenCV Documentation, Open Source Computer Vision Library, Available:

[Link]
7. Espressif Systems, ESP32 Technical Reference Manual, Available:
[Link]
8. Python Software Foundation, Python Documentation, Available:
[Link]
9. Bradski, G., “The OpenCV Library,” Dr. Dobb’s Journal of Software Tools, 2000.

10. Szeliski, R., Computer Vision: Algorithms and Applications, Springer, 2010.

11. PySerial Documentation, “Python Serial Port Extension,” Available:


[Link]
12. Gonzalez, R. C., & Woods, R. E., Digital Image Processing, Pearson Education,

2008.
13. Bishop, C. M., Pattern Recognition and Machine Learning, Springer, 2006.

42
14. Goodfellow, I., Bengio, Y., & Courville, A., Deep Learning, MIT Press, 2016.

15. Arduino Documentation, “Serial Communication and Microcontroller


Programming,” Available: [Link]
16. Redmon, J., Divvala, S., Girshick, R., & Farhadi, A., You Only Look Once:

Unified, Real-Time Object Detection, CVPR, 2016.


17. He, K., Zhang, X., Ren, S., & Sun, J., Deep Residual Learning for Image

Recognition, CVPR, 2016.


18. Howard, A. G., et al., MobileNets: Efficient Convolutional Neural Networks for

Mobile Vision Applications, arXiv preprint arXiv:1704.04861.


19. Sandler, M., et al., MobileNetV2: Inverted Residuals and Linear Bottlenecks,

CVPR, 2018.
20. Liu, W., et al., SSD: Single Shot MultiBox Detector, ECCV, 2016.

21. Schroff, F., Kalenichenko, D., & Philbin, J., FaceNet: A Unified Embedding for

Face Recognition and Clustering, CVPR, 2015.


22. Taigman, Y., Yang, M., Ranzato, M., & Wolf, L., DeepFace: Closing the Gap to

Human-Level Performance in Face Verification, CVPR, 2014.


23. Kortli, Y., Jridi, M., Falou, A. A., & Atri, M., Face Recognition Systems: A

Survey, Sensors, vol. 20, 2020.


24. Chen, Z., et al., Lightweight CNN-Based Face Recognition on Embedded Systems,

Multimedia Systems, 2023.


25. Hofer, P., et al., Efficient Face Recognition Pipelines on Embedded Devices,

MoMM Conference, 2023.


26. IEEE ICME, Low-Power Efficient and Accurate Facial-Landmark Detection for

Embedded Systems, 2024.


27. Wang, X., et al., Privacy and Ethics in Facial Recognition Technology, Frontiers

in Big Data, 2024.

43
28. Qandeel, M., Facial Recognition Technology: Regulations, Rights and the Rule of

Law, Frontiers in Big Data, 2024.


29. Espressif Systems, ESP-WHO: Face Detection and Recognition Framework,

Technical Documentation.
30. Edge AI and Vision Alliance, Edge AI for Vision Applications, 2023.

31. TensorFlow, TensorFlow Lite for Microcontrollers, Available:

[Link]
32. IEEE Access, Real-Time Lightweight CNN Models for Embedded Vision, 2023.

33. Jain, A. K., Bolle, R., & Pankanti, S., Biometrics: Personal Identification in

Networked Society, Springer, 1999.


34. Turk, M., & Pentland, A., Eigenfaces for Recognition, Journal of Cognitive

Neuroscience, 1991.
35. NIST, Face Recognition Vendor Test (FRVT), National Institute of Standards and

Technology Reports.

44

You might also like