The Crowd Detection System is a real-time, AI-powered solution designed to detect, analyze, and monitor crowd activity using computer vision techniques. Leveraging the YOLO (You Only Look Once) deep learning model, it processes video frames to identify people, track their movement, and detect anomalies in crowd behavior. The system includes a Python-based backend for analytics and a React web frontend for visualization.
- Real-Time Crowd Detection: Uses YOLOv8 for detecting and counting people in video frames.
- Movement Analysis: Tracks individual movement and calculates overall velocity (RMS) within the crowd.
- Anomaly Detection: Monitors crowd and velocity metrics to identify unusual activity using adaptive statistics and linear regression.
- WebSocket Communication: Enables live data and video streaming between client, server, and web UI.
- User Interface: React-based frontend for displaying real-time crowd statistics and alerts.
crowd-detection/
├── client/
│ └── client.py # Python script to send video frames to the server via WebSocket.
├── server/
│ ├── server.py # Main backend logic for frame processing, detection, and anomaly analytics.
│ └── anomaly_monitor.py # Utility for adaptive anomaly scoring and detection.
├── react-app/
│ ├── public/
│ │ └── index.html # Web UI template.
│ ├── src/ # React components and assets (not shown here).
│ └── README.md # React app setup instructions.
└── README.md # (You are here!)
- The client captures frames from a video source (e.g., file, camera).
- Frames are compressed and sent to the server using WebSockets.
- The server uses YOLOv8 to detect people in each frame.
- It counts detected humans and tracks their positions.
- RMS Velocity: Calculates movement velocity using root mean square between frames.
- AnomalyMonitor: Tracks crowd and velocity histories, computes adaptive weights, and applies statistical analysis to detect anomalies (e.g., sudden crowd surges or dispersals).
- Processed frames and analytics are sent to the React frontend for visualization.
- The UI can display crowd counts, velocity graphs, and anomaly alerts in real time.
The above screenshot demonstrates the live system in action:
- Left: Real-time detection of people in a corridor, each marked with bounding boxes.
- Right: Dashboard with live plots showing people count, movement intensity (RMS), and anomaly score over time.
- Python 3.8+
- Node.js & npm (for React frontend)
- Required Python packages (see below)
1. Clone the repository:
git clone https://github.com/agrpranjal07/crowd-detection.git
cd crowd-detection
2. Python Backend Setup:
# Create a virtual environment (optional)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install opencv-python websockets ultralytics numpy scikit-learn
3. React Frontend Setup:
cd react-app
npm install
npm start
This will launch the web UI at http://localhost:3000.
Run the backend server:
cd server
python server.py
Run the client to send video frames:
cd client
python client.py
- Update
VIDEO_PATH
inclient.py
to your video file. - Ensure
SERVER_URI
matches the server endpoint (default:ws://localhost:8765/client
).
- Used for robust, fast object detection.
- Pretrained weights (
yolov8n (1).pt
) required; update the path if needed.
- Tracks crowd and velocity metrics.
- Uses adaptive weighting and linear regression to dynamically adjust anomaly thresholds.
- Flags anomalies based on deviations in recent vs. historical data.
- Efficient real-time data transfer between client, server, and frontend.
- Crowd Count: Number of detected people per frame.
- Velocity: Movement intensity metric (RMS).
- Anomaly Score: Composite metric indicating abnormal crowd behavior.
- UI Visualization: Real-time display of analytics and alerts.
Contributions and suggestions are welcome! Please fork the repository and submit pull requests.
This project currently does not specify a license. Please add one if you intend to share or distribute.
The project was a team project with Shashwat Raj and Saunak Das Chaudhary.
For more details, consult the design document: System Documentation