Real-time face detection with FPS counter, timestamp overlay, and dynamic face-count styling.
This project is a clean, real-time face detection app built with OpenCV. It captures frames from your webcam, converts them to grayscale for efficient processing, detects faces using Haar Cascades, and overlays useful UI elements: a live face counter, timestamp, and a frames-per-second (FPS) indicator. Rectangle colors change dynamically based on the number of faces detected (🟩 green ≤ 2, 🟥 red ≥ 3) for instant visual feedback.
- Real-time webcam capture (VideoCapture)
- Haar Cascade face detection (
haarcascade_frontalface_default.xml
) - Dynamic rectangle color based on face count
- On-screen overlays: face count, timestamp, FPS
- Simple keyboard control: press
q
to quit
- Python 3.8+
- OpenCV (
opencv-python
)
- Python 3.8 or newer
- Webcam access
pip install opencv-python
The Haar Cascade file is resolved via OpenCV’s built-in path:
cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
python main.py
- q — Quit the app
- Black window / no camera: ensure your webcam is connected and not used by another app.
- Slow FPS: close other heavy apps; reduce
waitKey
delay or resize frames before processing. - No faces detected: check lighting, camera angle, and that the Haar Cascade path resolves correctly.
- 🎯 Add eye/Smile detection
- 🕶️ Fun overlays (sunglasses/emoji)
- 💾 Snapshot capture (
s
to save) - ⚙️ CLI flags for camera index and cascade params
Issues and PRs are welcome! Please open an issue to discuss major changes.