diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index dd585317..b1f0793a 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -833,7 +833,7 @@ class DotAnnotator(BaseAnnotator): radius: int = 5, position: Position = Position.CENTER, color_lookup: ColorLookup = ColorLookup.CLASS, - outer_thickness : int = 0 + outer_thickness: int = 0, ): """ Args: @@ -901,7 +901,7 @@ class DotAnnotator(BaseAnnotator): ) center = (int(xy[detection_idx, 0]), int(xy[detection_idx, 1])) cv2.circle(scene, center, self.radius, color.as_bgr(), -1) - cv2.circle(scene, center, self.radius, (0,0,0), self.outer_thickness) + cv2.circle(scene, center, self.radius, (0, 0, 0), self.outer_thickness) return scene @@ -1674,7 +1674,7 @@ class TriangleAnnotator(BaseAnnotator): ![triangle-annotator-example](https://media.roboflow.com/ supervision-annotator-examples/triangle-annotator-example.png) """ - if (self.outline_thickness): + if self.outline_thickness: for detection_idx in range(len(detections)): x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) color = resolve_color( @@ -1686,20 +1686,47 @@ class TriangleAnnotator(BaseAnnotator): else custom_color_lookup, ) - midpoint_top = ((x1 + x2) // 2, (y1 + y1) // 2) #midpoint((x1, y1), (x2, y1)) + midpoint_top = ( + (x1 + x2) // 2, + (y1 + y1) // 2, + ) # midpoint((x1, y1), (x2, y1)) - #shifted origin/centroid - cen2 = (midpoint_top[0], midpoint_top[1]-18) - tri_vertices = np.array([[cen2[0], cen2[1]+12], - [cen2[0]-10, cen2[1]-10], - [cen2[0]+10, cen2[1]-10]]) + # shifted origin/centroid + cen2 = (midpoint_top[0], midpoint_top[1] - 18) + tri_vertices = np.array( + [ + [cen2[0], cen2[1] + 12], + [cen2[0] - 10, cen2[1] - 10], + [cen2[0] + 10, cen2[1] - 10], + ] + ) - #upperhead pointer - cv2.drawContours(scene, [tri_vertices], -1, color.as_bgr(), thickness=-1) #BGR -->(0,255,232) - cv2.line(scene, ([cen2[0], cen2[1]+12]), ([cen2[0]-10, cen2[1]-10]), (0,0,0), self.outline_thickness) - cv2.line(scene, [cen2[0]-10, cen2[1]-10], [cen2[0]+10, cen2[1]-10], (0,0,0), self.outline_thickness) - cv2.line(scene, [cen2[0]+10, cen2[1]-10], [cen2[0], cen2[1]+12], (0,0,0), self.outline_thickness) - else: + # upperhead pointer + cv2.drawContours( + scene, [tri_vertices], -1, color.as_bgr(), thickness=-1 + ) # BGR -->(0,255,232) + cv2.line( + scene, + ([cen2[0], cen2[1] + 12]), + ([cen2[0] - 10, cen2[1] - 10]), + (0, 0, 0), + self.outline_thickness, + ) + cv2.line( + scene, + [cen2[0] - 10, cen2[1] - 10], + [cen2[0] + 10, cen2[1] - 10], + (0, 0, 0), + self.outline_thickness, + ) + cv2.line( + scene, + [cen2[0] + 10, cen2[1] - 10], + [cen2[0], cen2[1] + 12], + (0, 0, 0), + self.outline_thickness, + ) + else: xy = detections.get_anchors_coordinates(anchor=self.position) for detection_idx in range(len(detections)): color = resolve_color( @@ -1719,7 +1746,7 @@ class TriangleAnnotator(BaseAnnotator): ], np.int32, ) - + cv2.fillPoly(scene, [vertices], color.as_bgr()) return scene