0% found this document useful (0 votes)
30 views9 pages

Final Project Draft

The final project aims to design and develop a facial recognition system for identifying individuals and automating attendance processes. Participants will learn about facial recognition technology, its implementation using Python and OpenCV, and secure database management. The project successfully integrates these technologies to enhance security and efficiency in attendance tracking.

Uploaded by

rheymonoy
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)
30 views9 pages

Final Project Draft

The final project aims to design and develop a facial recognition system for identifying individuals and automating attendance processes. Participants will learn about facial recognition technology, its implementation using Python and OpenCV, and secure database management. The project successfully integrates these technologies to enhance security and efficiency in attendance tracking.

Uploaded by

rheymonoy
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
You are on page 1/ 9

Final Project

<Title>

Course Code: CPE103 Program: BSCPE

Course Title: Object-Oriented Programming Date Performed: 2/22/2025

Section: 1A Date Submitted: 4/26/2025

Leader: Vasig, Yuan Hessed O.


Members: Disomnong, Jalilah
Monoy, Justin Rhey Instructor: Engr. Maria Rizette Sayo
Nerio, Hannah Grace
Palmes, Lewis Clark

1. Objective(s):

The key objectives of this project are:

 To design and develop a facial recognition system for identifying and tracking individuals registered in the
system.
 To enhance security by ensuring accurate identification through facial recognition technology.
 To automate the attendance process to save time and reduce manual work.

2. Intended Learning Outcomes (ILOs):

By the end of this project, participants will:

 Understand the principles and applications of facial recognition technology.


 Gain experience in implementing facial recognition using Python and OpenCV.
 Enhance knowledge of database management for secure data storage.
 Learn how to automate attendance systems using facial recognition.

3. Discussion:
Facial recognition technology leverages computer vision and machine learning to identify individuals based on
their unique facial features. By combining this with an Arduino-controlled hardware system, we can achieve an
efficient and secure identification process.

The project workflow includes:

 Capturing and preprocessing facial data.


 Extracting facial features using deep learning models such as OpenCV..
 Developing a structured database to store facial records securely.
 Automating attendance recording based on successful identification.

4. Materials and Equipments:

Hardware:

 Camera (Webcam)
 Computer

Software:

 OpenCV Library
 Python Programming Language
 Visual Studio Code

5. Procedure:
Data Collection:

 Capture facial data from registered individuals by taking a picture in multiple angles
 Ensure proper lighting conditions to improve detection accuracy.

Preprocessing:

 Apply image enhancement techniques such as normalization, and face alignment to improve accuracy.

Feature Extraction:

 Extract unique facial features for identification.


Database Management:

Develop a structured database to securely store facial data and attendance records.
Identification Process:

Design a Python program that compares detected faces with the stored data for identification.

SOURCE CODE:

import os
import cv2
import numpy as np
import face_recognition
import customtkinter as ctk
from PIL import Image, ImageTk
from datetime import datetime
import threading
import pywinstyles

# Initialize theme
ctk.set_appearance_mode("Dark")
ctk.set_default_color_theme("dark-blue")

# Locate directories
directories = os.path.dirname(os.path.abspath(_file_))
students_dir = os.path.join(directories, "Images", "Students")
attendance_path = os.path.join(directories, "Attendance.csv")
# Prepare attendance file
if not os.path.isdir(students_dir):
raise FileNotFoundError(f"Student images folder not found: {students_dir}")
if not os.path.isfile(attendance_path):
with open(attendance_path, "w") as f:
f.write("Name,Timestamp\n")

# Load and encode student faces


encodeListKnown = []
studentNames = []
for student in os.listdir(students_dir):
folder = os.path.join(students_dir, student)
if not os.path.isdir(folder): continue
for file in os.listdir(folder):
path = os.path.join(folder, file)
img = cv2.imread(path)
if img is None: continue
rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encs = face_recognition.face_encodings(rgb)
if encs:
encodeListKnown.append(encs[0])
studentNames.append(student.upper())
print(f"Loaded {len(encodeListKnown)} encodings for {len(set(studentNames))} students.")

# Attendance function
def markAttendance(name):
with open(attendance_path, "r+", newline="") as f:
entries = f.readlines()
names = [e.split(',')[0] for e in entries]
if name not in names:
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
f.write(f"{name},{now}\n")
print(f"Marked {name} at {now}")

# GUI Application
class AttendanceApp(ctk.CTk):
def __init__(self):
super().__init__()
self.title("Face Recognition Attendance")
self.geometry("900x500")
pywinstyles.apply_style(self, style="mica")

self.unknown_count = 0
self.present_students = set()

# Camera frame
self.camera_frame = ctk.CTkFrame(self, corner_radius=15)
self.camera_frame.grid(row=0, column=0, padx=20, pady=20)
self.img_label = ctk.CTkLabel(self.camera_frame, text="")
self.img_label.pack()

# Control panel
self.control_panel = ctk.CTkFrame(self, width=300, corner_radius=15)
self.control_panel.grid(row=0, column=1, sticky="nsew", padx=10, pady=20)

ctk.CTkLabel(self.control_panel, text="Control Panel", font=("Arial Bold", 20)).pack(pady=10)

self.start_button = ctk.CTkButton(self.control_panel, text="Start Camera", font=("Arial", 16),


command=self.start_camera)
self.start_button.pack(pady=8)

self.stop_button = ctk.CTkButton(self.control_panel, text="Stop Camera", font=("Arial", 16),


command=self.stop_camera)
self.stop_button.pack(pady=8)

self.status_label = ctk.CTkLabel(self.control_panel, text="Status:\nIdle", justify="left")


self.status_label.pack(pady=20)

ctk.CTkLabel(self.control_panel, text="Live Stats", font=("Arial Bold", 16)).pack(pady=5)


self.total_label = ctk.CTkLabel(self.control_panel, text=f"Total Students: {len(set(studentNames))}")
self.total_label.pack()
self.present_label = ctk.CTkLabel(self.control_panel, text="Marked Present: 0")
self.present_label.pack()
self.unknown_label = ctk.CTkLabel(self.control_panel, text="Unknown Detected: 0")
self.unknown_label.pack()

self.protocol("WM_DELETE_WINDOW", self.on_closing)
self.cap = None
self.running = False

def start_camera(self):
if self.running: return
self.cap = cv2.VideoCapture(0)
if not self.cap.isOpened():
self.status_label.configure(text="Status:\nFailed to open camera.")
return
self.running = True
self.status_label.configure(text="Status:\nCamera running.")
threading.Thread(target=self.update_frame, daemon=True).start()

def update_frame(self):
THRESHOLD = 0.55
while self.running:
ret, frame = self.cap.read()
if not ret: break

small = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)


rgb_small = cv2.cvtColor(small, cv2.COLOR_BGR2RGB)
locs = face_recognition.face_locations(rgb_small)
encs = face_recognition.face_encodings(rgb_small, locs)

for enc, loc in zip(encs, locs):


distances = face_recognition.face_distance(encodeListKnown, enc)
best_idx = np.argmin(distances)
best_dist = distances[best_idx]

top, right, bottom, left = [v * 4 for v in loc]

if best_dist <= THRESHOLD:


name = studentNames[best_idx]
if name not in self.present_students:
self.present_students.add(name)
markAttendance(name)
self.present_label.configure(text=f"Marked Present: {len(self.present_students)}")
else:
name = "UNKNOWN"
self.unknown_count += 1
self.unknown_label.configure(text=f"Unknown Detected: {self.unknown_count}")

# Draw
cv2.rectangle(frame, (left, top), (right, bottom), (255, 165, 0), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (255, 165, 0), cv2.FILLED)
cv2.putText(frame, name, (left + 6, bottom - 6),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)

# Update GUI image


img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=img)
self.img_label.imgtk = imgtk
self.img_label.configure(image=imgtk)

self.cap.release()

def stop_camera(self):
if not self.running: return
self.running = False
self.status_label.configure(text="Status:\nCamera stopped.")

def on_closing(self):
self.stop_camera()
self.destroy()

if _name_ == '_main_':
app = AttendanceApp()
app.mainloop()

6. Output

<pic>
<description>

7. Conclusion:
This project successfully combines facial recognition technology to deliver a secure and automated identification
system. The integration of these technologies ensures improved security, efficiency, and accuracy in tracking
attendance and controlling access. By implementing this system, organizations can streamline attendance
management while enhancing overall security measures.

8. References

You might also like