Yogananda School of AI, Computers and Data-
Sciences Faculty of Engineering & Technology
Shoolini University, Solan, Himachal Pradesh
Biometric Traits
Project File
BTech CSE with Specialization in Cyber
Security 5th Semester
Session-2023-2027
Project Title: Face Detection and Reaction Setter using
Python and MySQL
Submitted To: Submitted By:
Dr. Arvind Sharma Yulan Yadav
Associate Professor INGF202312013
1
1. Introduction
Face recognition has emerged as one of the most widely adopted biometric techniques due to its
convenience, non-contact operation, and ability to analyze individuals in real time. With
advancements in artificial intelligence and computer vision, face detection systems are now used in
security, automation, and user authentication processes.
This project demonstrates a Face Detection and Reaction Setter System using Python and MySQL.
The system captures live video from a webcam, detects faces, assigns a reaction based on
recognition logic, and stores the results within a structured database. This integration showcases
how biometric technology can enhance intelligent decision-making and digital security.
2
2. Objectives
The main goals of this project are:
To develop a real-time face detection system using Python and OpenCV.
To recognize and classify detected faces as known or unknown.
To generate automatic reactions based on the detected identity.
To record detection events, identity results, and timestamps in a MySQL database.
To demonstrate how biometric systems can support automation and secure data logging.
3. Scope of the Project
This project focuses on implementing real-time face detection and database-backed logging. The
system can be used for:
Automated attendance tracking
Smart door or access systems
Monitoring unauthorized access
Personalized user interaction systems
Security and surveillance analytics
3
Code:
import cv2
import [Link]
from datetime import datetime
def connect_database():
"""Connect to MySQL database and return the connection object."""
try:
db = [Link](
host="localhost",
user="root",
password="your_mysql_password",
database="biometric_system"
print("[INFO] Database connected successfully.")
return db
except Exception as e:
print("[ERROR] Database Connection Failed:", e)
exit()
def save_to_db(cursor, db, name, reaction):
"""Insert detected face record into the database."""
timestamp = [Link]()
4
sql = "INSERT INTO face_log (name, reaction, timestamp) VALUES (%s, %s, %s)"
[Link](sql, (name, reaction, timestamp))
[Link]()
print(f"[LOG] Saved: {name} | {reaction} | {timestamp}")
def identify_face():
"""
Placeholder logic for recognition.
In a real system, this would use trained ML models (LBPH / FaceNet).
"""
# Simulation: Change or upgrade later for real recognition
recognized = False
if recognized:
return "Authorized User", "Access Granted - Welcome!"
else:
return "Unknown", "Warning: Unrecognized Face Detected"
def start_face_detection():
# Connect to database
db = connect_database()
cursor = [Link]()
5
# Load Haar Cascade Classifier
face_detector = [Link]([Link] +
"haarcascade_frontalface_default.xml")
cam = [Link](0)
if not [Link]():
print("[ERROR] Webcam not detected!")
exit()
print("[INFO] Face Detection Started. Press 'Q' to exit.")
while True:
ret, frame = [Link]()
if not ret:
print("[ERROR] Frame not received from camera.")
break
gray = [Link](frame, cv2.COLOR_BGR2GRAY)
# Detect faces
faces = face_detector.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
6
for (x, y, w, h) in faces:
[Link](frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
name, reaction = identify_face()
save_to_db(cursor, db, name, reaction)
[Link](frame, reaction, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.7, (0, 255, 0), 2)
[Link]("Biometric Face Detection System", frame)
if [Link](1) & 0xFF == ord('q'):
print("\n[INFO] System Terminated by User.")
break
[Link]()
[Link]()
[Link]()
[Link]()
print("[INFO] Resources Closed Successfully.")
if __name__ == "__main__":
start_face_detection()
7
8