Prototype system for CCTV-based PPE (helmet, vest, etc.) detection with object tracking, violation capture, and a web dashboard.
The system uses:
- Python Flask for backend API and detection pipeline
- YOLO (YOLOv12n,m,l) for PPE detection
- SORT for object tracking
- React + Vite for the dashboard UI
- Redis for shared state and worker coordination
- PM2 for multi-process orchestration Violation images are automatically captured and stored with timestamp, camera location, and object ID.
+---------------------+
| React UI |
| (Frontend Server) |
+----------+----------+
| HTTP / MJPEG
+-------v--------+
| Flask API |
| (Backend) |
+-------+--------+
| Redis (state, coordination)
+-----------v-----------+
| PM2 Orchestrator |
| (Worker Management) |
+-----------+-----------+
|
+------------------+------------------+
| |
+-------v-------+ +--------v-------+
| CCTV Worker 1 | | CCTV Worker N |
| YOLO + SORT | | YOLO + SORT |
+-------+-------+ +--------+-------+
| |
+--------------> Violations <----------+
Image Storage
Each CCTV stream runs in an independent worker process managed by PM2. Workers perform detection and send results through Redis to the backend/dashboard.
- YOLO-based PPE detection
- SORT tracking for object persistence
- Per-object violation deduplication
- Automatic violation image capture
- Multi-camera worker system
- React dashboard with live CCTV streams
- Redis coordination for distributed workers
- PM2 orchestration and auto-restart
CCTV-Detection-Factory
│
├── backend/
│ ├── app.py # Flask entrypoint
│ ├── requirements.txt
│ ├── core/ # Detection & processing logic
│ │ ├── detection
│ │ ├── scheduler
│ │ └── violation_processor
│ ├── workers/ # Per-camera workers
│ │ ├── pm2_manager.py
│ │ └── cctv_worker.py
│ ├── model/ # YOLO model files
│ ├── services/ # DB / storage services
| └── .env.example # Environment variable template
│
├── frontend/
│ ├── src/
│ ├── server.mjs # Stream proxy server
│ └── package.json
│
├── ecosystem.config.js # PM2 process configuration
└── README.md
- Python 3.10+
- Node.js 18+
- Redis
- npm
- PM2 (global)
Optional:
- GPU with CUDA for faster YOLO inference
-
Create Python Environment Using Conda:
conda create -n your_name_env python=3.10 -y conda activate your_name_env
-
Install Backend Dependencies
pip install -r backend/requirements.txt pip install redis ultralytics pip install --upgrade pip setuptools wheel
-
Install Frontend Dependencies
cd frontend npm install npm install -g pm2 -
Database Setup The system uses PostgreSQL by Supabase. A database schema is provided in:
db_ppe_detection.sql -
Configure Environment Variables Create the
.envfile from the template:cp backend/.env.example backend/.env
Then edit the file and fill in the required values.
-
Start Redis
- macOS (Homebrew):
brew install redis brew services start redis
- Windows:
Download Redis from:
https://github.com/tporadowski/redis/releases
Then start:
redis-server
- macOS (Homebrew):
-
Run Backend
python backend/app.py
-
Run Frontend
cd frontend npm run build node server.mjs
PM2 is used to manage backend services and automatically restart workers.
-
Start the system:
pm2 start ecosystem.config.js pm2 list
-
View logs:
pm2 logs
-
Restart services:
pm2 restart all
-
Save configuration:
pm2 save pm2 startup
Redis is used for:
- Worker coordination
- Shared camera state
- Lightweight message passing
- Deduplication caches Ensure Redis is running before starting the system.
-
Python dependency errors Recreate the environment:
conda remove -n cctv --all conda create -n cctv python=3.10
-
Frontend React hook errors Reinstall node modules:
rm -rf node_modules package-lock.json npm install npm run build
-
Browser blocks port Use safe ports such as:
3000 5001 5173
-
Backend
conda activate your_name_env python backend/app.py
-
Frontend development
cd frontend npm run dev -
PM2
pm2 start ecosystem.config.js pm2 logs pm2 save
© 2025 PT Summit Adyawinsa Indonesia