Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views39 pages

Crowd Anomaly Detection

The document is a project report on 'Crowd Behavior and Anomaly Detection' submitted by students of Sreyas Institute of Engineering and Technology for their Bachelor of Technology degree in CSE (Data Science). It outlines the project's objectives, which include developing a real-time system to detect abnormal crowd behavior using computer vision techniques, and discusses its implementation, including a user-friendly web dashboard. The report also highlights the importance of the project in enhancing public safety during mass gatherings by providing timely alerts to security personnel.

Uploaded by

Ananya Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views39 pages

Crowd Anomaly Detection

The document is a project report on 'Crowd Behavior and Anomaly Detection' submitted by students of Sreyas Institute of Engineering and Technology for their Bachelor of Technology degree in CSE (Data Science). It outlines the project's objectives, which include developing a real-time system to detect abnormal crowd behavior using computer vision techniques, and discusses its implementation, including a user-friendly web dashboard. The report also highlights the importance of the project in enhancing public safety during mass gatherings by providing timely alerts to security personnel.

Uploaded by

Ananya Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

CROWD ANOMALY DETECTION

Industrial-oriented Mini Project Report Submitted to

SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY


(Affiliated to JNTUH, Approved by A.I.C.T.E and Accredited by NAAC, New Delhi)
Bandlaguda Beside Indu Aranya, Nagole, Hyderabad-500068,Ranga Reddy Dist.

2022-2026

In partial fulfillment of the requirements for the

Award of the degree of

BACHELOR OF TECHNOLOGY
in
CSE (DATA SCIENCE)
By
ADLA VIJWAL (22VE1A6701)
SHOURYA DHATRIKA (22VE1A6717)
NAINA GURRAM (22VE1A6725)
SRAVANTHI AAVULA (22VE1A6756)

Under the Guidance


of
Dr.K.ROHIT KUMAR
Head of the department
of
CSE(Data Science)
SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF CSE (DATASCIENCE)
CERTIFICATE

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.

Internal Guide Project Coordinator


Dr.K.Rohit Kumar Mrs.D.Chaitanya
Head of the Department Assistant Professor

Head of the Department External Examiner


Dr.K.Rohit Kumar
SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF CSE (DATASCIENCE)

DECLARATION

We baring Hall ticket Nos - 22VE1A67A01, 22VE1A6717, 22VE1A6725,


22VE1A6756 hereby declare that the Crowd behaviour and anomaly detection
system by us under the guidance of Dr.K.Rohit Kumar Head of the Department
which is submitted in the partial fulfillment of the requirement for the award of the
B. Tech degree in CSE(Data Science) at Sreyas Institute of Engineering &
Technology, Bandlaguda, Hyderabad is our original work.

ADLA VIJWAL 22VE1A6701


SHOURYA DHATRIKA 22VE1A6717
NAINA GURRAM 22VE1A6725
SRAVANTHI AAVULA 22VE1A6756

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.

A Special vote of Thanks to Mrs.D.Chaitanya, Project Coordinator, and Dr. K.


Rohit Kumar, Head of the Department, who has been a source of Continuous motivation
and support. They had taken time and effort to guide and correct me throughout this
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.

ADLA VIJWAL 22VE1A6701


SHOURYA DHATRIKA 22VE1A6717
NAINA GURRAM 22VE1A6725
SRAVANTHI AAVULA 22VE1A6756

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

Chapter Title Page No.


Chapter-1 INTRODUCTION 1
1.1 Motivation 1

1.2 Objective 1

1.3 Scope 2

1.4 Outline 2

Chapter-2 LITERATURE SURVEY 3

Chapter-3 PROPOSED SYSTEM 6

3.1 Existing System 6

3.2 Proposed System 6

3.3 Software Requirement 7


Specification

3.4 SDLC Methodologies 8

3.5 Functional Requirements 8

Chapter-4 SYSTEM DESIGN 10

4.1 Importance of Design 10

4.2 System Architecture 10

4.3 UML Diagrams 11

4.3.1 Sequence Diagram 11

4.3.2 Class Diagram 12

Chapter-5 IMPLEMENTATION 13

5.1 Module Description 13

5.2 Sample Code 14


LIST Chapter Title Page No.
OF Chapter-6 TESTING 24
6.1 Importance of Testing 24
6.2 Types of Testing 24
6.3 Test Cases 25
Chapter-7 OUTPUT SCREENSHOTS 26
Chapter-8 FUTURE SCOPE 32
Chapter-9 CONCLUSION 33
Chapter-10 REFERENCES 34

FIGURES

Fig. No. Name of Figure Page No.


4.1 System Architecture 10
4.2 Sequence Diagram 11
4.3 Class Diagram 12

Table No. Name of Table Page No.


6.3 Test Cases Table 25

LIST OF TABLES

LIST OF TEST CASE SCREENSHOTS


Fig. No Name of Figure Page No.
7.1 Front end 26
7.2 Upload a file 26
7.3 Upload a sample video 27
7.4 Detecting objects 27
7.5 Tracking objects 28
7.6 Generates detected anomalies 28
7.7 Generates detected anomalies 29
CHAPTER - 1
INTRODUCTION

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.

By developing this project, we ensure

● 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.

To achieve this, we aim to:

● 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.

The scope of the project includes features like:

● 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.

2. Object Detection with YOLO (You Only Look Once)

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.

Advantage: Fast and efficient detection of people in live video feeds.


Why We Use It: Enables real-time monitoring even on low-resource systems.

3. Tracking with SORT (Simple Online and Realtime Tracker)

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.

Advantage: Provides reliable tracking with minimal computational overhead.


Why We Use It: Ensures consistent person tracking across frames for behavior analysis.

4. Anomaly Detection in Crowds

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.

Limitation: High complexity and poor real-time performance without GPUs.


Our Approach: Uses logic-based detection (sudden speed, loitering, proximity) that is efficient and
adaptable.

5. Audio-Visual Alert Systems

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.

6. Web-Based Monitoring Dashboards

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

3.1 Existing 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.

Limitations of existing systems:

1. High Computational Requirements


Many existing models, particularly those based on optical flow, social force models, or deep learning,

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.

2. Lack of Real-Time Responsiveness


Several systems operate in batch or offline mode, analyzing footage post-event rather than identifying
anomalies as they happen. This delay in detection renders them ineffective for immediate crowd
control or emergency response.

3. Poor Individual Behavior Detection


Traditional crowd analysis tools often focus on global patterns (e.g., flow or density) but fail to capture
individual behaviors such as loitering, sudden aggression, or proximity violations, which are early
indicators of potential violence or panic.

4. Over-Reliance on Large Datasets


Deep learning-based anomaly detection systems require extensive training data to learn what
constitutes "normal" and "abnormal" behavior. Acquiring large, annotated datasets, particularly of rare
events like stampedes or fights, is both costly and time-consuming.

5. Cost and Accessibility Constraints


Commercial surveillance systems are often expensive, requiring specialized hardware, paid licenses,
and maintenance. These factors make them inaccessible to smaller institutions, public gatherings, or
developing regions.

6. Limited Customization and Flexibility


Proprietary systems offer little room for customization. Users cannot modify detection logic, integrate
additional features, or adapt the system to specific event types without vendor support.

7.No Integrated Alert Mechanism


Many research-based or basic systems lack real-time alerting mechanisms (like sound, notifications, or
dashboards), making them ineffective in preventing incidents before escalation.

8. Lack of User-Friendly Visualization


Most systems do not offer interactive dashboards with real-time video, heatmaps, or analytics. This
makes it harder for human operators to interpret system outputs quickly and take informed decisions.
Our project solves these issues by using simple and fast technologies to create an efficient, real-time
alert system for crowd safety.

3.2 Proposed System

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.

Features of the proposed system:

1. Real-Time Human Detection


a. We use YOLOv4-Tiny, a fast model that detects people in every video frame.
b. It's optimized to run quickly, even on low-power devices like laptops.
2. Tracking People in the Crowd
a. SORT tracks each person across video frames by giving them a unique ID.
b. This helps us follow their movements and detect any unusual behavior.
3. Anomaly Detection
a. We have special rules to spot:
i. Sudden Running or Fast Movement (which could indicate panic or aggression).
ii. Loitering (people standing still for too long in one spot).
iii. Proximity Violation (when people get too close or form a crowd).
iv. These behaviors are detected by tracking speed and position.
4. Instant Alerts
a. If abnormal behavior is detected, the system sends an immediate sound alert using pygame.
b. This helps security teams take quick action.
5. Easy-to-Use Web Dashboard
a. The system has a simple, dark-themed Flask dashboard that shows
i. Live video with detected people and their IDs.
ii. A list of any detected anomalies.
iii. A heatmap showing where crowds are forming.
-A bar chart showing types of anomalies (e.g., loitering, running).
iv. Light and Affordable
The system uses open-source tools, so it doesn't require expensive hardware or cloud services.
It can run on normal computers, making it affordable and easy to set up.

3.3 Software Requirement Specification

Functional requirements

These define what the system should do:


● Detect People in Real Time
○ Detect human presence in each frame using YOLOv4-Tiny.
● Track Each Person
○ Assign unique IDs to detected individuals and track them using SORT.
● Analyze Behavior
○ Detect anomalies like sudden Movement (e.g., running)
■ Loitering (standing in one place too long)
■ Proximity Violation (getting too close to others)
● Alert Mechanism

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:

These define how well the system should perform:

1. Performance: The system should process video frames at real-time speed (≤


500ms/frame).
2. Reliability: The system should be stable and alert accurately with minimal false positives.
3. Usability: The dashboard must be intuitive, easy to navigate, and visually clear.
4. Portability: The system should run on standard laptops and can be adapted for low-power devices.
5. Security: Access to the dashboard should be limited to authorized users.
6. Maintainability: Code should be modular and well-documented to allow future updates or
extensions.
7. Scalability: Can be scaled to support multiple camera feeds with minor changes.
8. Cost-Effective: Should use open-source tools and no expensive hardware.

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

● Laptop: 8GB RAM Intel(R) Core(TM) i7-5500U CPU


● GPU: GeForce 840M

3.4 SDLC Methodologies

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.

Build the system in versions (iterations), improving with each cycle.

Iteration 1 – Basic video input + YOLOv4 detection setup.

Iteration 2 – Add multi-person tracking with SORT.

Iteration 3 – Introduce basic anomaly detection (e.g., sudden movement).

Iteration 4 – Expand logic to include loitering and proximity checks.

Iteration 5 – Add sound alert feature.

Iteration 6 – Develop the web dashboard for visualization.

Iteration 7 – Final refinement of UI and system performance.

Each version is testable and expandable, allowing gradual improvements.

3.5 Functional requirements

The system is designed to detect, track, and analyze crowd behavior in real-time. The following are the
core functionalities the system must perform:

1. Real-Time Human Detection:


○ Detects people in every video frame using YOLOv4-Tiny, a lightweight and fast object
detection model. Draw bounding boxes around detected individuals.
2. Multi-Person Tracking
○ Assign a unique ID to each person using SORT (Simple Online Realtime Tracker).
○ Track each person’s movement across consecutive video frames.
3. Anomaly Detection
○ Analyze tracking data to identify unusual behavior, such as:
i. Sudden Running or Rapid Movement (possible panic/aggression)
ii. Loitering (staying too long in one place)
iii. Proximity Violations (excessively close crowd formations)
4. Instant Alert System
○ Generate sound alerts using Pygame when an anomaly is detected.
○ Enable immediate awareness for security or monitoring staff.

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:

1. Clear System Architecture


Defines the interaction between modules like detection, tracking, anomaly logic, and the dashboard.
2. Modularity and Scalability
Each feature is built as a separate module (e.g., detection, tracking, alerts).
New features like facial detection or area-based alerts can be added easily in the future.
3. High Accuracy and Real-Time Efficiency
Design decisions such as using YOLOv4-Tiny and SORT optimize for real-time performance.
4. User-Friendly Interface

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.

4.2 System Architecture

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.

4.3 UML Diagrams:

4.3.1 Sequence Diagram

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:

1. Video Input Capture(cv2.VideoCapture):


○ The system captures video from a live webcam or pre-recorded videos.
○ Frames are read using OpenCV.

14
2. n

3. Object Tracking – SORT (Simple Online Real Time Tracker)[sort.py, tracker.py]


○ YOLO detections are passed into SORT for tracking.
○ SORT assigns unique IDs to each person and tracks their location over time.
○ Helps maintain the identity of individuals across frames.

4. Anomaly Detection Logic(anomaly_logic.py):


○ Custom Python module analyzes movement history.
○ Three types of anomalies were detected:
i. Sudden Movement: Rapid speed over a short time.
ii. Loitering: A Person standing idle in the same spot for too long.
iii. Proximity Violation: People are too close together.
iv. Each anomaly type is logged with a timestamp and ID.

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.

6. Frontend – HTML, CSS, JS:


○ Dark-themed dashboard created with HTML5, CSS, and JS.
○ Displays:
i. Live video feed with bounding boxes and IDs.
ii. Real-time anomaly list.
iii. Heatmap showing crowded zones.
iv. Bar chart for anomaly statistics.

7. Logging and Data Storage:


○ Anomalies are logged in structured formats (JSON/CSV).
○ Useful for auditing or further machine learning.

5.2 Sample Code

anomaly_detect.py
for det in detections:

x1, y1, x2, y2, track_id = det

cx, cy = (x1 + x2) / 2, (y1 + y2) / 2

15
if track_id not in track_history:

track_history[track_id] = []

track_history[track_id].append((cx, cy))

# Limit history length

if len(track_history[track_id]) > HISTORY_LENGTH:

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])

if speed > SPEED_THRESHOLD:

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)

if total_dist < LOITERING_THRESHOLD:

anomalies.append({

'id': track_id,

'type': 'loitering',

'distance': total_dist

})

return anomalies

track_people.py

for track in tracks:

x1, y1, x2, y2, track_id = track.astype(int)

ids.append(track_id)

centroid = get_centroid((x1, y1, x2, y2))

# Track centroid history

if track_id not in track_history:

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]

speed = euclidean(old_centroid, centroid)

if speed > SPEED_THRESHOLD:

anomalies.append({

"type": "speed",

"frame": int(frame_count),

"id": int(track_id),

"bbox": [int(x1), int(y1), int(x2), int(y2)]

})

cv2.putText(frame, "SPEED", (x1, y1 - 10),


cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2)

cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 255), 2)

else:

cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)

else:

cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 255, 0), 1)

# Idle Anomaly

if len(track_history[track_id]) >= IDLE_FRAMES:

dist = euclidean(track_history[track_id][0], centroid)

if dist < IDLE_THRESHOLD:

anomalies.append({

18
"type": "idle",

"frame": int(frame_count),

"id": int(track_id),

"bbox": [int(x1), int(y1), int(x2), int(y2)]

})

cv2.putText(frame, "IDLE", (x1, y2 + 15),


cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 200, 0), 2)

# 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)

if angle > ANGLE_CHANGE_THRESHOLD:

anomalies.append({

"type": "sudden_turn",

"frame": int(frame_count),

"id": int(track_id),

"bbox": [int(x1), int(y1), int(x2), int(y2)]

})

cv2.putText(frame, "TURN", (x1, y2 + 30),


cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 100, 100), 2)

prev_centroids[track_id] = centroid

19
# Proximity anomaly

for i in range(len(ids)):

for j in range(i + 1, len(ids)):

id1, id2 = ids[i], ids[j]

if id1 in prev_centroids and id2 in prev_centroids:

dist = euclidean(prev_centroids[id1], prev_centroids[id2])

if dist < PROXIMITY_THRESHOLD:

anomalies.append({

"type": "close_proximity",

"frame": int(frame_count),

"id_pair": [int(id1), int(id2)],

"distance": float(round(dist, 2))

})

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:

1. Identify and fix bugs or logic errors before deployment.


2. Ensure each component functions as intended in isolation (unit testing) and combination (integration
testing).
3. Enhance user experience by validating that user interfaces behave as expected across browsers and
devices.
4. Prevent potential vulnerabilities in authentication, data manipulation, and account access.
5. Improve overall system performance by identifying performance bottlenecks early.

Testing in your project ensures that:

● Detection is accurate.
● Alerts are reliable.
● Visuals update correctly.
● The system handles real-time inputs smoothly.

6.2 Types of testing

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.

5. User Interface Testing


● Purpose: To test the frontend's usability, responsiveness, and accuracy.
● Examples:
○ The dashboard displays correct bounding boxes and IDs.
○ Anomalies appear in real-time on the list.
○ Heatmaps update without page refresh.
6. Performance Testing
● Purpose: To check system responsiveness and stability under load.
● Examples:
○ How does it perform with videos of larger crowds?
○ Frame rate drop or memory usage with long-duration video.
○ CPU/GPU load when multiple people are detected.
7. Stress and Exception Testing
● Purpose: To test the system's behavior in unexpected or extreme conditions.
● Examples:
○ What happens if the video feed fails?
○ How does the system behave with corrupted input?
○ Can it recover gracefully from tracking loss?

22
6.3 Test Cases

23
CHAPTER 7
OUTPUT SCREENSHOTS

Fig 7.1 Front end

24
Fig 7.2 Upload file

Fig 7.3. Uploaded a sample video.

25
Figure 7.4 Detecting objects

Fig 7.5 Tracking objects

26
Fig 7.6: Generates detected anomalies.

Fig 7.7: Generates detected anomalies.

27
CHAPTER 8
FUTURE SCOPE

1. Dynamic Input & CCTV Integration:


a. The system can be extended to support real-time dynamic inputs from live CCTV footage
across multiple public or private locations.
b. This will allow automated, city-wide anomaly monitoring in real-world environments like
streets, malls, and religious gatherings.

2. Heatmaps and Charts on the Dashboard:


a. In future updates, the project will include advanced dashboards that visually represent crowd
behavior using:
i. Live heatmaps to show areas of high density
ii. Interactive bar and pie charts to display anomaly distribution
This will help security personnel and analysts easily interpret crowd patterns and trends over time.

3. SMS Alert Notifications:


a. Instead of only audio alerts, the system will be enhanced to send real-time SMS notifications
to security officials or emergency responders when abnormal behavior is detected.
b. This ensures faster communication and more effective incident response, especially in large
or noisy environments.

4. Scalability to Multiple Cameras:

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.

5. Cloud Integration for Centralized Monitoring:


a. A cloud-based control panel can be introduced to remotely monitor anomalies from various
locations and store long-term data for analysis.

6. Mobile Application Support:


a. A companion mobile app could allow guards or staff to view the live feed, receive alerts, and
mark responses directly from their smartphones.

7. Predictive Crowd Analysis:


a. In future versions, AI models can be trained to predict possible high-risk situations like
stampedes or riots based on crowd flow and behavior history.

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

You might also like