Spaces:
Sleeping
π¦ TrafficGuard AI β Flipkart Gridlock Hackathon 2.0 (Round 2)
Automated Photo Identification & Classification for Traffic Violations
π Submission Checklist (from HackerEarth)
| # | Deliverable | Status | Notes |
|---|---|---|---|
| 1 | Title | [ ] |
"TrafficGuard AI β Automated Traffic Violation Detection & Classification" |
| 2 | Description | [ ] |
Detailed project write-up (we'll draft this) |
| 3 | Theme | [ ] |
Select from dropdown (Computer Vision / AI) |
| 4 | Snapshots | [ ] |
3-5 screenshots of the dashboard + detection results |
| 5 | Video URL | [ ] |
2-3 min demo video (upload to YouTube/Loom) |
| 6 | Presentation | [ ] |
10-12 slide pitch deck (.pdf/.pptx) |
| 7 | Demo Link | [ ] |
Deployed web app (Vercel + Railway/Render) |
| 8 | Repository URL | [ ] |
GitHub repo with clean README |
| 9 | Source Code | [ ] |
.zip of the repo (max 50MB) |
| 10 | Instructions to Run | [ ] |
Step-by-step setup guide |
| 11 | Custom Attachment | [ ] |
Optional: model weights, sample data |
ποΈ System Architecture
graph TB
subgraph Input["π· Input Layer"]
A[Traffic Camera Image] --> B[Image Upload API]
B --> C[Image Preprocessing]
end
subgraph Preprocessing["π§ Preprocessing Pipeline"]
C --> D[Quality Enhancement]
D --> D1[Denoising / Dehazing]
D --> D2[Low-light Enhancement]
D --> D3[Motion Blur Correction]
D1 & D2 & D3 --> E[Normalized Image]
end
subgraph Detection["π Detection Engine"]
E --> F[YOLOv8 Vehicle Detection]
E --> G[YOLOv8 Person Detection]
F --> H[Vehicle Classification]
G --> I[Rider/Pedestrian Classification]
H & I --> J[Region of Interest Extraction]
end
subgraph Violation["β οΈ Violation Analysis"]
J --> K[Helmet Detection Model]
J --> L[Seatbelt Detection Model]
J --> M[Triple Riding Detector]
J --> N[Wrong-Side Driving Detector]
J --> O[Stop-Line / Red-Light Violation]
J --> P[Illegal Parking Detector]
end
subgraph LPR["π’ License Plate Recognition"]
J --> Q[License Plate Detection]
Q --> R[Plate Region Extraction]
R --> S[OCR - EasyOCR/PaddleOCR]
S --> T[Registration Number]
end
subgraph Output["π Output Layer"]
K & L & M & N & O & P --> U[Violation Classifier]
U --> V[Confidence Scoring]
V --> W[Annotated Evidence Image]
T --> W
W --> X[Database Storage]
X --> Y[Analytics Dashboard]
X --> Z[Report Generation]
end
π οΈ Recommended Tech Stack
| Layer | Technology | Why |
|---|---|---|
| Object Detection | YOLOv8 (Ultralytics) | State-of-art, fast, easy fine-tuning, hackathon-friendly |
| Image Preprocessing | OpenCV + albumentations | Industry standard, rich preprocessing toolkit |
| OCR (License Plates) | EasyOCR or PaddleOCR | Works well on Indian plates, multi-language support |
| Backend API | FastAPI (Python) | Async, fast, auto-generates Swagger docs (impressive for judges) |
| Frontend Dashboard | React + Vite | Fast dev, modern UI, great for analytics visualizations |
| Charts/Analytics | Recharts or Chart.js | Easy to integrate, beautiful charts |
| Database | SQLite (dev) / PostgreSQL (prod) | Lightweight for hackathon, scales for demo |
| Deployment | Vercel (frontend) + Railway/Render (backend) | Free tier, easy deploy |
| Model Serving | ONNX Runtime or direct PyTorch | Fast inference, no GPU needed for demo |
π Phased Workflow (Execution Order)
The phases below are ordered by dependency and impact. Follow this exact sequence for maximum efficiency. Time estimates assume 1-2 person team working intensively.
Phase 1: Foundation & Setup (Day 1 β ~4 hours)
Goal: Get the project skeleton up and running.
Tasks:
Repository Setup
- Create GitHub repo with proper structure
- Add
.gitignore,README.md,LICENSE - Set up virtual environment (
python -m venv venv)
Project Structure
trafficguard-ai/ βββ backend/ β βββ app/ β β βββ main.py # FastAPI entry point β β βββ routes/ β β β βββ upload.py # Image upload endpoint β β β βββ violations.py # Violation query endpoints β β β βββ analytics.py # Stats & reporting β β βββ models/ β β β βββ detector.py # YOLO detection wrapper β β β βββ violation.py # Violation classification logic β β β βββ ocr.py # License plate OCR β β β βββ preprocessor.py # Image preprocessing pipeline β β βββ database/ β β β βββ models.py # SQLAlchemy models β β β βββ db.py # DB connection β β βββ utils/ β β β βββ annotator.py # Draw bounding boxes + labels β β β βββ evidence.py # Evidence image generation β β βββ config.py β βββ weights/ # Pre-trained model weights β βββ requirements.txt β βββ Dockerfile βββ frontend/ β βββ src/ β β βββ components/ β β β βββ Dashboard.jsx β β β βββ UploadPanel.jsx β β β βββ ViolationCard.jsx β β β βββ AnalyticsCharts.jsx β β β βββ EvidenceViewer.jsx β β βββ pages/ β β βββ App.jsx β β βββ main.jsx β βββ package.json β βββ vite.config.js βββ data/ β βββ sample_images/ # Test images β βββ annotations/ # Ground truth (if any) βββ notebooks/ β βββ exploration.ipynb # Model experiments βββ docs/ β βββ architecture.png βββ README.mdInstall Core Dependencies
# Backend pip install fastapi uvicorn ultralytics opencv-python-headless easyocr \ sqlalchemy pillow python-multipart albumentations # Frontend npm create vite@latest frontend -- --template react cd frontend && npm install recharts axios react-router-dom lucide-reactDownload Pre-trained Models
- YOLOv8n or YOLOv8s from Ultralytics (for speed in demo)
- EasyOCR models (auto-download on first use)
Phase 2: Image Preprocessing Pipeline (Day 1-2 β ~3 hours)
Goal: Build a robust preprocessing module that handles real-world image challenges.
Tasks:
preprocessor.pyβ Core preprocessing functions:- Auto-enhancement: CLAHE (Contrast Limited Adaptive Histogram Equalization) for low-light
- Denoising: OpenCV's
fastNlMeansDenoisingColored - Dehazing: Dark channel prior or simple contrast stretch
- Motion blur detection: Laplacian variance check β apply Wiener filter if blurry
- Normalization: Resize to standard input size (640Γ640 for YOLO), normalize pixel values
Quality Assessment Score: Output a 0-100 image quality score to display in UI
Don't over-engineer preprocessing. YOLO is robust to moderate noise. Focus on CLAHE + resize + normalize as the minimum viable pipeline. Add dehazing/deblurring as polish.
Phase 3: Vehicle & Person Detection (Day 2 β ~4 hours)
Goal: Detect and classify all road users from a traffic image.
Tasks:
detector.pyβ YOLO Detection Wrapper:- Load YOLOv8 pretrained on COCO (has car, truck, bus, motorcycle, bicycle, person classes)
- Run inference β extract bounding boxes, class labels, confidence scores
- Filter by confidence threshold (β₯ 0.4)
- Apply NMS (Non-Maximum Suppression) β built into YOLO
Vehicle Classification:
- Map COCO classes β custom categories:
carβ Sedan/Hatchbacktruckβ Heavy Vehiclebusβ Public Transportmotorcycleβ Two-Wheelerbicycleβ Bicycle
- Count occupants per vehicle (person boxes overlapping with vehicle boxes)
- Map COCO classes β custom categories:
Output Format:
{ "detections": [ { "id": 1, "class": "motorcycle", "category": "Two-Wheeler", "bbox": [x1, y1, x2, y2], "confidence": 0.92, "occupants": 2 } ] }
Phase 4: Violation Detection Models (Day 2-3 β ~8 hours) β CORE
Goal: This is the heart of the project. Detect specific traffic violations.
This is the most critical phase. Spend the most time here. The quality of violation detection directly determines your hackathon score.
4A. Helmet Non-Compliance Detection
- Approach: For each detected motorcycle rider, check if a helmet is present
- Method 1 (Quick): Fine-tune YOLOv8 on a helmet/no-helmet dataset
- Datasets: Safety Helmet Detection on Kaggle, or motorcycle helmet datasets
- Method 2 (Faster for hackathon): Use a pre-trained helmet detection YOLO model from Roboflow Universe
- Logic: If
persononmotorcycleAND nohelmetdetected in head region β VIOLATION
4B. Seatbelt Non-Compliance
- Approach: For occupants in cars, check seatbelt presence
- Method: Crop the driver/passenger region β run a binary classifier (seatbelt/no-seatbelt)
- Alternative: Use a pre-trained model from Roboflow or fine-tune a small CNN (ResNet18)
4C. Triple Riding Detection
- Approach: Count persons associated with a single motorcycle
- Logic: If motorcycle has β₯ 3
persondetections overlapping β VIOLATION - Implementation: IoU (Intersection over Union) between person boxes and motorcycle box
4D. Wrong-Side Driving
- Approach: Detect vehicle direction relative to road lane markings
- Method:
- Detect lane markings (Hough Line Transform or a lane detection model)
- Determine expected traffic direction from road geometry
- Check if vehicle heading contradicts expected direction
- Simplified: Define ROI zones in the image; vehicles detected in the wrong zone = violation
4E. Stop-Line / Red-Light Violation
- Approach:
- Detect traffic signals (red/green/yellow) using color detection or a small classifier
- Detect stop line position (edge detection or predefined zone)
- If signal is RED and vehicle bbox crosses the stop line β VIOLATION
4F. Illegal Parking
- Approach:
- Define no-parking zones (configurable regions in the image)
- If a vehicle is detected stationary in a no-parking zone β VIOLATION
- For static images: vehicle in no-parking zone = violation
Violation Classification Output:
{
"violations": [
{
"type": "HELMET_NON_COMPLIANCE",
"severity": "HIGH",
"confidence": 0.87,
"vehicle_id": 1,
"description": "Motorcycle rider without helmet detected",
"bbox": [x1, y1, x2, y2]
}
]
}
Phase 5: License Plate Recognition (Day 3 β ~4 hours)
Goal: Detect license plates and extract text via OCR.
Tasks:
Plate Detection:
- Use YOLOv8 fine-tuned on Indian license plate dataset (available on Roboflow/Kaggle)
- Or use a pre-trained WPOD-NET / ALPR model
- Crop the detected plate region
Plate Preprocessing:
- Grayscale conversion
- Perspective correction (deskew)
- Binarization (Otsu's threshold)
- Resize to standard dimensions
OCR Extraction:
import easyocr reader = easyocr.Reader(['en']) result = reader.readtext(plate_image) # Post-process: regex for Indian plate format # e.g., "MH 12 AB 1234" or "DL 01 CA 0001"Indian Plate Format Validation:
- Regex:
^[A-Z]{2}\s?\d{1,2}\s?[A-Z]{1,3}\s?\d{4}$ - Common OCR corrections (0βO, 1βI, 5βS, 8βB)
- Regex:
Phase 6: Evidence Generation & Storage (Day 3-4 β ~3 hours)
Goal: Produce annotated images and store violation records.
Tasks:
annotator.pyβ Draw on images:- Bounding boxes with color-coded labels (red for violations, green for compliant)
- Violation type labels with confidence %
- License plate text overlay
- Timestamp and location watermark
evidence.pyβ Generate evidence package:- Annotated image (saved as JPEG)
- Violation metadata JSON
- Timestamp
- Unique violation ID
Database Models (SQLAlchemy):
class Violation(Base): id = Column(Integer, primary_key=True) image_path = Column(String) annotated_image_path = Column(String) violation_type = Column(String) # ENUM confidence = Column(Float) vehicle_type = Column(String) license_plate = Column(String) timestamp = Column(DateTime) location = Column(String) severity = Column(String) status = Column(String) # "pending", "confirmed", "dismissed"
Phase 7: Backend API (Day 4 β ~4 hours)
Goal: RESTful API that ties everything together.
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/upload |
Upload image for analysis |
GET |
/api/violations |
List all violations (with filters) |
GET |
/api/violations/{id} |
Get violation details |
GET |
/api/analytics/summary |
Violation statistics |
GET |
/api/analytics/trends |
Time-based trends |
GET |
/api/analytics/by-type |
Violations grouped by type |
GET |
/api/evidence/{id} |
Get annotated evidence image |
POST |
/api/batch-upload |
Process multiple images |
Processing Flow:
@app.post("/api/upload")
async def analyze_image(file: UploadFile):
# 1. Save uploaded image
# 2. Preprocess
# 3. Run vehicle/person detection
# 4. Run violation detection
# 5. Run license plate OCR
# 6. Generate annotated evidence
# 7. Store in database
# 8. Return results
Phase 8: Frontend Dashboard (Day 4-5 β ~6 hours) β HIGH IMPACT
Goal: A stunning, modern dashboard that wows the judges.
The dashboard is what judges SEE FIRST. Make it visually impressive. Dark theme, smooth animations, glassmorphism, gradient accents.
Pages & Components:
Dashboard Home (
/)- Real-time violation counter cards (with animated numbers)
- Violation type distribution (donut chart)
- Trend line chart (violations over time)
- Recent violations feed (live-updating cards)
- Severity heatmap
Upload & Analyze (
/analyze)- Drag-and-drop image upload zone
- Real-time processing animation (skeleton loader β results)
- Side-by-side: Original image β Annotated image
- Detected violations list with confidence bars
- License plate extracted text
- Export evidence button
Violation Records (
/violations)- Searchable, filterable table
- Filter by: type, date, severity, vehicle type, plate number
- Click to expand β full evidence view
- Bulk export (CSV/PDF)
Analytics (
/analytics)- Interactive charts (violations by type, by time, by location)
- Top offenders (by license plate)
- Model performance metrics (accuracy, precision, recall display)
- Processing speed metrics
Design System:
- Colors: Dark navy (
#0f172a) background, electric blue (#3b82f6) accents, violation red (#ef4444), success green (#22c55e) - Typography: Inter (Google Fonts)
- Effects: Glassmorphism cards, gradient borders, subtle hover animations
- Icons: Lucide React
Phase 9: Integration & Testing (Day 5 β ~4 hours)
Goal: Wire everything together and test end-to-end.
Tasks:
- Connect frontend β backend API
- Test with sample traffic images (collect 20-30 from Google / Kaggle)
- Fix edge cases (no violations found, blurry image, no plate detected)
- Performance benchmarking:
- Measure inference time per image
- Calculate mAP, precision, recall on test set
- Document results in a metrics table
Performance Metrics to Report:
| Metric | Target | How to Calculate |
|---|---|---|
| Accuracy | > 85% | Correct predictions / Total |
| Precision | > 80% | TP / (TP + FP) |
| Recall | > 75% | TP / (TP + FN) |
| F1-Score | > 78% | 2 Γ (P Γ R) / (P + R) |
| mAP@0.5 | > 70% | YOLO's built-in eval |
| Inference Time | < 2s/image | Time per image on CPU |
Phase 10: Deployment (Day 5-6 β ~3 hours)
Goal: Get a live demo URL.
Deployment Strategy:
- Frontend β Vercel (free, auto-deploy from GitHub)
- Backend β Railway or Render (free tier, supports Python)
- Model Weights β Bundle with backend (< 50MB for YOLOv8n) or use cloud storage
- Database β SQLite file (bundled) or Railway PostgreSQL
Steps:
# Frontend
cd frontend && npm run build
# Deploy to Vercel via CLI or GitHub integration
# Backend
# Create Dockerfile
# Deploy to Railway: railway up
Phase 11: Presentation & Documentation (Day 6 β ~4 hours)
Goal: Create a compelling pitch deck and demo video.
Pitch Deck (10-12 slides):
| Slide | Content |
|---|---|
| 1 | Title + Team + Tagline |
| 2 | Problem Statement (with statistics) |
| 3 | Solution Overview (architecture diagram) |
| 4 | Tech Stack |
| 5 | Key Features (with screenshots) |
| 6 | Live Demo Screenshots |
| 7 | Violation Detection Examples (before/after) |
| 8 | Analytics & Reporting |
| 9 | Performance Metrics (accuracy table) |
| 10 | Scalability & Future Scope |
| 11 | Business Impact |
| 12 | Thank You + Contact |
Demo Video (2-3 mins):
- Quick problem statement (15 sec)
- Upload an image β show real-time detection (45 sec)
- Walk through annotated results (30 sec)
- Show license plate OCR (15 sec)
- Dashboard analytics (30 sec)
- Architecture overview (15 sec)
README.md Must Include:
- Project title + badges
- Architecture diagram
- Features list
- Screenshots
- Tech stack
- Setup instructions (copy-paste ready)
- API documentation
- Performance metrics
- Future scope
π― Winning Strategy β What Judges Look For
Based on typical hackathon judging criteria, prioritize these:
| Priority | Aspect | Weight | Our Approach |
|---|---|---|---|
| π₯ | Innovation & Uniqueness | HIGH | Multi-violation detection in single image, real-time confidence scoring, evidence chain |
| π₯ | Working Prototype | HIGH | Live deployed demo with real detections |
| π₯ | Technical Depth | MEDIUM-HIGH | YOLO + OCR + preprocessing pipeline, proper ML evaluation metrics |
| π₯ | UI/UX Quality | MEDIUM-HIGH | Premium dark-theme dashboard with animations |
| π₯ | Scalability | MEDIUM | Containerized, async processing, batch upload |
| π₯ | Presentation | MEDIUM | Clear pitch deck + demo video |
π Differentiators (What Makes Us Stand Out)
- Multi-Violation Detection in Single Image: Most solutions detect one violation type. Ours detects ALL types simultaneously.
- Indian License Plate Specialized OCR: Custom regex + corrections for Indian plate formats.
- Confidence-Scored Evidence Chain: Every detection has a confidence score β legally defensible evidence.
- Adaptive Preprocessing: Auto-detects image quality issues and applies appropriate corrections.
- Real-time Analytics Dashboard: Not just detection, but actionable insights and trends.
- Batch Processing: Upload multiple images for bulk analysis.
β οΈ Open Questions for You
Please clarify these before we start building:
Team Size: You mentioned "1 member" β are you working solo or will more people join? This affects the scope we should target.
Timeline: When is the submission deadline for Round 2? This determines how much we can build.
GPU Access: Do you have access to any GPU (Google Colab, Kaggle, personal GPU)? This affects whether we fine-tune models or use only pre-trained ones.
Deployment Preference: Do you want to deploy on Vercel + Railway (free), or do you have other hosting in mind?
Scope Priority: Given time constraints, which violations should we prioritize? My recommendation:
- Must Have: Helmet detection, Triple riding, License plate OCR
- Should Have: Red-light violation, Stop-line violation, Wrong-side driving
- Nice to Have: Seatbelt detection, Illegal parking
Do you want me to start building the code now, or do you want to refine the plan first?
π Effort Estimation Summary
| Phase | Hours | Priority |
|---|---|---|
| Foundation & Setup | 4h | π΄ Critical |
| Image Preprocessing | 3h | π‘ Important |
| Vehicle Detection | 4h | π΄ Critical |
| Violation Detection | 8h | π΄ Critical |
| License Plate OCR | 4h | π΄ Critical |
| Evidence Generation | 3h | π‘ Important |
| Backend API | 4h | π΄ Critical |
| Frontend Dashboard | 6h | π΄ Critical |
| Integration & Testing | 4h | π‘ Important |
| Deployment | 3h | π‘ Important |
| Presentation & Docs | 4h | π΄ Critical |
| Total | ~47h | β |
For a solo developer working intensively, this is achievable in 5-6 days with focused effort.