Reference for ultralytics/solutions/speed_estimation.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/speed_estimation.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.speed_estimation.SpeedEstimator
A class to estimation speed of objects in real-time video stream based on their tracks.
Source code in ultralytics/solutions/speed_estimation.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 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
__init__()
Initializes the speed-estimator class with default values for Visual, Image, track and speed parameters.
Source code in ultralytics/solutions/speed_estimation.py
calculate_speed(trk_id, track)
Calculation of object speed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trk_id |
int
|
object track id. |
required |
track |
list
|
tracking history for tracks path drawing |
required |
Source code in ultralytics/solutions/speed_estimation.py
display_frames()
estimate_speed(im0, tracks, region_color=(255, 0, 0))
Calculate object based on tracking data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0 |
nd array
|
Image |
required |
tracks |
list
|
List of tracks obtained from the object tracking process. |
required |
region_color |
tuple
|
Color to use when drawing regions. |
(255, 0, 0)
|
Source code in ultralytics/solutions/speed_estimation.py
extract_tracks(tracks)
Extracts results from the provided data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tracks |
list
|
List of tracks obtained from the object tracking process. |
required |
Source code in ultralytics/solutions/speed_estimation.py
plot_box_and_track(track_id, box, cls, track)
Plot track and bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track_id |
int
|
object track id. |
required |
box |
list
|
object bounding box data |
required |
cls |
str
|
object class name |
required |
track |
list
|
tracking history for tracks path drawing |
required |
Source code in ultralytics/solutions/speed_estimation.py
set_args(reg_pts, names, view_img=False, line_thickness=2, region_thickness=5, spdl_dist_thresh=10)
Configures the speed estimation and display parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reg_pts |
list
|
Initial list of points defining the speed calculation region. |
required |
names |
dict
|
object detection classes names |
required |
view_img |
bool
|
Flag indicating frame display |
False
|
line_thickness |
int
|
Line thickness for bounding boxes. |
2
|
region_thickness |
int
|
Speed estimation region thickness |
5
|
spdl_dist_thresh |
int
|
Euclidean distance threshold for speed line |
10
|
Source code in ultralytics/solutions/speed_estimation.py
store_track_info(track_id, box)
Store track data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
track_id |
int
|
object track id. |
required |
box |
list
|
object bounding box data |
required |