Age & Gender Recognition using OpenCV DNN
This project uses OpenCV's deep learning module (DNN) to detect faces in video frames and predict the age and gender of individuals in real-time. The model utilizes pre-trained convolutional neural networks for accurate age and gender classification.
Introduction
The Age & Gender Recognition system is designed to detect faces and predict the age range and gender of individuals from video input. This project makes use of pre-trained models for face detection, age classification, and gender classification, enabling real-time predictions.
Features
- Real-time face detection in video.
- Age classification into predefined age groups.
- Gender classification (Male/Female).
- Supports both real-time video capture and video file input.
Requirements
-
Python 3.x
-
OpenCV
-
Pre-trained models for:
-Face detection
-Age prediction
-Gender prediction
Installation
-
Clone the repository:
git clone https://github.com/sanskarsri26/Age_gender_recognize.git cd Age_gender_recognize
-
Install dependencies:
Make sure you have OpenCV installed. You can install OpenCV using pip:
pip install opencv-python
- Download the pre-trained models:
Download the following model files and place them in your project directory:
--opencv_face_detector.pbtxt and opencv_face_detector_uint8.pb (for face detection)
--age_deploy.prototxt and age_net.caffemodel (for age prediction)
--gender_deploy.prototxt and gender_net.caffemodel (for gender prediction)
** Usage**
-
Running the Project
Run the Python script:
This script processes video input, detects faces, and predicts the age and gender of individuals.
python age_gender_recognition.py
- Input Video:
The script is set to read from a video file (4.mp4 in this case). You can change this to use your webcam or another video source.
To use the webcam, replace:
video = cv2.VideoCapture('4.mp4')
with:
video = cv2.VideoCapture(0)
Exiting:
Press q to quit the video processing window.
Explanation
Face Detection: Detects faces in each video frame using a pre-trained model.
Age Prediction: Predicts the age group of the detected faces based on the age_net.caffemodel.
Gender Prediction: Classifies gender as Male or Female using the gender_net.caffemodel.
The predicted age and gender are displayed as text labels over each detected face in the video feed.
Models
Ensure the following models are available in the root directory:
Face Detection:
opencv_face_detector.pbtxt
opencv_face_detector_uint8.pb
Age Detection:
age_deploy.prototxt
age_net.caffemodel
Gender Detection:
gender_deploy.prototxt
gender_net.caffemodel
The project uses OpenCV's DNN module to load these models and make predictions.