Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👁️ Real-Time Face Detection System

Java + OpenCV | Haar Cascade Classifier

Detect human faces from static images and live webcam feeds in real time, with bounding boxes and a live face count.

Java OpenCV Maven Platform Status


📖 Overview

Face detection is a foundational building block of modern computer vision — powering everything from smart cameras to attendance systems. This project uses OpenCV's Haar Cascade Classifier, wired up in Java, to detect faces in two modes:

  • 🖼️ Image mode — scan a static photo and mark every face found
  • 🎥 Webcam mode — detect faces frame-by-frame from a live camera feed

Detected faces are outlined with green bounding boxes, and the total number of faces is shown live on screen.


✨ Features

  • ✅ Face detection in static images
  • ✅ Real-time face detection via webcam
  • ✅ Bounding boxes drawn around every detected face
  • ✅ Live on-screen face count
  • ✅ Clean, modular Java implementation (easy to extend)

🛠️ Tech Stack

Component Details
Language Java (JDK 11+)
Computer Vision OpenCV 4.1.2
Detection Model Haar Cascade Classifier (haarcascade_frontalface_default.xml)
Build Tool Maven
IDE VS Code (or any Java IDE)
OS Windows

📂 Project Structure

FaceDetection/
│
├── src/
│   ├── FaceDetectionImage.java      # Detects faces in a static image
│   └── FaceDetectionWebcam.java     # Detects faces from a live webcam feed
│
├── models/
│   └── haarcascade_frontalface_default.xml   # Pre-trained Haar Cascade model
│
├── images/
│   └── test.jpg                     # Sample test image
│
├── pom.xml                          # Maven build configuration
├── run.bat                          # Windows script to build/run the project
└── README.md

⚙️ Getting Started

Prerequisites

  • JDK 11 or higher — verify with:
    java -version
  • Maven installed and added to PATH
  • OpenCV 4.1.2 native library (opencv_java412.dll) if not resolved automatically via Maven — download from opencv.org/releases

Installation

# Clone the repository
git clone https://github.com/krushna1845/FaceDetection.git
cd FaceDetection

# Build the project with Maven
mvn clean install

The OpenCV dependency is pulled in automatically via pom.xml. If you hit a native library (UnsatisfiedLinkError) issue on Windows, add the OpenCV build/java/x64 folder to your system PATH and restart your IDE/terminal.


▶️ Usage

Option 1 — Run via run.bat (Windows, quickest)

run.bat

Option 2 — Run manually

Image face detection:

javac -cp ".;lib/opencv-4120.jar" src/FaceDetectionImage.java
java -cp ".;lib/opencv-4120.jar;src" FaceDetectionImage

Webcam face detection:

javac -cp ".;lib/opencv-4120.jar" src/FaceDetectionWebcam.java
java -cp ".;lib/opencv-4120.jar;src" FaceDetectionWebcam

Press ESC to close the webcam window.


🧠 How It Works

  1. OpenCV loads a frame — either from an image file or a webcam stream.
  2. The frame is converted to grayscale for faster, more accurate processing.
  3. The Haar Cascade Classifier scans the frame using pre-trained facial-feature patterns.
  4. Every detected face is outlined with a green rectangle.
  5. The live face count is calculated and rendered on screen in real time.

📸 Sample Output

  • Green bounding boxes drawn around every detected face
  • Live counter overlay:
    Faces Detected: 3
    

📌 Use Cases

  • 🔐 Security & surveillance systems
  • 🕒 Attendance and access-control systems
  • 🙋 Face-based authentication
  • 🤖 Human–computer interaction

🚀 Roadmap

  • Face recognition (identify who, not just detect a face)
  • Eye detection
  • Mask detection
  • Automated attendance system using face recognition
  • Emotion detection

🤝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

👤 Author

Krushna Malode GitHub: @krushna1845


⭐ Acknowledgements

  • OpenCV community & documentation
  • Java documentation

📜 License

This project is intended for educational purposes. Feel free to fork, learn from, and build on it.


If this project helped you, consider giving it a ⭐!

About

Real-time face detection in Java using OpenCV's Haar Cascade Classifier — detects faces from static images and live webcam feeds with bounding boxes and a live face count.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages