Women Safety SOS https://github.com/RAVI-RAJPUT-UMATH/Women_Safety : A quick emergency response system for women's safety.
Signal Automation https://github.com/pawankushwahh/Signal_Automation : An AI-driven system for optimizing traffic signals based on real-time traffic density.
Traffic Rule Violation Detection and Notification System** (This repository): Automated detection of traffic rule violations using computer vision.
Video Demonstration https://drive.google.com/file/d/1GaEdtEzO_qE81oPrjO9-C9Vlkk_zl1CV/view?usp=sharing
An automated system that detects traffic rule violations using computer vision, processes the violations, and sends notifications to both violators and traffic authorities.
- Real-time Violation Detection: Uses YOLOv8 for detecting vehicles and identifying violations
- Multiple Violation Types: Detects various violations including:
- No Helmet
- Wrong Side Driving
- Signal Jump
- Automated Notifications: Sends instant email notifications to:
- Vehicle owners
- Traffic authorities
- Violation Logging: Maintains detailed logs of all violations
- Fine Generation: Automatically calculates fines based on violation type
The project runs in two simple steps. They are connected through one CSV file:
video.mp4
│
▼
[ STEP 1: violation_detector.py ]
- YOLO finds vehicles, EasyOCR reads number plates
- decides if a rule was broken
- writes each violation as a row in data/violators_data.csv
│
▼
data/violators_data.csv ← the link between the two steps
│
▼
[ STEP 2: notification_system.py ]
- reads each violation row
- looks up the owner (vehicle_database.csv) and police zone (location_authorities.csv)
- emails both, and saves a copy in notification_logs/
You can run both steps at once with main.py.
- Python 3.8 or higher
- A Gmail account (or any SMTP provider) for sending emails
- You can also run in simulation mode with no email account at all.
-
Clone the repository:
git clone https://github.com/pawankushwahh/traffic-violation-detection.git cd traffic-violation-detection -
Install required packages:
pip install -r requirements.txt
-
Create your
.envfile (copy from.env.example) and fill in your values:SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your.email@gmail.com SMTP_PASSWORD=your_gmail_app_password FROM_EMAIL=your.email@gmail.com EMAIL_SIMULATION=trueGmail setup: Enable 2-Step Verification, then create an App Password and use that as
SMTP_PASSWORD. KeepEMAIL_SIMULATION=truewhile testing so no real emails are sent.
Traffic-management-and-women-safety/
├── config.py # ALL settings live here (read this first!)
├── main.py # run the whole pipeline (step 1 + step 2)
├── violation_detector.py # STEP 1: detect violations in a video
├── notification_system.py # STEP 2: email owners and authorities
├── email_service.py # helper that actually sends the emails
├── data/
│ ├── vehicle_database.csv # owner info (name, phone, address, email)
│ ├── violators_data.csv # detected violations (the link between steps)
│ └── location_authorities.csv # police zone contact details
├── violations/ # snapshot images of caught vehicles
├── notification_logs/ # a text copy of every email
├── .env.example # template for your .env file
└── requirements.txt # project dependencies
python main.py --video video.mp4If you don't want a video window to open (e.g. on a server):
python main.py --video video.mp4 --no-display-
Detect violations (writes rows into
data/violators_data.csv):python violation_detector.py --video video.mp4
-
Send notifications for everything recorded so far:
python notification_system.py
- By default (
EMAIL_SIMULATION=true), emails are only printed and saved tonotification_logs/— nothing is actually sent. Great for testing. - To send for real, set
EMAIL_SIMULATION=falsein.env, or use the--sendflag:python main.py --notify-only --send python notification_system.py --send
-
data/vehicle_database.csv:
Vehicle_Number,Owner_Name,Phone_Number,Address,Owner_Email UP32UV1111,Aditya Mishra,+91XXXXXXXXXX,"45 Indira Nagar, Lucknow",aditya.mishra@example.com(Addresses that contain a comma must be wrapped in "double quotes".)
-
data/violators_data.csv:
Vehicle_Number,Violation_Type,Location,Violation_Time,Fine_Amount UP32UV1111,No Helmet,Hazratganj,2025-02-15 08:20:00,500
- Helmet detection is a placeholder. The default
yolov8nmodel was not trained on helmets, sohas_helmet()inviolation_detector.pycurrently always returnsTrue. To make "No Helmet" work, plug in a helmet-trained YOLO model there. - Detected plates must exist in
vehicle_database.csvfor an email to be sent. If a real-world plate is read that isn't in the database, the notification step logs a warning and skips it (this is expected). - The sample rows already in
data/violators_data.csvlet you test the email step on their own, without running detection.
-
Violator Notification:
Traffic Violation Notice Dear [Owner Name], Your vehicle ([Vehicle Number]) was detected violating traffic rules: Violation: [Violation Type] Location: [Location] Time: [Timestamp] Fine Amount: Rs. [Amount] -
Authority Notification:
New Traffic Violation Detected Vehicle Number: [Number] Violation Type: [Type] Location: [Location] Time: [Timestamp] Vehicle Owner: [Name] Owner Contact: [Phone] Fine Amount: Rs. [Amount]
-
No Notifications Being Sent:
- Check if SMTP credentials are correctly set in
.env - For Gmail, use an App Password (not your regular password)
- Verify vehicle exists in database with a valid
Owner_Email - Check network connectivity
- Check if SMTP credentials are correctly set in
-
Vehicle Not Found:
- Ensure vehicle information is present in
vehicle_database.csv - Check if vehicle number format matches database format
- Ensure vehicle information is present in
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
mail - Kushwahpawan2005@gmail.com Project Link: https://github.com/pawankushwahh/traffic-violation-detection