Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🚀 Add default color to PolygonZoneAnnotator, drawing functions #1591

Merged
merged 6 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions supervision/detection/tools/polygon_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PolygonZoneAnnotator:

Attributes:
zone (PolygonZone): The polygon zone to be annotated
color (Color): The color to draw the polygon lines
color (Color): The color to draw the polygon lines, default is white
thickness (int): The thickness of the polygon lines, default is 2
text_color (Color): The color of the text on the polygon, default is black
text_scale (float): The scale of the text on the polygon, default is 0.5
Expand All @@ -104,7 +104,7 @@ class PolygonZoneAnnotator:
def __init__(
self,
zone: PolygonZone,
color: Color,
color: Color = Color.WHITE,
thickness: int = 2,
text_color: Color = Color.BLACK,
text_scale: float = 0.5,
Expand Down
26 changes: 18 additions & 8 deletions supervision/draw/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@


def draw_line(
scene: np.ndarray, start: Point, end: Point, color: Color, thickness: int = 2
scene: np.ndarray,
start: Point,
end: Point,
color: Color = Color.ROBOFLOW,
thickness: int = 2,
) -> np.ndarray:
"""
Draws a line on a given scene.
Expand All @@ -18,7 +22,7 @@ def draw_line(
scene (np.ndarray): The scene on which the line will be drawn
start (Point): The starting point of the line
end (Point): The end point of the line
color (Color): The color of the line
color (Color): The color of the line, defaults to Color.ROBOFLOW
thickness (int): The thickness of the line

Returns:
Expand All @@ -35,7 +39,7 @@ def draw_line(


def draw_rectangle(
scene: np.ndarray, rect: Rect, color: Color, thickness: int = 2
scene: np.ndarray, rect: Rect, color: Color = Color.ROBOFLOW, thickness: int = 2
) -> np.ndarray:
"""
Draws a rectangle on an image.
Expand All @@ -60,7 +64,7 @@ def draw_rectangle(


def draw_filled_rectangle(
scene: np.ndarray, rect: Rect, color: Color, opacity: float = 1
scene: np.ndarray, rect: Rect, color: Color = Color.ROBOFLOW, opacity: float = 1
) -> np.ndarray:
"""
Draws a filled rectangle on an image.
Expand Down Expand Up @@ -151,14 +155,17 @@ def draw_rounded_rectangle(


def draw_polygon(
scene: np.ndarray, polygon: np.ndarray, color: Color, thickness: int = 2
scene: np.ndarray,
polygon: np.ndarray,
color: Color = Color.ROBOFLOW,
thickness: int = 2,
) -> np.ndarray:
"""Draw a polygon on a scene.

Parameters:
scene (np.ndarray): The scene to draw the polygon on.
polygon (np.ndarray): The polygon to be drawn, given as a list of vertices.
color (Color): The color of the polygon.
color (Color): The color of the polygon. Defaults to Color.ROBOFLOW.
thickness (int): The thickness of the polygon lines, by default 2.

Returns:
Expand All @@ -171,14 +178,17 @@ def draw_polygon(


def draw_filled_polygon(
scene: np.ndarray, polygon: np.ndarray, color: Color, opacity: float = 1
scene: np.ndarray,
polygon: np.ndarray,
color: Color = Color.ROBOFLOW,
opacity: float = 1,
) -> np.ndarray:
"""Draw a filled polygon on a scene.

Parameters:
scene (np.ndarray): The scene to draw the polygon on.
polygon (np.ndarray): The polygon to be drawn, given as a list of vertices.
color (Color): The color of the polygon.
color (Color): The color of the polygon. Defaults to Color.ROBOFLOW.
opacity (float): The opacity of polygon when drawn on the scene.

Returns:
Expand Down