This project is a Python-based object tracking system that detects and tracks multiple moving people (or objects) in a video using OpenCV. It leverages a simple but effective Centroid Tracking Algorithm to assign unique IDs and compute trajectories and speeds for each detected object.
- Background subtraction with MOG2
- Multi-object tracking with unique ID assignment
- Real-time trajectory plotting
- Speed estimation (in pixels/second)
- Automatic object removal if lost for too long
- Foreground Detection: Uses
cv2.createBackgroundSubtractorMOG2to detect moving objects. - Contour Detection: Filters out small blobs and calculates centroids.
- Tracking: Maintains a mapping between object IDs and their centroids using a simple distance-based assignment.
- Trajectory Drawing: Tracks the last 32 positions for each object and draws its path.
- Speed Calculation: Computes object speed using frame rate and Euclidean distance between centroids.
- Python 3.6+
- OpenCV
- NumPy
pip install opencv-python numpy
