Skip to content

Draw

draw_line

Draws a line on a given scene.

Parameters:

Name Type Description Default
scene ndarray

The scene on which the line will be drawn

required
start Point

The starting point of the line

required
end Point

The end point of the line

required
color Color

The color of the line

required
thickness int

The thickness of the line

2

Returns:

Type Description
ndarray

np.ndarray: The scene with the line drawn on it

Source code in supervision/draw/utils.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def draw_line(
    scene: np.ndarray, start: Point, end: Point, color: Color, thickness: int = 2
) -> np.ndarray:
    """
    Draws a line on a given scene.

    Parameters:
        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
        thickness (int): The thickness of the line

    Returns:
        np.ndarray: The scene with the line drawn on it
    """
    cv2.line(
        scene,
        start.as_xy_int_tuple(),
        end.as_xy_int_tuple(),
        color.as_bgr(),
        thickness=thickness,
    )
    return scene

draw_rectangle

Draws a rectangle on an image.

Attributes:

Name Type Description
scene ndarray

The scene on which the rectangle will be drawn

rect Rect

The rectangle to be drawn

color Color

The color of the rectangle

thickness int

The thickness of the rectangle border

Returns:

Type Description
ndarray

np.ndarray: The scene with the rectangle drawn on it

Source code in supervision/draw/utils.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def draw_rectangle(
    scene: np.ndarray, rect: Rect, color: Color, thickness: int = 2
) -> np.ndarray:
    """
    Draws a rectangle on an image.

    Attributes:
        scene (np.ndarray): The scene on which the rectangle will be drawn
        rect (Rect): The rectangle to be drawn
        color (Color): The color of the rectangle
        thickness (int): The thickness of the rectangle border

    Returns:
        np.ndarray: The scene with the rectangle drawn on it
    """
    cv2.rectangle(
        scene,
        rect.top_left.as_xy_int_tuple(),
        rect.bottom_right.as_xy_int_tuple(),
        color.as_bgr(),
        thickness=thickness,
    )
    return scene