An real time DVS-style traffic monitoring system for:
- Real-time vehicle detection and tracking
- Vehicle classification (Car, Bike, Truck) using a self trained CNN
- Event-frame generation inspired by Dynamic Vision Sensors (DVS)
- Speed estimation based on movement across predefined virtual lines
Unlike traditional frame-based detection, this project uses DVS-inspired motion detection — using pixel-level intensity changes between consecutive frames to generate event frames, making it very efficient and responsive to motion.
- Motion detection via event-based frame differencing (DVS-inspired)
- Real-time object tracking with contour detection and centroid association
- Vehicle classification (Car, Bike, Truck) using a trained CNN model
- Relative speed estimation using timestamps between virtual lines across the road.
- Overlay visualizations with object IDs, motion arrows, and system metrics (CPU, latency, memory).
- Python 3.10+
- TensorFlow – Vehicle classification
- OpenCV – Image processing & tracking
- NumPy, SciPy – Centroid distance computation
- psutil – System performance monitoring
- os, time – Standard library utilities
traffic-surveillance/
├── collect_data.py # Save DVS-style ROIs from video
├── train_model.py # Train CNN on vehicle images
├── main.py/ # Real-time detection, classification & speed tracking
│ └── vehicle_cnn_model.h5 # Saved trained model
├── vehicle_dataset/
│ ├── Car/
│ ├── Bike/
│ └── Truck/
├── Resources/
│ ├── traffic_3.mp4 # For data collection
│ └── traffic_5.mp4 # For real-time inference
└── README.md
-
Clone the repository
git clone https://github.com/your-username/traffic-surveillance.git cd traffic-surveillance -
Install dependencies
pip install opencv-python tensorflow numpy scipy psutil
Extract grayscale event-based ROIs from a video for each class label.
python collect_data.pyControls:
Press s → Save current ROI (image)
Press n → Switch label (Car → Bike → Truck)
Press p → Pause and resume
Press q → Quit
🛠 Make sure Resources/traffic_3.mp4 exists before running.
Train a basic CNN to classify grayscale ROIs using the saved dataset.
python train_model.pyInput: Grayscale images (120×100)
Output: Trained model saved as model/vehicle_cnn_model.h5
Run the real-time DVS-style vehicle detection, classification, and speed tracking system.
python main.pyIt performs -
- DVS-style motion detection via frame differencing
- Vehicle classification using the trained CNN
- Centroid-based object tracking with ID persistence
- Speed estimation from movement across lines (y = 240 → 200)
- Live overlay: object boxes, motion arrows, labels, and stats
Built with ❤️ by Shreya Verma
