Utils
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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
draw_rectangle¶
Draws a rectangle on an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene |
ndarray
|
The scene on which the rectangle will be drawn |
required |
rect |
Rect
|
The rectangle to be drawn |
required |
color |
Color
|
The color of the rectangle |
required |
thickness |
int
|
The thickness of the rectangle border |
2
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The scene with the rectangle drawn on it |
Source code in supervision/draw/utils.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
draw_filled_rectangle¶
Draws a filled rectangle on an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene |
ndarray
|
The scene on which the rectangle will be drawn |
required |
rect |
Rect
|
The rectangle to be drawn |
required |
color |
Color
|
The color of the rectangle |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The scene with the rectangle drawn on it |
Source code in supervision/draw/utils.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
draw_polygon¶
Draw a polygon on a scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene |
ndarray
|
The scene to draw the polygon on. |
required |
polygon |
ndarray
|
The polygon to be drawn, given as a list of vertices. |
required |
color |
Color
|
The color of the polygon. |
required |
thickness |
int
|
The thickness of the polygon lines, by default 2. |
2
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The scene with the polygon drawn on it. |
Source code in supervision/draw/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
draw_text¶
Draw text with background on a scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene |
ndarray
|
A 2-dimensional numpy ndarray representing an image or scene |
required |
text |
str
|
The text to be drawn. |
required |
text_anchor |
Point
|
The anchor point for the text, represented as a Point object with x and y attributes. |
required |
text_color |
Color
|
The color of the text. Defaults to black. |
black()
|
text_scale |
float
|
The scale of the text. Defaults to 0.5. |
0.5
|
text_thickness |
int
|
The thickness of the text. Defaults to 1. |
1
|
text_padding |
int
|
The amount of padding to add around the text when drawing a rectangle in the background. Defaults to 10. |
10
|
text_font |
int
|
The font to use for the text. Defaults to cv2.FONT_HERSHEY_SIMPLEX. |
FONT_HERSHEY_SIMPLEX
|
background_color |
Color
|
The color of the background rectangle, if one is to be drawn. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The input scene with the text drawn on it. |
Examples:
>>> scene = np.zeros((100, 100, 3), dtype=np.uint8)
>>> text_anchor = Point(x=50, y=50)
>>> scene = draw_text(scene=scene, text="Hello, world!",text_anchor=text_anchor)
Source code in supervision/draw/utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
draw_image¶
Draws an image onto a given scene with specified opacity and dimensions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene |
ndarray
|
Background image where the new image will be drawn. |
required |
image |
Union[str, ndarray]
|
Image to draw. |
required |
opacity |
float
|
Opacity of the image to be drawn. |
required |
rect |
Rect
|
Rectangle specifying where to draw the image. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The updated scene. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the image path does not exist. |
ValueError
|
For invalid opacity or rectangle dimensions. |
Source code in supervision/draw/utils.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
calculate_dynamic_font_scale¶
Calculate a dynamic font scale based on the resolution of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution_wh |
Tuple[int, int]
|
A tuple representing the width and height of the image. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The calculated font scale factor. |
Source code in supervision/draw/utils.py
236 237 238 239 240 241 242 243 244 245 246 247 |
|
calculate_dynamic_line_thickness¶
Calculate a dynamic line thickness based on the resolution of an image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resolution_wh |
Tuple[int, int]
|
A tuple representing the width and height of the image. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The calculated line thickness in pixels. |
Source code in supervision/draw/utils.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|