This project is a Python-based application that uses YOLOv5 for head detection and SORT tracking for object tracking. It provides a graphical user interface (GUI) built with Tkinter to load videos or start webcam-based detection, displays results in real-time, and sounds an alarm when certain thresholds are met.
Also has a mobile application (WIP)
-
YOLOv5 Model Integration: Detects heads of people in videos or via webcam using a pre-trained YOLOv5 model.
-
SORT Tracker: Tracks detected objects across frames for consistent identification.
-
Tkinter GUI: Easy-to-use interface with options to load videos, start webcam detection, and stop detection.
-
Alarm System: Plays an alert sound if the number of unique detections crosses a specified threshold.
-
Optimizations:
-
Detects in every 5th frame to reduce CPU load.
-
Loads the YOLO model in a separate thread to improve application responsiveness.
-
Alarm sound thread with a cooldown timer prevents overlapping alarms.
-
-
Visual Representation:
-
Usage of Bar and Line graph to visually represent the head count of the crowd per minute (can also implement per hour if needed).
-
The program counts the total number of people appeared in a minute and save the count in a dictionary, then the count is reset, and the next minute data is captured.
-
ROI (Region of Interest), where you could select a particular region in the video footage and the algo will focus on only the specified region.
-
Documentation: read this file for more detailed instructions on installation and use. (P.S., I would prefer you to read this first as it has more deep info!)
- Python 3.7 or above
Install the required libraries using the following command:
pip install -r requirements.txt
torch
opencv-python
Pillow
playsound
numpy
tkinter
sort
(Include thesort.py
file in the project directory)matplotlib
ttkbootstrap
git clone https://github.com/IDKSAM27/crowd-analyser
- Download or save an
alarm.mp3
file in the same directory as the script.
python head.py
- Open Video: Load a video file and start detection.
- Start Webcam: Start real-time head detection using the Webcam
- Stop Detection: Stop video/webcam detection.
- Display Minute Counts: Displays line and bar graph of the occured data.
- Select and Clear ROI: Enable user to select and clear Region of Interest.
- Track heads of people in the video or live feed.
- Displays the total nubmer of unique people and the number of people currently in the frame.
- Plays an alarm in the total count exceeds 60 unique detection (modifiable in the code).
Crowd_analysis/
├── head.py # Main application file
├── graph_display.py # Display graphs
├── alarm.mp3 # Alarm sound file (place in the same directory)
├── sort.py # SORT tracking algorithm file
├── requirements.txt
6801
# List of dependencies
├── Documentation.txt # Detailed Documentation
└── README.md # basic doc file
- The
sort.py
file is required for the tracking functionality. Ensure it's included in the same directory. - The application processes every 5th frame of the video by default to reduce CPU load. You can modify the
process_interval
in the code as needed. - If the alarm is not playing, verify the presence and path of
alarm.mp3
. - Always make sure to create 'virtual environment' before installing the requirements or libraries.
- Add support for real-time saving of detected outputs (e.g., save frames with bounding boxes).
- Introduce a configuration file to make parameters like thresholds, frame intervals, and alarm settings customizable.
- Extend detection to include other objects or classes with minimal changes.
This project is licensed under the MIT License.
- Ultralytics YOLOv5 for the object detection model.
- SORT Tracker for multi-object tracking.
- Community contributions for libraries like OpenCV, Tkinter, and PyTorch.
For questions, issues, or suggestions, feel free to open an issue or contact me.