Crowd Anomaly Detection
Crowd Anomaly Detection
2022-2026
BACHELOR OF TECHNOLOGY
in
CSE (DATA SCIENCE)
By
ADLA VIJWAL (22VE1A6701)
SHOURYA DHATRIKA (22VE1A6717)
NAINA GURRAM (22VE1A6725)
SRAVANTHI AAVULA (22VE1A6756)
This is to certify that the Major Project Report on “Crowd behavior and anomaly
detection” submitted by Adla Vijwal, Shourya Dhatrika, Naina Gurram, Sravanthi
Aavula bearing Hall ticket Numbers - 22VE1A6701, 22VE1A6717, 22VE1A6725,
22VE1A6756 in partial fulfillment of the requirements for the award of the degree of
Bachelor of Technology in CSE (DATA SCIENCE) from Sreyas institute of
engineering and technology, Bandlaguda, Hyderabad for the academic year 2022-2026 is a
record of bonafide work carried out by them under our guidance and supervision.
DECLARATION
ACKNOWLEDGEMENT
The successful completion of any task would be incomplete without mention
of the people who made it possible through their guidance and encouragement,
crowning all the efforts with success. We take this opportunity to acknowledge with
thanks and a deep gratitude to Dr. K Rohit Kumar, Head of the Department, Department
of CSE (Data Science), for his constant encouragement and valuable guidance during
the Project work.
We owe very much to the Department Faculty, Principal, and Management who
made my term at Sreyas a stepping stone for my career. We treasure every moment we
have spent in college. Last but not least, our heartiest gratitude to our parents and fellow
students for their continuous encouragement. Without their support, this work would not
have been possible.
ABSTRACT
In densely populated environments, detecting anomalous crowd behavior in real time is vital
for ensuring public safety and enabling rapid response to critical incidents. This project presents a
lightweight, real-time crowd anomaly detection system integrated with a dark-themed, interactive web
dashboard. Utilizing YOLOv4-tiny for efficient object detection and tracking, the backend processes
input video streams to identify unusual behaviors based on movement patterns and crowd density.
Detected anomalies are stored and visualized on the frontend, which includes a dynamic video player,
visual alerts, and a log of detected events.
The user interface allows dynamic video upload and playback, synchronizing anomaly alerts
with video timestamps. A modern, dark aesthetic improves user experience and focuses attention on
critical information. The system is designed to be lightweight enough to run on low-end GPUs, making
it suitable for deployment on cost-constrained devices such as surveillance systems in schools,
transportation hubs, and public venues.
Future expansions include viseme-based avatar reactions and integration with 3D web
visualization to provide a spatial understanding of anomalies. This project demonstrates the potential
for combining machine learning, computer vision, and web technologies to build effective, user-
friendly monitoring tools for real-world applications.
TABLE OF CONTENTS
1.2 Objective 1
1.3 Scope 2
1.4 Outline 2
Chapter-5 IMPLEMENTATION 13
FIGURES
LIST OF TABLES
1.1 Motivation
In today’s world, public safety has become a growing concern, especially in crowded environments
like train stations, festivals, protests, and sports arenas. Manual monitoring through CCTV is not only
labor-intensive but also prone to human error and delayed response times.
We were motivated to take on this project because we believe that integrating technology, particularly
AI and computer vision, into surveillance systems can make a real difference. By automatically
detecting abnormal behavior such as fighting, panic, or sudden crowd surges, our system aims to assist
security personnel with real-time alerts, enabling faster intervention and potentially preventing harm.
A tragic example is the Kumbh Mela stampede in 2025, where over 30 people lost their lives and
many were injured due to a sudden crowd surge. The root cause of such disasters often lies in delayed
responses, poor crowd management, and the inability to detect signs of panic, aggression, or abnormal
movement patterns in time.
Motivated by these challenges, we envisioned a real-time, AI-powered system that could proactively
detect signs of abnormal behavior such as sudden crowd surges, fights, or panic—before they escalate
into dangerous situations. The increasing incidents of violence in public places highlighted the need
for a proactive, automated solution, which inspired us to build a system that contributes to safer,
smarter public spaces.
1.2 Objective
The primary objective of our project is to develop a real-time system capable of detecting abnormal
crowd behavior, such as sudden movements, fights, or panic, by analyzing surveillance video footage.
Our goal is to enhance public safety during mass gatherings by generating immediate alerts when
potential threats or anomalies are detected, allowing authorities to respond swiftly and effectively.
Our goal is to assist human operators by reducing their monitoring burden and enhancing situational
awareness. With the right data and real-time insights, we believe that such a system could help save
lives during major events like religious festivals, political rallies, and concerts, making public spaces
safer and more secure.
● User-friendly dashboard that makes it easy to monitor multiple areas simultaneously from one
central system.
1
● Enhances personal safety during high-risk situations in places like festivals, rallies, train stations,
and public gatherings.
● Builds public trust in safety measures, encouraging greater participation in events and activities.
● Reduces the need for excessive physical infrastructure (e.g., barriers, excess staff) by relying on
smart surveillance, making crowd control more efficient and eco-friendly.
● Contributes to a safer public space ecosystem, particularly in densely populated or sensitive areas.
● Detect and track individuals in a crowd using computer vision techniques like YOLOv4-Tiny and
SORT.
● Analyze movement patterns to identify abnormal behavior, such as aggressive interactions or
sudden directional changes.
● Visualize crowd density and activity through real-time heatmaps and bar charts for better
situational awareness.
● Trigger audio alerts using pygame when an anomaly is detected, ensuring that security personnel
are promptly notified.
● Deliver a user-friendly interface through a clean, responsive web application using HTML5, CSS
(dark theme), and JavaScript, with a Python Flask backend for smooth data handling and logic
processing.
Through this system, we strive to reduce reliance on manual monitoring, minimize human error,
and ultimately prevent incidents like stampedes, violence, and mass panic during large-scale public
events.
1.3 Scope
This project focuses on building an AI-powered, real-time video surveillance system that detects and
responds to abnormal crowd behavior in public spaces. The system combines computer vision, object
tracking, and data visualization to improve safety and situational awareness during large-scale events
and gatherings.
● Detection of abnormal behavior such as Fights, sudden crowd surges, and panic movements.
● Real-time object detection and tracking using Computer Vision)
○ YOLOv4-Tiny for fast and accurate detection
○ SORT for efficient object tracking
● Live video feed analysis through CCTV or sample video files, or pre-recorded videos.
● Generates real-time alerts using audio notifications (via pygame).
● Provides crowd activity visualization through:
○ Dynamic heatmaps (showing density)
○ Bar charts (indicating movement/activity)
● User interface for monitoring, built with:
○ HTML5, CSS (dark theme), and JavaScript
○ Flask + Python backend for logic and control
2
This scope ensures a focused, technically feasible, and impactful system that can be deployed in real-
world scenarios to enhance public safety and reduce the risk of mass casualties.
1.4 Outline
Key Components:
1. YOLOv4-Tiny (Detection):
a. A fast and lightweight model for detecting people in each frame.
2. SORT (Tracking):
a. Assigns consistent IDs to people across frames for motion analysis.
3. Anomaly Detection Logic (anomaly_logic.py):
a. Detects sudden Movement (speed), Loitering (idle), and Proximity Violations
4. Alert System:
a. Sound Alert using pygame when anomalies are detected.
5. Flask Web Dashboard:
a. Real-time view of the video feed, Anomalies list, Heatmap visualization, Bar chart of
anomaly types
Steps Implemented:
Backend:
1. Set up YOLOv4-tiny for detection.
2. Integrated SORT for multi-object tracking.
3. Created anomaly logic module.
4. Generated and logged anomalies as JSON.
5. Added pygame sound alert for detection.
Frontend :
1. Designed a dark-themed dashboard.
2. Displayed anomaly list dynamically.
3. Rendered heatmap and bar charts with JS.
4. Used send_file and url_for() to serve static content properly.
CHAPTER 2
LITERATURE SURVEY
2.1 Introduction
Literature survey highlights relevant existing research, gaps, and how our project builds upon or
improves current solutions.
2.2 SURVEY
3
1. Real-Time Crowd Surveillance using Computer Vision
Numerous studies have explored using computer vision techniques to monitor and analyze crowd
behavior in public spaces. Systems like those proposed by Mehran et al. (2009) use optical flow and
social force models to understand crowd dynamics. However, such methods are often computationally
expensive and struggle with real-time performance in dense crowds.
Limitation: High processing time and limited scalability for real-time use in large-scale events.
The YOLO family of models has been widely adopted for real-time object detection. YOLOv4-Tiny,
in particular, offers a trade-off between speed and accuracy, making it suitable for lightweight edge
devices or systems requiring high frame rates.
SORT is a lightweight tracking algorithm that uses Kalman filters and Hungarian assignment to
maintain consistent tracking IDs. It performs well in moderate-density environments and is suitable for
systems requiring real-time performance.
Prior research, such as "Anomaly Detection in Crowded Scenes" by Adam et al. (2008) and newer
deep learning models like Conv-LSTM and Autoencoders, has explored anomaly detection. However,
deep models often require large datasets and long training times, making them unsuitable for practical
deployment without large-scale infrastructure.
Studies show that combining visual detection with audio alerts can significantly improve response time
in safety systems. Real-time notification through sound ensures that even distracted or busy staff are
alerted instantly.
Why We Use pygame: Easy integration with Python backend for quick alert triggering.
4
Modern surveillance systems often use interactive dashboards to display live footage, analytics, and
alerts. Technologies like Flask, HTML5, and JavaScript are widely adopted for creating such
interfaces, enabling cross-platform, real-time user access.
Why We Use It: Ensures smooth integration of video streams, alerts, and data visualization in one UI.
2.3 Conclusion
While several systems for crowd monitoring and anomaly detection exist, many suffer from either high
computational demand or a lack of real-time responsiveness. Our project fills this gap by combining
fast detection (YOLOv4-Tiny), efficient tracking (SORT), and simple yet effective anomaly detection
logic, all wrapped in a user-friendly Flask-based dashboard with audio alerts. This makes our system
both practical and deployable in real-world scenarios like the Kumbh Mela or railway stations.
CHAPTER 3
PROPOSED SYSTEM
Crowd behavior monitoring and anomaly detection have been critical research areas in computer
vision and public safety. Various systems have been developed using diverse technologies and
approaches. While existing systems offer diverse solutions for crowd monitoring, they often suffer
from trade-offs in real-time performance, accessibility, and complexity. Most enterprise systems are
costly and inflexible, while research tools demand large datasets and intensive computation.
5
require significant computational resources for processing. This makes them unsuitable for real-time
deployment on standard hardware or edge devices, especially in outdoor or resource-limited settings.
Our proposed system is designed to monitor crowded environments in real-time and automatically
detect unusual or dangerous behaviors such as sudden movements, loitering, or people getting too
6
close (which may indicate a fight or panic situation). It generates alerts instantly to help authorities
take quick action and prevent stampedes, violence, or other crowd-related disasters.
Functional requirements
7
○ Trigger an immediate sound alert using pygame if any anomaly is detected.
● Dashboard Features
○ Display live video feed with bounding boxes and IDs.
○ Show real-time anomaly list.
○ Generate and update a heatmap for crowd density.
○ Generate a bar chart showing the counts of each anomaly type
● Logging
○ Log all detected anomalies with timestamps for future review.
Non-Functional Requirements:
Software Interfaces
● YOLOv4-Tiny: For fast, real-time object detection.
● SORT: For assigning and maintaining object IDs.
● Flask: Backend server for handling video processing and frontend rendering.
● pygame: To generate alert sounds.
● HTML/CSS/JavaScript: For building the user interface.
● OpenCV: For video processing and frame handling.
Hardware requirements
Since our project involves real-time performance, tuning, and testing different scenarios (e.g., festivals,
crowds, abnormal behavior), Agile or Iterative methodology will offer the flexibility and testing cycles
you need.
The iterative model focuses on building an initial version, then repeatedly refining it through cycles.
8
The iterative model involves building the basic version of the system first, then refining and expanding
it in multiple versions or cycles.
The system is designed to detect, track, and analyze crowd behavior in real-time. The following are the
core functionalities the system must perform:
9
5. Live Video Feed on Web Interface
○ Stream annotated video in real-time through a Flask-based dashboard
○ Show live detection and tracking overlays (bounding boxes + IDs).
6. Anomaly Visualization Dashboard
○ Provide a user-friendly, dark-themed web interface displaying:
i. Live video feed
ii. Real-time anomaly list
iii. Heatmap showing crowd density
iv. Bar chart showing frequency/type of anomalies
7. Data Logging
○ Record detected anomalies (type, timestamp, location) in JSON or CSV format.
○ Support offline analysis and system evaluation.
8. Support for Multiple Video Sources
○ Accept video input from webcams, video files, and CCTV\IP Cameras
CHAPTER 4
SYSTEM DESIGN
4.1 Importance of Design
Design is a critical phase in software development that defines how the system will look, behave, and
function. In our project, good design ensures performance, accuracy, and user experience. System
design is a crucial phase in software development where the architecture and components of the system
are defined. It bridges the gap between requirement analysis and implementation, ensuring the
application is scalable, reliable, and maintainable.
System design is critically important in software development and engineering because it lays the
foundation for building reliable, scalable, and efficient systems. Here are the main reasons why system
design is important:
10
A clean, dark-themed dashboard improves user experience.
Real-time video, heatmaps, and bar charts make monitoring intuitive.
5. Security and Stability
A structured design reduces the risk of system crashes.
Ensures reliable monitoring even during high crowd density.
In our project, good design ensures seamless integration of real-time detection, tracking, and alert
systems.
The crowd behaviour and anomaly detection consists of the following major components:
11
1. Input source:
a. Captures live video from a webcam, video file, or surveillance camera.
b. Acts as a primary data source for crowd monitoring.
2. Human Detection(YOLOv4-Tiny):
a. YOLOv4-Tiny is a lightweight, fast object detection model.
b. Role: Detects all people in each frame of the video.
c. Output: Bounding boxes and confidence scores for each detected person.
3. Object Tracking (SORT):
a. We use a tool, SORT (Simple Online Real Time Tracker)
b. Role: Assigns a unique ID to each detected person and tracks their movement across frames.
c. Benefit: Enables tracking of individual behavior over time.
4. Anomaly Detection Logic
a. Logic Rules:
i. Sudden Movement / Running: Detected by high speed.
ii. Loitering: Staying in the same area for too long.
iii. Proximity Violation: People standing too close or forming dense clusters.
b. Output: Flags suspicious or unsafe behavior.
5. Alert System (Audio Alerts)
a. Technology Used: pygame
b. Trigger: When an anomaly is detected.
c. Effect: Plays a warning sound to notify authorities/security.
6. Frontend: Real-Time Web Dashboard
a. Technologies: HTML5, CSS (Dark Mode), JavaScript
b. Features:
i. Displays Live Video Feed with boxes and person IDs.
ii. Lists anomalies with timestamps.
iii. Shows a Heatmap of crowd density.
iv. Displays Bar Charts for anomaly types.
7. Data Logging & Export (Optional)
a. Purpose: Saves anomaly events in JSON or CSV format.
b. Use Case: For future analysis, audit, or training models.
12
4.3.2 Class Diagram
Purpose: Describes classes, their attributes, and relationships
Key Classes:
● Detector: Loads YOLO model and detects people.
● Tracker: Manages SORT tracking and person IDs.
● AnomalyDetector: Contains logic for movement, loitering, and proximity.
● AlertManager: Triggers audio alerts.
● Visualizer: Handles heatmaps and bar chart rendering.
13
CHAPTER 5
IMPLEMENTATION
Here’s a structured explanation of the implementation of your Crowd Behavior and Anomaly Detection
System, broken down module by module:
14
2. n
5. Alert System(alert.py):
○ If an anomaly is detected:
i. Play a warning sound using pygame.
ii. Data is logged into a JSON or CSV file for records.
anomaly_detect.py
for det in detections:
15
if track_id not in track_history:
track_history[track_id] = []
track_history[track_id].append((cx, cy))
track_history[track_id] = track_history[track_id][-HISTORY_LENGTH:]
# Speed-based anomaly
if len(track_history[track_id]) >= 2:
speed = euclidean(track_history[track_id][-1],
track_history[track_id][-2])
anomalies.append({
'id': track_id,
'type': 'sudden_movement',
'speed': speed
})
# Loitering-based anomaly
if len(track_history[track_id]) == HISTORY_LENGTH:
total_dist = sum(
16
euclidean(track_history[track_id][i], track_history[track_id][i
+ 1])
for i in range(HISTORY_LENGTH - 1)
anomalies.append({
'id': track_id,
'type': 'loitering',
'distance': total_dist
})
return anomalies
track_people.py
ids.append(track_id)
track_history[track_id] = deque(maxlen=MAX_HISTORY)
track_history[track_id].append(centroid)
17
# Speed Anomaly
if track_id in prev_centroids:
old_centroid = prev_centroids[track_id]
anomalies.append({
"type": "speed",
"frame": int(frame_count),
"id": int(track_id),
})
else:
else:
# Idle Anomaly
anomalies.append({
18
"type": "idle",
"frame": int(frame_count),
"id": int(track_id),
})
# Turn Anomaly
if len(track_history[track_id]) >= 3:
mid_idx = len(track_history[track_id]) // 2
angle = calculate_angle(track_history[track_id][0],
track_history[track_id][mid_idx], centroid)
anomalies.append({
"type": "sudden_turn",
"frame": int(frame_count),
"id": int(track_id),
})
prev_centroids[track_id] = centroid
19
# Proximity anomaly
for i in range(len(ids)):
anomalies.append({
"type": "close_proximity",
"frame": int(frame_count),
})
20
CHAPTER 6
TESTING
6.1 Importance of Testing
Software testing plays a crucial role in ensuring the quality, reliability, and stability of a system. For a
smart finance tracking application that handles sensitive financial data, effective testing guarantees that
users receive accurate, secure, and consistent service. Testing helps:
● Detection is accurate.
● Alerts are reliable.
● Visuals update correctly.
● The system handles real-time inputs smoothly.
21
1. Unit Testing:
● Purpose: To test individual components or functions in isolation.
● Examples: Testing the YOLO detection output (bounding boxes).
○ Verifying that anomaly_logic.py correctly flags sudden movement or loitering.
○ Testing the alert system by manually triggering an anomaly.
2. Integration testing:
● Purpose: To test the interaction between modules.
● Examples:
■ Ensure YOLOv4-Tiny outputs feed properly into SORT for tracking.
■ Confirm that detected anomalies trigger sound alerts and update the frontend.
■ Verify Flask correctly streams video and updates the dashboard in real time.
3. Functional Testing:
● Purpose: To validate that the system functions match the requirements.
● Examples:
■ Detect and track multiple people correctly
■ Generate and display heatmaps and bar charts.
■ Send alerts when a loitering or proximity violation occurs.
4. System Testing
● Purpose: To test the complete integrated system as a whole.
● Examples:
○ Running the entire system on a video feed to monitor end-to-end flow from input to
dashboard.
○ Observing how many frames per second it can handle.
○ Ensuring all components (YOLO, SORT, alerts, Flask) work seamlessly.
22
6.3 Test Cases
23
CHAPTER 7
OUTPUT SCREENSHOTS
24
Fig 7.2 Upload file
25
Figure 7.4 Detecting objects
26
Fig 7.6: Generates detected anomalies.
27
CHAPTER 8
FUTURE SCOPE
28
a. The system will be designed to handle multiple camera feeds simultaneously, making it ideal
for large-scale public events or infrastructure like metro stations and stadiums.
CHAPTER 9
CONCLUSION
The Crowd Behavior and Anomaly Detection System successfully demonstrates the potential of
integrating computer vision and real-time analytics to enhance public safety and crowd management. By
utilizing technologies like YOLOv4-Tiny for human detection, SORT for tracking, and custom anomaly
detection logic, the system can effectively identify suspicious behaviors such as sudden movements,
loitering, and proximity violations.
The implementation of real-time video feed analysis, visual dashboards, and audio alerts provides a
proactive approach to detect and respond to potentially dangerous situations. This is especially relevant
in crowded events such as religious festivals, public gatherings, and transportation hubs, where timely
intervention can prevent disasters like stampedes or violence.
The system is lightweight, cost-effective, and designed to run on standard hardware, making it
accessible for deployment in various real-world scenarios. With future enhancements like SMS alerts,
CCTV integration, and dynamic dashboards, the system holds strong potential for broader adoption and
societal impact.
In conclusion, this project not only addresses a critical public safety need but also sets the foundation for
smarter, AI-driven crowd monitoring solutions.
29
CHAPTER 10
REFERENCES
● A. Bochkovskiy, C.-Y. Wang, and H.-Y. M. Liao, "YOLOv4: Optimal Speed and Accuracy of
Object Detection" (2020)Source: arXiv preprint, arXiv:2004.10934, 2020.
○ Link: arXiv:2004.10934
○ Objective: To optimize the speed and accuracy of the YOLO (You Only Look Once) object
detection framework for real-time applications.
○ Key Contributions: YOLOv4 introduces improvements in accuracy and speed by using
enhanced backbones and better data augmentation techniques.
○ Applications: Real-time video analysis, surveillance, autonomous systems.
● B.Zhou, X. Tang, and X. Wang, "Learning collective crowd behaviors with dynamic pedestrian-
agents" (2015)
○ Source: International Journal of Computer Vision, vol. 111, no. 1, pp. 50–68, Jan. 2015.
○ DOI: 10.1007/s11263-014-0787-9
○ Objective:
○ To model and predict collective behaviors in crowds by simulating pedestrians as dynamic
agents.
○ Key Contributions:
■ A framework that learns and predicts crowd movement patterns through dynamic
agents.
■ Uses machine learning to capture pedestrian interactions and global crowd patterns.
■ Applications: Crowd behavior prediction, safety, event management.
● OpenCV Library – Open Source Computer Vision Library.
○ A widely-used open-source library for real-time computer vision, used in our system for
image processing and video stream manipulation.
https://opencv.org
30
● YOLOv4-Tiny GitHub Repository
○ Contains the official implementation of YOLOv4-Tiny, a fast and efficient object detection
model ideal for edge devices and real-time scenarios.
https://github.com/AlexeyAB/darknet
● Pygame
○ A Python library used in our project to generate audio alerts whenever an anomaly is
detected, improving response time in crowded environments.
https://www.pygame.org
31