fix: remove inverted try/except in draw_detections and add empty-boxe…#508
fix: remove inverted try/except in draw_detections and add empty-boxe…#508KERDAWY-2 wants to merge 2 commits intoJdeRobot:masterfrom
Conversation
…s guard The previous try/except pattern always attempted the old supervision API first, guaranteeing an exception on every call with supervision>=0.18. Replaced with a clean direct call using BoxAnnotator and LabelAnnotator. Also added an early return when boxes is empty to prevent a Detections validation crash on supervision 0.18.
There was a problem hiding this comment.
Pull request overview
Updates draw_detections to align with the pinned supervision dependency (0.18.x), avoiding an exception-on-every-call compatibility path and preventing crashes when no detections are present.
Changes:
- Add an early return when
boxesis empty to avoidsv.Detectionsvalidation failures. - Replace the nested try/except compatibility logic with direct
BoxAnnotator+LabelAnnotatorusage. - Configure label rendering via
LabelAnnotatorparameters.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| box_annotator = sv.BoxAnnotator() | ||
| ann_image = box_annotator.annotate(scene=image, detections=detections) | ||
|
|
||
| label_annotator = sv.LabelAnnotator() | ||
| ann_image = label_annotator.annotate( | ||
| scene=ann_image, detections=detections, labels=labels | ||
| ) | ||
| label_annotator = sv.LabelAnnotator( | ||
| text_scale=0.7, text_thickness=1, text_padding=2 | ||
| ) |
There was a problem hiding this comment.
The docstring still says this function "Adapts to different supervision versions", but the version-conditional logic has been removed and the implementation now assumes the current supervision API (BoxAnnotator + LabelAnnotator). Please update the docstring to reflect the supported supervision version(s) and the current annotator approach to avoid misleading callers.
…equirement Updated documentation to specify requirements for supervision.
|
Closing since there is no associated issue (feel free to reopen after creting the corresponding issue) |
…s guard
The previous try/except pattern always attempted the old supervision API first, guaranteeing an exception on every call with supervision>=0.18. Replaced with a clean direct call using BoxAnnotator and LabelAnnotator. Also added an early return when boxes is empty to prevent a Detections validation crash on supervision 0.18.