A traffic congestion analysis system using YOLO Segmentation to detect and segment vehicles, then calculate congestion percentage within a Region of Interest (ROI).
- Vehicle Segmentation: Detect and segment vehicles using trained YOLO model
- ROI Selection: Select region of interest by clicking 4 points on the image
- Congestion Calculation: Calculate congestion percentage based on vehicle area within ROI
- Visualization: Display results with mask overlay, ROI, and congestion information
- Model Comparison: Compare results between trained and pretrained models
| Original | Trained Model | Segmentation |
|---|---|---|
![]() |
![]() |
![]() |
| Original | Trained Model | Segmentation |
|---|---|---|
![]() |
![]() |
![]() |
Compare the performance between YOLO11x-seg pretrained model and our custom trained model.
| Original | Pretrained Model | Trained Model |
|---|---|---|
![]() |
![]() |
![]() |
| Original | Pretrained Model | Trained Model |
|---|---|---|
![]() |
![]() |
![]() |
Want to train your own YOLO model for vehicle segmentation? Check out our training guide:
🔗 YOLOv11 Vehicle Segmentation Training
The guide includes:
- Dataset preparation and annotation
- Training configuration
- Model evaluation
- Export trained model
Vehicle-Segmentation/
├── main.py # Main traffic analysis script
├── compare_models.py # Compare two YOLO models
├── models/
│ ├── best.pt # Trained YOLO model
│ └── yolo_model.py # YOLO model wrapper
├── services/
│ └── congestion_analyzer.py # Congestion analysis
├── ui/
│ └── roi_selector.py # ROI selection interface
├── utils/
│ ├── geometry.py # Geometry calculations
│ ├── load_image.py # Image loader
│ └── show_result.py # Result display
├── visualization/
│ └── renderer.py # Result renderer
├── data_predict/ # Test images (10 samples)
└── result/ # Result images
- Python 3.8+
- OpenCV
- Ultralytics YOLO
- NumPy
git clone <repository-url>
cd Vehicle-Segmentationpython -m venv venv
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activatepip install opencv-python ultralytics numpypython main.pySteps:
- Select an image from file dialog
- Click 4 points to define ROI
- View results showing:
- Original image
- Image with ROI, masks, and congestion percentage
- Segmentation masks only
python compare_models.pyCompare trained model (best.pt) vs pretrained YOLO11x-seg model.
Load Image → Select ROI → YOLO Prediction → Calculate Intersection → Compute Congestion → Display Results
Congestion Percentage = (Total Vehicle Area in ROI / ROI Area) × 100







