From 0f76f731eeca8a42e1048bac9a0c594a33db5c79 Mon Sep 17 00:00:00 2001 From: LinasKo Date: Wed, 12 Jun 2024 14:58:48 +0300 Subject: [PATCH] bugfix: ColorAnnotator is now in-place --- supervision/annotators/core.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 8e9d1b55..37544808 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -430,6 +430,7 @@ class ColorAnnotator(BaseAnnotator): supervision-annotator-examples/box-mask-annotator-example-purple.png) """ mask_image = scene.copy() + scene_with_boxes = scene.copy() for detection_idx in range(len(detections)): x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) color = resolve_color( @@ -441,15 +442,17 @@ class ColorAnnotator(BaseAnnotator): else custom_color_lookup, ) cv2.rectangle( - img=scene, + img=scene_with_boxes, pt1=(x1, y1), pt2=(x2, y2), color=color.as_bgr(), thickness=-1, ) - scene = cv2.addWeighted( - scene, self.opacity, mask_image, 1 - self.opacity, gamma=0 + + blended_scene = cv2.addWeighted( + scene_with_boxes, self.opacity, mask_image, 1 - self.opacity, gamma=0 ) + np.copyto(scene, blended_scene) return scene