Drawing Architecture
TheDrawing class in drawing/main.py:86 orchestrates three specialized drawer components:
Main Drawing Pipeline
The complete drawing process indrawing/main.py:92:
Mask Drawing
TheMaskDrawer class in drawing/main.py:22 renders segmentation masks with transparency:
Mask Rendering Algorithm
The drawing process indrawing/main.py:26:
Mask Color Coding
- Default Colors
- Custom Mapping
- Dynamic Colors
Color scheme based on trash material types:
| Class | Material | BGR Color | Hex | Visual |
|---|---|---|---|---|
| 0 | Cardboard/Paper | (255, 0, 0) | #0000FF | Blue |
| 1 | Metal | (255, 255, 0) | #00FFFF | Cyan |
| 2 | Plastic | (200, 200, 200) | #C8C8C8 | Light Gray |
Color FormatOpenCV uses BGR (Blue, Green, Red) format, not RGB. When defining colors:
(255, 0, 0)= Blue(0, 255, 0)= Green(0, 0, 255)= Red
Bounding Box Rendering
TheBoundingBoxDrawer class in drawing/main.py:43 uses Ultralytics’ Annotator:
Box Format
Bounding boxes usexyxy format:
Label Customization
The trash classes dictionary maps indices to names:Track Visualization
TheTrackDrawer class in drawing/main.py:60 maintains object movement history:
Tracking Algorithm
The implementation indrawing/main.py:65 stores and renders centroid paths:
Track Persistence
Color Coding and Overlays
Consistent Color Assignment
Colors are assigned by track ID or class ID using Ultralytics utilities:colors() function ensures consistent colors across all visualizations.
Overlay Transparency
Mask overlays use alpha blending for transparency:- Semi-Transparent
- More Opaque
- Subtle
Default 50% transparency:
Customization Options
Custom Drawing Class
Create a customized drawing pipeline:Usage Examples
Performance Considerations
Drawing OverheadEach drawing layer adds processing time:
- Masks: ~10-15ms (polygon filling and blending)
- Boxes: ~2-5ms (simple rectangles and text)
- Tracks: ~3-7ms (line drawing)
Optimization Tips
- Disable unnecessary layers if you don’t need all visualizations
- Reduce track history length for faster rendering
- Use thinner lines to reduce drawing operations
- Skip frames for very high-speed requirements
Next Steps
Classification Pipeline
Learn about the complete processing pipeline
Video Processing
Set up real-time video stream processing