Skip to content

vicky60629/Face-Counting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘₯ Face Counting β€” Automated Head Count from Group Photos

Python Computer Vision OpenCV Flask Domain Stars

A computer vision application that automatically detects and counts the number of human faces in a group photo or selfie β€” built using deep learning-based object detection and deployed as a Flask web app.


πŸ“Œ Problem Statement

Manually counting people in photos is slow, error-prone, and impossible to scale. This project tackles the People Detection and Head Counting challenge β€” a classical yet demanding computer vision problem with real-world applications across crowd management, event safety, and retail analytics.

Given any group photo or selfie, the system:

  1. Detects all human faces in the image automatically
  2. Counts the total number of faces with a bounding box drawn around each
  3. Returns the final count instantly via a web interface

This project was built as part of a hackathon computer vision challenge β€” testing skills in deep learning and object detection.


🎯 Real-World Applications

Domain Use Case
Event Management Auto-count attendees from event photos
Retail Analytics Count footfall in store snapshots
Security & Surveillance Crowd density estimation in public spaces
Education Automated attendance tracking from classroom photos
Social Media Auto-tag count for group selfies
Public Safety Crowd control β€” detect overcrowding at venues

🧠 How It Works

The system uses deep learning-based face detection to locate every face in an image, regardless of size, angle, or lighting conditions:

Input Image (Group Photo / Selfie)
        ↓
  Face Detection Model
  (Deep Learning / OpenCV)
        ↓
  Bounding Boxes Drawn
  Around Each Face
        ↓
  Total Face Count Returned

The key challenge in head counting is detecting small, partially occluded, or tilted faces in dense group photos β€” a much harder problem than single-face detection.


πŸ—οΈ Project Architecture

Face-Counting/
β”œβ”€β”€ static/
β”‚   └── style.css                # Flask frontend styling
β”œβ”€β”€ templates/
β”‚   └── index.html               # Web app interface
β”œβ”€β”€ uploads/                     # Temporary storage for uploaded images
β”œβ”€β”€ Face Counting.ipynb          # Development & experimentation notebook
β”œβ”€β”€ app.py                       # Flask application (main entry point)
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ Procfile                     # Heroku deployment config
└── README.md

πŸ” Technical Approach

Face Detection Pipeline

Step 1 β€” Image Input

  • Accept image uploads via the Flask web interface
  • Support common formats: JPG, JPEG, PNG

Step 2 β€” Preprocessing

  • Resize image for optimal detection performance
  • Convert to appropriate colour space (RGB/BGR as required by the model)

Step 3 β€” Face Detection

  • Apply deep learning-based face detector to locate all faces
  • Each detected face returns a bounding box (x, y, width, height) with a confidence score
  • Filter detections by confidence threshold to reduce false positives

Step 4 β€” Annotation & Counting

  • Draw bounding boxes around each detected face
  • Count total number of valid detections
  • Return annotated image + count to the user

Why Deep Learning over Traditional Methods?

Approach Method Limitation
Traditional Haar Cascades (Viola-Jones) Poor on tilted, small, or occluded faces
Deep Learning βœ… CNN-based detector Handles varied poses, sizes, lighting

Deep learning-based detection significantly outperforms traditional Haar cascade methods, especially in dense group photos where faces may be small, partially covered, or at various angles.


πŸ› οΈ Tech Stack

Category Tools
Language Python 3.7+
Computer Vision OpenCV
Deep Learning DeepFace / CNN-based detection
Image Processing PIL / Pillow, NumPy
Web Framework Flask
Frontend HTML, CSS
Deployment Heroku β†’ Render
Notebook Jupyter Notebook

πŸš€ Running Locally

# Clone the repository
git clone https://github.com/vicky60629/Face-Counting.git
cd Face-Counting

# Install dependencies
pip install -r requirements.txt

# Run the Flask app
python app.py

Open http://localhost:5000 in your browser.


πŸ–₯️ How to Use the App

  1. Open the web app in your browser
  2. Upload a group photo or selfie (JPG/PNG)
  3. Click "Count Faces"
  4. View the annotated image with bounding boxes drawn around every detected face
  5. See the total face count displayed instantly

Example:

Input Output
Group selfie with 8 people βœ… 8 faces detected β€” bounding boxes drawn on each
Crowd photo with partial faces βœ… Detects even partially visible faces

πŸ“ˆ Key Challenges & How They Were Solved

Challenge Solution
Small faces in large group photos Deep learning model trained on varied scales
Partially occluded faces CNN features capture partial face patterns
Varied lighting conditions Preprocessing normalisation before detection
Multiple overlapping faces Non-Maximum Suppression (NMS) to avoid double-counting
Different face angles / poses Model trained on diverse multi-angle datasets

πŸ’‘ Key Learnings & Future Improvements

What worked well:

  • Deep learning-based detection significantly outperforms Haar cascades on group photos
  • Flask made it easy to wrap the CV pipeline into an accessible web app
  • Confidence threshold tuning was critical β€” too low causes false positives, too high misses small faces

Future enhancements:

  • Add real-time video stream face counting via webcam
  • Integrate YOLOv8 for faster, more accurate detection
  • Build a crowd density heatmap overlay to show where faces are clustered
  • Add age & gender estimation per detected face using DeepFace
  • Deploy on Render with a permanent live demo link
  • Extend to multi-frame video β€” count unique individuals across frames (de-duplicate repeated faces)
  • Add emotion detection overlay on each bounding box

πŸ”¬ Computer Vision Context

Face counting sits at the intersection of two active research areas:

Object Detection β€” locating and bounding instances of objects (here: faces) within images. Modern detectors like YOLO and RetinaNet achieve near-human accuracy on standard benchmarks.

Crowd Counting β€” estimating the number of people in dense scenes. Goes beyond simple detection β€” at extreme densities, individual face detection fails and density map estimation is used instead (e.g., CSRNet, MCNN). This project's approach works well for small-to-medium group sizes (2–50 people).


πŸ‘¨β€πŸ’» About the Author

Vicky Gupta β€” Data Engineering Analyst @ Accenture (4.5 years) | Aspiring Data Scientist

Passionate about computer vision, NLP, and building end-to-end ML systems. Experienced in PySpark, ETL pipelines, and deploying ML models from notebook to production.

πŸ”— LinkedIn | GitHub

πŸ“§ vg60629@gmail.com


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


⭐ Found this useful? Star the repository to help others discover it!

About

Face Counting

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors