0% found this document useful (0 votes)
13 views25 pages

Cs Projects

Cs projects for class 12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views25 pages

Cs Projects

Cs projects for class 12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ACHARIYA SIKSHA MANDIR

ERODE – 638 107

2024 – 2025

COMPUTER SCIENCE

PROJECT REPORT

Submitted by

TAMZHILSELVAN.V

GRADE XII - LOTUS

1
CERTIFICATE

This is to certify that the project work entitled

“AGE AND GENDER DETECTOR” is the bonafide

record of work done by

TAMZHILSELVAN.V, Roll No:

in partial fulfilment of the requirement for the award of Grade XII

during the academic year 2024-2025

VIVA VOCE HELD ON:

INTERNAL EXAMINER EXTERNAL EXAMINER

PRINCIPAL

2
ACKNOWLEDGEMENT

First, I would like to thank the Almighty for all the blessings
which are endowed upon me. With profound sense of indebtedness, I
thank my parents and friends for their immense love and support to do
the project
I am grateful to thank our Principal Mr. Ravula Vara Praveen
for his inspiration and permission to undergo the project.
I express my immense gratitude to my subject teacher
Mr. T.VENKATESAN, Business studies Faculty, who always gave
valuable suggestions and guidance for completion of my project.
He helped me to understand and remember the important details
of the project.
I would like to take this opportunity to record my gratitude to all
those persons who have enthusiastically assisted me during all the
phases of project.

TAMZHILSELVAN.V
XII - LOTUS

3
CONTENT

S.No PARTICULARS PAGE.No

1 Introduction 5

2 Key Concepts of Age and Gender Detector 6

Tools and Libraries for Age and Gender


3 8
Detector

4 workings of the Age and Gender Detector 10

5 Applications of Age and Gender Detector 12

6 Input for Age and Gender Detector 14

7 Output of the Age and Gender Detector 16

8 Steps to Run the Code 19

9 SOURCE CODE 20

Conclusion of the Age and Gender


10 23
Detector

11 Bibliography 25

DATE OF SUBMISSION: TEACHERS SIGNATURE:

4
INTRODUCTION

The Age and Gender Detector is a computer vision-based


project designed to predict the approximate age group and
gender of a person from an image or video feed. This project
utilizes advanced techniques in deep learning and machine
learning, integrated with computer vision, to analyze facial
features and provide predictions.

With the increasing demand for intelligent systems, age and


gender detection finds applications in diverse fields such as
surveillance, marketing, healthcare, and social media
analytics. This project demonstrates the practical
implementation of such technologies by leveraging pre-
trained models for face detection, age estimation, and gender
classification.

The program works by first detecting faces in an image or


webcam feed using a pre-trained deep learning model. Once
a face is detected, it is analyzed using convolutional neural
networks (CNNs) trained to classify the image into specific
age groups and gender categories.

This project not only highlights the potential of artificial


intelligence in solving real-world problems but also serves as
an excellent example of how technology can simplify complex
tasks, making it an engaging and educational experience for
Class 12 Computer Science students.

5
Key Concepts of Age and
Gender Detector

1. Computer Vision
Computer vision involves enabling machines to interpret and
analyze visual data like images and videos. In this project,
computer vision techniques are used to detect faces in
images or live video feeds.

2. Deep Learning Models

Deep learning models, particularly Convolutional Neural


Networks (CNNs), are employed to analyze facial features for
age and gender prediction. These models are pre-trained on
large datasets to recognize patterns related to age and
gender.

3. Face Detection

A pre-trained Caffe-based SSD (Single Shot MultiBox


Detector) model is used to detect human faces.
The model processes an image and outputs bounding boxes
indicating the location of faces.

4. Age Prediction

The detected face is passed through a CNN model trained to


classify age into specific groups, such as (0-2), (15-20), (25-
32), etc.

6
5. Gender Prediction

The same CNN pipeline is used to classify gender as Male or


Female.
The prediction is made based on features like facial symmetry
and proportions.

6. Image Preprocessing

Images are resized and normalized to meet the input


requirements of the models.
OpenCV’s cv2.dnn.blobFromImage is used for preprocessing,
including resizing, mean subtraction, and scaling.

7. Output Visualization

The program overlays rectangles on detected faces with


labels indicating the predicted age group and gender.

8. Applications of the Key Concepts


Face Detection is used in security systems, unlocking devices,
and monitoring applications.
Age and Gender Prediction has applications in targeted
advertising, social media analytics, and demographic studies.

7
Tools and Libraries for Age
and Gender Detector

1. Programming Language
 Python: The project is implemented using Python, a
versatile and beginner-friendly programming language
widely used for AI and computer vision applications.

2. Libraries Used
a. OpenCV (Open Source Computer Vision Library)
 Used for image and video processing.
 Key functionalities:
o Face detection using pre-trained deep learning

models.
o Drawing rectangles and labels on detected faces

o Installation :

pip install opencv-python

b. NumPy
 A library for numerical computations and data
manipulation.
 Used for handling arrays and scaling data.
 Installation
pip install numpy

8
c. Pre-trained Deep Learning Models (Caffe
Framework)
Pre-trained models are used to avoid training from scratch,
making the project implementation efficient.
 Face Detection Model:
o Files: deploy.prototxt and

res10_300x300_ssd_iter_140000.caffe
model.
o Detects faces in an image or video feed.

 Age Prediction Model:


o Files: age_deploy.prototxt and

age_net.caffemodel.
o Predicts age groups like (0-2), (15-20), (25-

32).
o
 Gender Prediction Model:
o Files: gender_deploy.prototxt and

gender_net.caffemodel.
o Classifies gender as Male or Female.

3. Hardware and Software Requirements


 Hardware:
o A computer with a webcam (for live video feed).

o Basic processing power (GPU is optional but not

mandatory).
 Software:
o Python IDE (e.g., PyCharm, Jupyter Notebook, or

VS Code).
o Necessary Python libraries installed via pip.

9
workings of the Age and
Gender Detector

1. Input Data
The program can process:
 Live video feed from a webcam.
 Static images uploaded by the user.

2. Preprocessing
 The input image is resized to a standard size suitable for
the deep learning models.
 A blob (Binary Large Object) is created from the image
using OpenCV’s cv2.dnn.blobFromImage.
o Adjusts size, scales pixel values, and performs mean

subtraction.

3. Face Detection
 A pre-trained Caffe SSD (Single Shot MultiBox Detector)
model is used to locate faces in the input image.
 Steps:
1. The face detection model outputs bounding boxes
for detected faces.
2. Confidence scores are checked to filter out weak
detections (e.g., confidence > 0.5).
3. Each detected face is cropped and passed to the
next stage for predictions.

10
4. Age and Gender Prediction
 Gender Prediction:
o The cropped face is passed to the gender prediction

model, which classifies it as Male or Female.


 Age Prediction:
o The cropped face is also passed to the age

prediction model, which categorizes it into


predefined age groups, such as (0-2), (15-20), (25-
32).

5. Output Visualization
 For each detected face, the program overlays:
1. A rectangle around the face.
2. A label displaying the predicted age group and
gender.
 The processed frame is displayed in a window, updating
in real-time for video feeds.

6. Closing the Program


 The program continuously processes frames until the user
exits (e.g., pressing the q key).

11
Applications of Age and
Gender Detector

1. Security and Surveillance


 Enhances surveillance systems by identifying age and
gender of individuals in real-time.
 Useful in monitoring sensitive areas like airports, public
transport hubs, and government facilities.

2. Targeted Advertising
 Helps advertisers customize campaigns based on the
demographic profile (age and gender) of their audience.
 For example, displaying ads for toys to children or
cosmetics to women in retail stores or malls.

3. Retail Analytics
 Used in retail environments to gather insights on
customer demographics.
 Helps store owners understand their customer base and
improve product placement or services.

4. Social Media and Entertainment


 Enhances user experience by personalizing
recommendations based on detected age and gender.
 Social media platforms can tailor content and
advertisements accordingly.

12
5. Healthcare Applications
 Used in telemedicine to gather basic demographic
information.
 Helps in early detection of age-related conditions like
wrinkles, skin issues, or other visible health factors.

6. Smart Attendance Systems


 In educational institutions or workplaces, it can add an
extra layer of security by detecting and recording
demographic details during attendance marking.

7. Public Demographic Analysis


 Useful for collecting anonymized data in public spaces
for urban planning and policymaking.
 Can be deployed in smart cities to study population flow
and diversity.

8. Gaming and Augmented Reality (AR)


 Used in AR applications to adapt user experiences based
on detected age and gender.
 Enables dynamic character customization in video
games.

9. Education and Research


 Helps students and researchers explore AI and machine
learning applications in real-world scenarios.
 Demonstrates practical implementation of deep learning
and computer vision concepts.

13
Input for Age and Gender
Detector

1. Webcam Feed (Real-Time Video Input)


Description:
The webcam provides a live video feed, which is
processed frame by frame to detect faces and predict age
and gender.
How It Works:
o The script accesses the webcam using
cv2.VideoCapture(0).
o Each frame from the webcam is treated as an image
for face detection and prediction.
Advantages:
o Real-time processing.
o Easy to set up and use for live demonstrations.

2. Static Image Input


Description:
A pre-saved image (e.g., a photograph or scanned
document) is processed to detect faces and predict their
age and gender.
How It Works:
 The image file is read using OpenCV's cv2.imread()
function.
 Face detection and predictions are performed on the
image.

14
3. Video File Input
Description:
A pre-recorded video file (e.g., .mp4, .avi) is processed
frame by frame to detect faces and predict their age and
gender.

How It Works:
 The video file is read using
cv2.VideoCapture("video_path.mp4").
 Each frame is processed similarly to the webcam feed.
Advantages:
 Useful for testing on a larger dataset or controlled
scenarios.

4. Input Specifications
 Image Requirements:
o Formats: .jpg, .png, .bmp, etc.

o Recommended size: 300x300 or larger for better

detection accuracy.
 Video Requirements:
o Formats: .mp4, .avi, .mkv, etc.

o Should contain clear and visible faces for accurate

detection.

15
Output of the Age and Gender
Detector

1. Visual Output
The project generates a processed image or video feed with
the following:
Bounding Boxes:
Rectangles drawn around the detected faces in the
input.
Predicted Labels:
Text labels showing the predicted age group and gender
for each detected face.

2. Textual Output
The labels displayed for each detected face include:

Gender: Predicted as either Male or Female.

Age Group: Predicted as one of the predefined age


ranges, such as (0-2), (15-20), (25-32), etc.

Example Output on Screen


For a face detected in the frame:
1. Bounding Box:
A green rectangle surrounding the detected face.
2. Label Display:
o Position: Above the bounding box.

o Content: "Male, (25-32)"

16
Output in Different Input Scenarios

a. Real-Time Webcam Feed


 The output appears live on the screen.
 Each frame of the video feed is processed, and
predictions are updated dynamically.
 Example:
o A live feed with green rectangles and text labels for

every detected face.


b. Static Image Input
 The image is displayed in a window with predictions
overlaid on the detected faces.
 Example:
o An image with bounding boxes and labels such as

"Female, (15-20)".
c. Pre-Recorded Video
 Each frame of the video is processed similarly to the
webcam feed.
 The video can be saved with overlaid predictions for
later review.

17
Sample Output Demonstration
Here’s an example of what the output might look like:
1. Detected Face 1:
o Bounding Box: Drawn around the face.

o Label: "Male, (25-32)".

2. Detected Face 2:
o Bounding Box: Drawn around another face.

o Label: "Female, (15-20)".

Output Characteristics
1) Real-Time Processing:
Dynamic predictions for live webcam or video input.
2) Accurate Predictions:
Results are dependent on the quality of the input image
and the pre-trained models.
3) Visual Clarity: Clean and user-friendly display with
bounding boxes and text labels.

18
Steps to Run the Code
Install Required Libraries:
Install the necessary Python libraries using pip:
pip install opencv-python numpy

Download Pre-trained Models:


 Face Detection:
o deploy.prototxt

o res10_300x300_ssd_iter_140000.caffe

model
o

 Age Prediction:
o age_deploy.prototxt

o age_net.caffemodel

 Gender Prediction:
o gender_deploy.prototxt

o gender_net.caffemodel

Place Models in the Project Directory:

Ensure all the model files are in the same directory as your
Python script.

Run the Script:

Execute the script using:


python age_gender_detector.py

19
SOURCE CODE
import cv2
import numpy as np

# Paths to the pre-trained models


FACE_PROTO = "deploy.prototxt"
FACE_MODEL = "res10_300x300_ssd_iter_140000.caffemodel"
AGE_PROTO = "age_deploy.prototxt"
AGE_MODEL = "age_net.caffemodel"
GENDER_PROTO = "gender_deploy.prototxt"
GENDER_MODEL = "gender_net.caffemodel"

# Predefined age groups and gender categories


AGE_LIST = ['(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32)', '(38-43)',
'(48-53)', '(60-100)']
GENDER_LIST = ['Male', 'Female']

# Load the pre-trained models


face_net = cv2.dnn.readNet(FACE_MODEL, FACE_PROTO)
age_net = cv2.dnn.readNet(AGE_MODEL, AGE_PROTO)
gender_net = cv2.dnn.readNet(GENDER_MODEL,
GENDER_PROTO)

# Function to detect faces


def detect_faces(net, frame, confidence_threshold=0.5):
blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), [104, 117,
123], False, False)
net.setInput(blob)
detections = net.forward()
faces = []
h, w = frame.shape[:2]

for i in range(detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > confidence_threshold:
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(x1, y1, x2, y2) = box.astype("int")
20
faces.append((x1, y1, x2, y2))
return faces

# Function to predict age and gender


def predict_age_gender(face_net, age_net, gender_net, frame, faces):
for (x1, y1, x2, y2) in faces:
face = frame[max(0, y1):min(y2, frame.shape[0]), max(0,
x1):min(x2, frame.shape[1])]
blob = cv2.dnn.blobFromImage(face, 1.0, (227, 227), (78.426,
87.769, 114.896), swapRB=False)

# Gender prediction
gender_net.setInput(blob)
gender_preds = gender_net.forward()
gender = GENDER_LIST[gender_preds[0].argmax()]

# Age prediction
age_net.setInput(blob)
age_preds = age_net.forward()
age = AGE_LIST[age_preds[0].argmax()]

label = f"{gender}, {age}"


cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, label, (x1, y1 - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 255), 2)
return frame

# Main function to process video stream


def main():
cap = cv2.VideoCapture(0) # Use webcam as input
while True:
ret, frame = cap.read()
if not ret:
break

faces = detect_faces(face_net, frame)


output_frame = predict_age_gender(face_net, age_net,
gender_net, frame, faces)
21
cv2.imshow("Age and Gender Detector", output_frame)

# Exit on pressing 'q'


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

cap.release()
cv2.destroyAllWindows()

if __name__ == "__main__":
main()

22
Conclusion of the Age and
Gender Detector

Key Takeaways:
Integration of Advanced Technologies:
The project highlights the practical implementation of
technologies such as:

o OpenCV for image processing.


o Deep Neural Networks (DNN) for age and gender
prediction.
Real-World Relevance:
The project has various applications in fields such as
security, retail analytics, targeted advertising, and
healthcare, showcasing its practical value.
Educational Value:
o Introduces students to key concepts in artificial
intelligence, such as face detection and
classification.
o Serves as a hands-on example of how data
preprocessing, model inference, and visualization
are integrated into a complete system.
Challenges and Learnings:
o Challenges Faced: Handling variations in lighting,
angles, and image quality for accurate predictions.
o Learnings: Understanding the importance of pre-
trained models and their role in reducing
computational effort and improving accuracy.
23
Future Scope:
Improved Accuracy:
Use more advanced models, such as CNNs trained on
larger datasets, for better performance.
Extended Features:
o Include additional attributes like emotion detection
or ethnicity classification.
o Enable real-time video analysis with higher frame
rates.
Deployment:
Integrate the system into web or mobile applications for
broader accessibility.

24
BIBLIOGRAPHY

1) https://www.vedantu.com/
2) https://byjus.com/

3) https://www.wikipedia.org/

4) https://www.learncbse.in/

25

You might also like