Skip to content

NandithKumar/Age-prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👤 Enhanced Real-time Age & Gender Detection

A real-time computer vision system that detects age range, gender, confidence scores, and edge density from live webcam feed or static images — built using OpenCV DNN with pre-trained Caffe models.

Python OpenCV DNN License


🎯 Live Demo Output

Real detections from webcam and static images:

📸 Webcam Detection

Demo 1 Demo 2 Demo 3
Demo 1 Demo 2 Demo 3
Male, 21–24 years · 100% conf Male, 21–24 years · 100% conf Male, 21–24 years · 100% conf

🖼️ Static Image Detection

Child Detection Senior Detection
Child Senior
Female, 4–6 years (Child) · 100% conf Male, 60+ years (Senior) · High Confidence

📌 Overview

The system runs a 3-stage DNN pipeline on every frame:

  1. Face Detection — SSD ResNet10 model detects faces with bounding boxes
  2. Age Classification — Classifies face into one of 9 age buckets
  3. Gender Classification — Predicts Male/Female with confidence score

Additionally computes edge density per face using Canny edge detection — a measure of facial texture detail.


✨ Features

Feature Details
🎥 Real-time webcam Live detection at 5–7 FPS
🖼️ Static image mode Detect from any image file
📹 Video file mode Process entire video files
🎯 Age classification 9 age buckets from infant to senior
👤 Gender detection Male/Female with confidence %
📊 Edge density Canny-based facial texture metric
💾 Screenshot save Press 's' to save any frame
🖥️ FPS counter Real-time frame rate display

🏗️ Project Structure

Age-Prediction/
├── app.py                      # Main entry point (CLI)
├── src/
│   ├── __init__.py
│   ├── detector.py             # Core DNN detection engine
│   ├── webcam.py               # Real-time webcam application
│   ├── image_predictor.py      # Static image predictor
│   ├── utils.py                # Edge density, labels, banner
│   └── download_models.py      # Auto model downloader
├── models/
│   ├── README.md               # Model download instructions
│   ├── deploy.prototxt         # Face detector config (download)
│   ├── age_deploy.prototxt     # Age model config (download)
│   └── gender_deploy.prototxt  # Gender model config (download)
├── outputs/
│   ├── demo_webcam_1.jpeg      # Real webcam output screenshot
│   ├── demo_webcam_2.jpeg
│   ├── demo_webcam_3.jpeg
│   ├── demo_image_child.jpeg   # Child detection result
│   └── demo_image_senior.jpeg  # Senior detection result
├── tests/
│   └── test_detector.py        # Unit tests
├── requirements.txt
├── .gitignore
└── README.md

⚙️ Setup & Installation

1. Clone the repo

git clone https://github.com/NandithKumar/Age-prediction.git
cd Age-prediction

2. Install dependencies

pip install -r requirements.txt

3. Download pre-trained models

python src/download_models.py

🚀 Usage

Live Webcam Detection

python app.py --mode webcam
  • Press s to save a screenshot
  • Press q to quit

Static Image Detection

python app.py --mode image --input path/to/image.jpg

Video File Detection

python app.py --mode video --input path/to/video.mp4 --output result.mp4

🧠 Detection Pipeline

Input Frame (Webcam / Image / Video)
          │
          ▼
  Face Detection (SSD ResNet10)
  → Bounding boxes + face confidence %
          │
          ▼
  Face Crop + Padding (20px)
          │
    ┌─────┴──────┐
    ▼            ▼
Age Net      Gender Net
(9 buckets)  (Male/Female)
    │            │
    └─────┬──────┘
          ▼
  Edge Density (Canny)
          │
          ▼
  Annotated Frame Output

📊 Age Buckets

Bucket Category
0–2 Infant
4–6 Child
8–12 Child
15–20 Teenager
21–24 Young Adult
25–32 Young Adult
38–43 Middle-Aged
48–53 Middle-Aged
60–100 Senior

🛠️ Tech Stack

Component Technology
Language Python 3.8+
Computer Vision OpenCV 4.7+
Deep Learning OpenCV DNN Module
Face Detection SSD ResNet10 (Caffe)
Age/Gender GilLevi Caffe Models
Edge Analysis Canny Edge Detection

🧪 Run Tests

python -m pytest tests/

👤 Author

Paladugu Nandith Kumar


📄 License

MIT License

About

Real-time age & gender detection system using OpenCV DNN with pre-trained Caffe models — supports webcam, image, and video modes

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages