๐ฅ Real-time Traffic Monitoring and Speed Enforcement
This system uses artificial intelligence to detect vehicles in video streams, track their movement, and calculate their speeds in real-time. It can:
๐ Identify different types of vehicles (cars, trucks, buses, motorcycles) ๐๏ธ Measure vehicle speeds accurately ๐ฆ Detect and log speed limit violations ๐ Display real-time results on screen
Our Vehicle Speed Detection System is composed of several interconnected components, each playing a crucial role in the overall functionality. Here's a detailed breakdown of each component:
-
๐ฌ Main Application (
main.py
) ๐ Serves as the entry point for the entire system ๐ญ Handles command-line arguments for video source selection ๐ Initializes and kicks off the video processing pipeline -
๐๏ธ Video Processor (
video_processor.py
) ๐ง Acts as the central brain of the system ๐ Coordinates interactions between all other components ๐ฅ๏ธ Manages the main processing loop for each video frame ๐๏ธ Implements performance optimizations like selective frame processing -
๐ Vehicle Detector (
detector.py
) ๐๏ธ Utilizes YOLOv8 AI model for real-time object detection ๐ Identifies and locates vehicles in each processed frame ๐ท๏ธ Classifies detected objects into vehicle categories (e.g., car, truck, bus, motorcycle) ๐ฏ Applies confidence thresholding to minimize false positives -
๐ผ๏ธ Visualizer (
visualizer.py
) ๐จ Draws bounding boxes around detected vehicles on the video frame ๐ Overlays vehicle information (type, speed) on the video ๐ฆ Color-codes speed displays based on speed limit compliance ๐ฅ๏ธ Manages the on-screen display of processing statistics (e.g., FPS counter) -
๐ Data Logger (
data_logger.py
) ๐ Records speed limit violations in real-time ๐ Timestamps each violation entry ๐ Saves violation data to an Excel file for later analysis ๐ Ensures data integrity with proper file handling and error management -
๐น Video Capture (
video_capture.py
) ๐ฅ Handles video input from various sources (webcam, video files) ๐งต Implements multi-threading for efficient frame capture ๐ ๏ธ Provides fallback options and error handling for different video backends -
โฑ๏ธ Speed Tracker (
speed_tracker.py
) ๐ Maintains position history for each detected vehicle ๐งฎ Calculates vehicle speeds based on position changes over time ๐ข Implements algorithms to smooth speed calculations and reduce fluctuations -
๐งฎ Speed Calculator (
speed_calculator.py
) ๐ Converts pixel movements to real-world speed measurements ๐งช Applies statistical methods to filter out anomalies in speed data ๐๏ธ Adapts calculations based on camera perspective and positioning -
๐ Calibration (
calibration.py
) ๐ Handles camera calibration parameters ๐บ๏ธ Translates pixel coordinates to real-world distances ๐ง Provides functions to adjust for camera angle and positioning -
โ๏ธ Configuration (
config.py
) ๐๏ธ Centralizes all system-wide settings and parameters ๐ฅ Defines speed limits for different vehicle types ๐๏ธ Allows easy tuning of detection and tracking parameters ๐๏ธ Stores mappings for vehicle classes and their corresponding indices
- Video Input: Uses your webcam or a video file
- Vehicle Detection: Spots vehicles using YOLOv8 AI
- Tracking: Follows each vehicle across video frames
- Speed Calculation: Estimates speed based on vehicle movement
- Visualization: Shows results on screen with bounding boxes and speed info
- Logging: Records speed violations in an Excel file
Python 3.8 or newer OpenCV NumPy Ultralytics YOLOv8 openpyxl SciPy
๐โโก๏ธ๐โโก๏ธ๐โโก๏ธBefore Run the Program ๐โโก๏ธ๐โโก๏ธ๐โโก๏ธ:
Install the required packages: ( pip install opencv-python numpy ultralytics openpyxl scipy ) ๐๐OR๐๐ ( pip install -r requirements.txt )
-
Run the Program: For webcam:
python main.py
For video file:python main.py path/to/your/video.mp4
-
Controls: Press 'q' to quit Press 's' to save a screenshot
Edit config.py
to change:
๐ฏ Detection sensitivity
๐ Speed calculation settings
๐ Speed limits for different vehicles
- Live video with:
- Boxes around detected vehicles
- Vehicle types (car, truck, etc.)
- Calculated speeds
- Frames per second (FPS) count
speed_violations.xlsx
file with logged violations
๐ Calibrate the camera settings in config.py
for your setup
๐ฅ Use high-quality video input for better accuracy
๐ป A computer with a good GPU will run the system faster
- Night-time detection improvements
- License plate recognition
- Web interface for remote monitoring
- Integration with traffic management systems
We welcome your ideas and code contributions! Here's how:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
๐ License
This project is a Open Source Project.
๐ฅ Team
ABHISHEK SINGH Project Lead and Creater.
๐ Need Help? ๐ Issues: GitHub Issues Page