This project demonstrates a simple method for detecting faces in video footage using Haar Cascades. The system assigns a unique ID to each detected face and tracks them across frames by calculating the Intersection over Union (IoU) between detected faces. The IDs are updated when faces move across the screen, and the system continues assigning new IDs to any new faces that appear in the frame.
- Haar Cascades for detecting faces and eyes.
- IoU (Intersection over Union) for re-identifying and tracking faces across video frames.
- Unique IDs assigned to each detected face, which are continuously updated based on their IoU with previous detections.
- OpenCV for video capture and object detection.
- NumPy for numerical operations.
-
Clone this repository and navigate to the project directory.
-
Install required dependencies by running:
pip install opencv-python-headless numpy
-
Update the video path:
- Make sure to specify the correct path to the input video file in the script
-
Run the Python script:
python inference.py
-
The script will display the video frames with rectangles drawn around each detected face, and a unique ID will be assigned to each face. These IDs will be updated for every frame and will persist as long as the face is detected.
-
Press 'Q' on the keyboard to stop the video playback and close the application.
The system displays each frame of the video with:
- Bounding boxes around detected faces.
- A unique ID above each face that persists through the frames as long as the face is visible.
- The system relies heavily on the accuracy of Haar Cascades for both face and eye detection, which may lead to occasional false positives or negatives.
- The IoU-based re-identification works well for tracking objects that move gradually, but may struggle in complex scenarios like occlusions or fast movements.
- IDs are reassigned based on visual similarity (IoU), but re-identification may not be perfect.
inference.py
: Main script for face detection and tracking using Haar Cascades and IoU.iou_utils.py
: Utility function for calculating the IoU between bounding boxes.requirements.txt
: List of dependencies.