This project implements a real-time crowd density monitoring system using a single laptop. It consists of three components:
- Edge Service: Captures video from a webcam/IP camera, detects people using YOLOv8, and sends data to the backend.
- Backend Service: A FastAPI server that receives crowd data and serves it to the frontend.
- Frontend Service: A web dashboard that displays real-time crowd density, count, and trends.
- Python 3.9+ installed.
- Git installed.
- Webcam (for testing) or Wi-Fi IP Camera (for demo).
-
Clone the Repository
git clone https://github.com/falcon370/design_thinking.git cd design_thinking
-
Create a Virtual Environment
python -m venv venv -
Activate the Virtual Environment
- Windows (PowerShell):
.\venv\Scripts\activate
- Mac/Linux:
source venv/bin/activate
- Windows (PowerShell):
-
Install Dependencies
pip install -r requirements.txt
We have provided a PowerShell script to start all services in separate windows.
- Open a PowerShell terminal in the project root.
- Run the script:
- Localhost (Default):
.\start_system.ps1
- Specific IP (e.g., for mobile testing):
If you want to access the dashboard from your phone or another computer, use your laptop's Wi-Fi IP address (e.g.,
192.168.68.104)..\start_system.ps1 -HostIP "192.168.68.104"
- Optional: Run with debug logging enabled:
.\start_system.ps1 -LogLevel DEBUG
- Localhost (Default):
- The dashboard will be available at:
- Localhost: http://localhost:8081
- IP Mode:
http://<YOUR_IP>:8081(e.g.,http://192.168.68.104:8081)
- A window showing the camera feed with detections will appear.
If you prefer to run services manually, open three separate terminals and follow these steps:
.\venv\Scripts\activate
$env:LOG_LEVEL='INFO'; uvicorn src.backend_service.main:app --host 0.0.0.0 --port 8000 --reloadpython -m http.server 8081 --directory src/frontendOpen http://localhost:8081 in your browser.
.\venv\Scripts\activate
# Usage: python src/edge_service/main.py <location_id> <camera_source>
python src/edge_service/main.py canteen 0You can run multiple instances of the Edge Service for different locations.
# Terminal A (Canteen - Webcam)
python src/edge_service/main.py canteen 0
# Terminal B (Library - IP Camera)
python src/edge_service/main.py library "rtsp://192.168.1.105:554/stream1"The system supports three log levels, configurable via the LOG_LEVEL environment variable or the -LogLevel script parameter:
- INFO (Default): Standard startup/shutdown and transmission logs.
- DEBUG: Detailed logs including every detection count per frame.
- CRITICAL: Only errors and critical failures.
To access the dashboard from other devices (e.g., a phone) on the same Wi-Fi:
-
Find your Laptop's IP Address:
- Open PowerShell and run
ipconfig. - Look for "IPv4 Address" (e.g.,
192.168.1.10).
- Open PowerShell and run
-
Update Frontend Config:
- Open
src/frontend/index.html. - Change line 55:
// const API_URL = "http://localhost:8000/current-status"; const API_URL = "http://192.168.1.10:8000/current-status"; // Replace with YOUR IP
- Open
-
Restart Frontend:
- If running manually, restart the frontend terminal.
- If using
start_system.ps1, close and run it again.
-
Access from Mobile:
- Open browser on phone:
http://192.168.1.10:8081
- Open browser on phone:
/src
/backend_service # FastAPI Server (main.py, test_backend.py)
/edge_service # Computer Vision Logic (main.py)
/frontend # Web Dashboard (index.html)
requirements.txt # Python dependencies
start_system.ps1 # Startup script
README.md # This file
- "Module not found": Ensure you activated the virtual environment (
.\venv\Scripts\activate) before running python commands. - Camera not opening: Check if another app (Zoom, Teams) is using the camera. Verify
CAMERA_SOURCEinsrc/edge_service/main.py. - Backend connection error: Ensure the Backend Service is running on port 8000 before starting the Edge Service.