Drawing#
draw_points
#
draw_points(frame, drawables=None, radius=None, thickness=None, color='by_id', color_by_label=None, draw_labels=True, text_size=None, draw_ids=True, draw_points=True, text_thickness=None, text_color=None, hide_dead_points=True, detections=None, label_size=None, draw_scores=False)
#
Draw the points included in a list of Detections or TrackedObjects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to draw on. Modified in place. |
required |
drawables |
Union[Sequence[Detection], Sequence[TrackedObject]]
|
List of objects to draw, Detections and TrackedObjects are accepted. |
None
|
radius |
Optional[int]
|
Radius of the circles representing each point. By default a sensible value is picked considering the frame size. |
None
|
thickness |
Optional[int]
|
Thickness or width of the line. |
None
|
color |
ColorLike
|
This parameter can take:
If using |
'by_id'
|
color_by_label |
bool
|
Deprecated. set |
None
|
draw_labels |
bool
|
If set to True, the label is added to a title that is drawn on top of the box. If an object doesn't have a label this parameter is ignored. |
True
|
draw_scores |
bool
|
If set to True, the score is added to a title that is drawn on top of the box. If an object doesn't have a label this parameter is ignored. |
False
|
text_size |
Optional[int]
|
Size of the title, the value is used as a multiplier of the base size of the font. By default the size is scaled automatically based on the frame size. |
None
|
draw_ids |
bool
|
If set to True, the id is added to a title that is drawn on top of the box. If an object doesn't have an id this parameter is ignored. |
True
|
draw_points |
bool
|
Set to False to hide the points and just draw the text. |
True
|
text_thickness |
Optional[int]
|
Thickness of the font. By default it's scaled with the |
None
|
text_color |
Optional[ColorLike]
|
Color of the text. By default the same color as the box is used. |
None
|
hide_dead_points |
bool
|
Set this param to False to always draw all points, even the ones considered "dead".
A point is "dead" when the corresponding value of |
True
|
detections |
Sequence[Detection]
|
Deprecated. use drawables. |
None
|
label_size |
Optional[int]
|
Deprecated. text_size. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
The resulting frame. |
Source code in norfair/drawing/draw_points.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 172 173 174 175 176 177 178 |
|
draw_tracked_objects(frame, objects, radius=None, color=None, id_size=None, id_thickness=None, draw_points=True, color_by_label=False, draw_labels=False, label_size=None)
#
Deprecated use draw_points
Source code in norfair/drawing/draw_points.py
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 |
|
draw_boxes
#
draw_boxes(frame, drawables=None, color='by_id', thickness=None, random_color=None, color_by_label=None, draw_labels=False, text_size=None, draw_ids=True, text_color=None, text_thickness=None, draw_box=True, detections=None, line_color=None, line_width=None, label_size=None, draw_scores=False)
#
Draw bounding boxes corresponding to Detections or TrackedObjects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to draw on. Modified in place. |
required |
drawables |
Union[Sequence[Detection], Sequence[TrackedObject]]
|
List of objects to draw, Detections and TrackedObjects are accepted.
This objects are assumed to contain 2 bi-dimensional points defining
the bounding box as |
None
|
color |
ColorLike
|
This parameter can take:
If using |
'by_id'
|
thickness |
Optional[int]
|
Thickness or width of the line. |
None
|
random_color |
bool
|
Deprecated. Set color="random". |
None
|
color_by_label |
bool
|
Deprecated. Set color="by_label". |
None
|
draw_labels |
bool
|
If set to True, the label is added to a title that is drawn on top of the box. If an object doesn't have a label this parameter is ignored. |
False
|
draw_scores |
bool
|
If set to True, the score is added to a title that is drawn on top of the box. If an object doesn't have a label this parameter is ignored. |
False
|
text_size |
Optional[float]
|
Size of the title, the value is used as a multiplier of the base size of the font. By default the size is scaled automatically based on the frame size. |
None
|
draw_ids |
bool
|
If set to True, the id is added to a title that is drawn on top of the box. If an object doesn't have an id this parameter is ignored. |
True
|
text_color |
Optional[ColorLike]
|
Color of the text. By default the same color as the box is used. |
None
|
text_thickness |
Optional[int]
|
Thickness of the font. By default it's scaled with the |
None
|
draw_box |
bool
|
Set to False to hide the box and just draw the text. |
True
|
detections |
Sequence[Detection]
|
Deprecated. Use drawables. |
None
|
line_color |
Optional[ColorLike]
|
Deprecated. Use color. |
None
|
line_width |
Optional[int]
|
Deprecated. Use thickness. |
None
|
label_size |
Optional[int]
|
Deprecated. Use text_size. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
The resulting frame. |
Source code in norfair/drawing/draw_boxes.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 172 173 174 175 176 177 178 179 180 181 |
|
draw_tracked_boxes(frame, objects, border_colors=None, border_width=None, id_size=None, id_thickness=None, draw_box=True, color_by_label=False, draw_labels=False, label_size=None, label_width=None)
#
Deprecated. Use draw_box
Source code in norfair/drawing/draw_boxes.py
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 |
|
color
#
Color
#
Contains predefined colors.
Colors are defined as a Tuple of integers between 0 and 255 expressing the values in BGR This is the format opencv uses.
Source code in norfair/drawing/color.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 172 173 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 |
|
Palette
#
Class to control the color pallete for drawing.
Examples:
Change palette:
>>> from norfair import Palette
>>> Palette.set("colorblind")
>>> # or a custom palette
>>> from norfair import Color
>>> Palette.set([Color.red, Color.blue, "#ffeeff"])
Source code in norfair/drawing/color.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
set(palette)
classmethod
#
Selects a color palette.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
palette |
Union[str, Iterable[ColorLike]]
|
can be either
- the name of one of the predefined palettes |
required |
Source code in norfair/drawing/color.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
set_default_color(color)
classmethod
#
Selects the default color of choose_color
when hashable is None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color |
ColorLike
|
The new default color. |
required |
Source code in norfair/drawing/color.py
355 356 357 358 359 360 361 362 363 364 365 |
|
hex_to_bgr(hex_value)
#
Converts conventional 6 digits hex colors to BGR tuples
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hex_value |
str
|
hex value with leading |
required |
Returns:
Type | Description |
---|---|
Tuple[int, int, int]
|
BGR values |
Raises:
Type | Description |
---|---|
ValueError
|
if the string is invalid |
Source code in norfair/drawing/color.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 34 35 36 37 38 39 40 41 |
|
parse_color(color_like)
#
Makes best effort to parse the given value to a Color
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_like |
ColorLike
|
Can be one of:
|
required |
Returns:
Type | Description |
---|---|
Color
|
The BGR tuple. |
Source code in norfair/drawing/color.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
path
#
Paths
#
Class that draws the paths taken by a set of points of interest defined from the coordinates of each tracker estimation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
get_points_to_draw |
Optional[Callable[[array], array]]
|
Function that takes a list of points (the By default it is the mean point of all the points in the tracker. |
None
|
thickness |
Optional[int]
|
Thickness of the circles representing the paths of interest. |
None
|
color |
Optional[Tuple[int, int, int]]
|
Color of the circles representing the paths of interest. |
None
|
radius |
Optional[int]
|
Radius of the circles representing the paths of interest. |
None
|
attenuation |
float
|
A float number in [0, 1] that dictates the speed at which the path is erased.
if it is |
0.01
|
Examples:
>>> from norfair import Tracker, Video, Path
>>> video = Video("video.mp4")
>>> tracker = Tracker(...)
>>> path_drawer = Path()
>>> for frame in video:
>>> detections = get_detections(frame) # runs detector and returns Detections
>>> tracked_objects = tracker.update(detections)
>>> frame = path_drawer.draw(frame, tracked_objects)
>>> video.write(frame)
Source code in norfair/drawing/path.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
draw(frame, tracked_objects)
#
Draw the paths of the points interest on a frame.
Warning
This method does not draw frames in place as other drawers do, the resulting frame is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to draw on. |
required |
tracked_objects |
Sequence[TrackedObject]
|
List of |
required |
Returns:
Type | Description |
---|---|
array
|
The resulting frame. |
Source code in norfair/drawing/path.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
AbsolutePaths
#
Class that draws the absolute paths taken by a set of points.
Works just like Paths
but supports camera motion.
Warning
This drawer is not optimized so it can be stremely slow. Performance degrades linearly with
max_history * number_of_tracked_objects
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
get_points_to_draw |
Optional[Callable[[array], array]]
|
Function that takes a list of points (the By default it is the mean point of all the points in the tracker. |
None
|
thickness |
Optional[int]
|
Thickness of the circles representing the paths of interest. |
None
|
color |
Optional[Tuple[int, int, int]]
|
Color of the circles representing the paths of interest. |
None
|
radius |
Optional[int]
|
Radius of the circles representing the paths of interest. |
None
|
max_history |
int
|
Number of past points to include in the path. High values make the drawing slower |
20
|
Examples:
>>> from norfair import Tracker, Video, Path
>>> video = Video("video.mp4")
>>> tracker = Tracker(...)
>>> path_drawer = Path()
>>> for frame in video:
>>> detections = get_detections(frame) # runs detector and returns Detections
>>> tracked_objects = tracker.update(detections)
>>> frame = path_drawer.draw(frame, tracked_objects)
>>> video.write(frame)
Source code in norfair/drawing/path.py
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 172 173 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 |
|
fixed_camera
#
FixedCamera
#
Class used to stabilize video based on the camera motion.
Starts with a larger frame, where the original frame is drawn on top of a black background. As the camera moves, the smaller frame moves in the opposite direction, stabilizing the objects in it.
Useful for debugging or demoing the camera motion.
Warning
This only works with TranslationTransformation
,
using HomographyTransformation
will result in
unexpected behaviour.
Warning
If using other drawers, always apply this one last. Using other drawers on the scaled up frame will not work as expected.
Note
Sometimes the camera moves so far from the original point that the result won't fit in the scaled-up frame. In this case, a warning will be logged and the frames will be cropped to avoid errors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scale |
float
|
The resulting video will have a resolution of |
2
|
attenuation |
float
|
Controls how fast the older frames fade to black. |
0.05
|
Examples:
>>> # setup
>>> tracker = Tracker("frobenious", 100)
>>> motion_estimator = MotionEstimator()
>>> video = Video(input_path="video.mp4")
>>> fixed_camera = FixedCamera()
>>> # process video
>>> for frame in video:
>>> coord_transformations = motion_estimator.update(frame)
>>> detections = get_detections(frame)
>>> tracked_objects = tracker.update(detections, coord_transformations)
>>> draw_tracked_objects(frame, tracked_objects) # fixed_camera should always be the last drawer
>>> bigger_frame = fixed_camera.adjust_frame(frame, coord_transformations)
>>> video.write(bigger_frame)
Source code in norfair/drawing/fixed_camera.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 |
|
adjust_frame(frame, coord_transformation)
#
Render scaled up frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame. |
required |
coord_transformation |
TranslationTransformation
|
The coordinate transformation as returned by the |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The new bigger frame with the original frame drawn on it. |
Source code in norfair/drawing/fixed_camera.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 |
|
absolute_grid
#
draw_absolute_grid(frame, coord_transformations, grid_size=20, radius=2, thickness=1, color=Color.black, polar=False)
#
Draw a grid of points in absolute coordinates.
Useful for debugging camera motion.
The points are drawn as if the camera were in the center of a sphere and points are drawn in the intersection of latitude and longitude lines over the surface of the sphere.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame |
ndarray
|
The OpenCV frame to draw on. |
required |
coord_transformations |
CoordinatesTransformation
|
The coordinate transformation as returned by the |
required |
grid_size |
int
|
How many points to draw. |
20
|
radius |
int
|
Size of each point. |
2
|
thickness |
int
|
Thickness of each point |
1
|
color |
ColorType
|
Color of the points. |
black
|
polar |
Bool
|
If True, the points on the first frame are drawn as if the camera were pointing to a pole (viewed from the center of the earth). By default, False is used which means the points are drawn as if the camera were pointing to the Equator. |
False
|
Source code in norfair/drawing/absolute_grid.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|