Tracker#
Tracker
#
The class in charge of performing the tracking of the detections produced by a detector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance_function |
Union[str, Callable[[Detection, TrackedObject], float]]
|
Function used by the tracker to determine the distance between newly detected objects and the objects that are currently being tracked.
This function should take 2 input arguments, the first being a Detection, and the second a TrackedObject.
It has to return a |
required |
distance_threshold |
float
|
Defines what is the maximum distance that can constitute a match. Detections and tracked objects whose distances are above this threshold won't be matched by the tracker. |
required |
hit_counter_max |
int, optional
|
Each tracked objects keeps an internal hit counter which tracks how often it's getting matched to a detection, each time it gets a match this counter goes up, and each time it doesn't it goes down. If it goes below 0 the object gets destroyed. This argument defines how large this inertia can grow, and therefore defines how long an object can live without getting matched to any detections, before it is displaced as a dead object, if no ReID distance function is implemented it will be destroyed. |
15
|
initialization_delay |
Optional[int], optional
|
Determines how large the object's hit counter must be in order to be considered as initialized, and get returned to the user as a real object.
It must be smaller than If set to 0, objects will get returned to the user as soon as they are detected for the first time, which can be problematic as this can result in objects appearing and immediately dissapearing. Defaults to |
None
|
pointwise_hit_counter_max |
int, optional
|
Each tracked object keeps track of how often the points it's tracking have been getting matched.
Points that are getting matched ( This is used to determine things like which individual points in a tracked object get drawn by |
4
|
detection_threshold |
float, optional
|
Sets the threshold at which the scores of the points in a detection being fed into the tracker must dip below to be ignored by the tracker. |
0
|
filter_factory |
FilterFactory, optional
|
This parameter can be used to change what filter the |
OptimizedKalmanFilterFactory()
|
past_detections_length |
int, optional
|
How many past detections to save for each tracked object. Norfair tries to distribute these past detections uniformly through the object's lifetime so they're more representative. Very useful if you want to add metric learning to your model, as you can associate an embedding to each detection and access them in your distance function. |
4
|
reid_distance_function |
Optional[Callable[[TrackedObject, TrackedObject], float]]
|
Function used by the tracker to determine the ReID distance between newly detected trackers and unmatched trackers by the distance function. This function should take 2 input arguments, the first being tracked objects in the initialization phase of type |
None
|
reid_distance_threshold |
float
|
Defines what is the maximum ReID distance that can constitute a match. Tracked objects whose distance is above this threshold won't be merged, if they are the oldest tracked object will be maintained with the position of the new tracked object. |
0
|
reid_hit_counter_max |
Optional[int]
|
Each tracked object keeps an internal ReID hit counter which tracks how often it's getting recognized by another tracker,
each time it gets a match this counter goes up, and each time it doesn't it goes down. If it goes below 0 the object gets destroyed.
If used, this argument ( |
None
|
Source code in norfair/tracker.py
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 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
current_object_count: int
property
#
Number of active TrackedObjects
total_object_count: int
property
#
Total number of TrackedObjects initialized in the by this Tracker
update(detections=None, period=1, coord_transformations=None)
#
Process detections found in each frame.
The detections can be matched to previous tracked objects or new ones will be created according to the configuration of the Tracker. The currently alive and initialized tracked objects are returned
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detections |
Optional[List[Detection]], optional
|
A list of If no detections have been found in the current frame, or the user is purposely skipping frames to improve video processing time, this argument should be set to None or ignored, as the update function is needed to advance the state of the Kalman Filters inside the tracker. |
None
|
period |
int, optional
|
The user can chose not to run their detector on all frames, so as to process video faster. This parameter sets every how many frames the detector is getting ran, so that the tracker is aware of this situation and can handle it properly. This argument can be reset on each frame processed, which is useful if the user is dynamically changing how many frames the detector is skipping on a video when working in real-time. |
1
|
coord_transformations |
Optional[CoordinatesTransformation]
|
The coordinate transformation calculated by the MotionEstimator. |
None
|
Returns:
Type | Description |
---|---|
List[TrackedObject]
|
The list of active tracked objects. |
Source code in norfair/tracker.py
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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
get_active_objects()
#
Get the list of active objects
Returns:
Type | Description |
---|---|
List[TrackedObject]
|
The list of active objects |
Source code in norfair/tracker.py
272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
match_dets_and_objs(distance_matrix, distance_threshold)
#
Matches detections with tracked_objects from a distance matrix
I used to match by minimizing the global distances, but found several cases in which this was not optimal. So now I just match by starting with the global minimum distance and matching the det-obj corresponding to that distance, then taking the second minimum, and so on until we reach the distance_threshold.
This avoids the the algorithm getting cute with us and matching things that shouldn't be matching just for the sake of minimizing the global distance, which is what used to happen
Source code in norfair/tracker.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
TrackedObject
#
The objects returned by the tracker's update
function on each iteration.
They represent the objects currently being tracked by the tracker.
Users should not instantiate TrackedObjects manually; the Tracker will be in charge of creating them.
Attributes:
Name | Type | Description |
---|---|---|
estimate |
np.ndarray
|
Where the tracker predicts the point will be in the current frame based on past detections. A numpy array with the same shape as the detections being fed to the tracker that produced it. |
id |
Optional[int]
|
The unique identifier assigned to this object by the tracker. Set to |
global_id |
Optional[int]
|
The globally unique identifier assigned to this object. Set to |
last_detection |
Detection
|
The last detection that matched with this tracked object. Useful if you are storing embeddings in your detections and want to do metric learning, or for debugging. |
last_distance |
Optional[float]
|
The distance the tracker had with the last object it matched with. |
age |
int
|
The age of this object measured in number of frames. |
live_points |
A boolean mask with shape Functions like |
|
initializing_id |
int
|
On top of Each new object created by the |
Source code in norfair/tracker.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
|
estimate_velocity: np.ndarray
property
#
Get the velocity estimate of the object from the Kalman filter. This velocity is in the absolute coordinate system.
Returns:
Type | Description |
---|---|
np.ndarray
|
An array of shape (self.num_points, self.dim_points) containing the velocity estimate of the object on each axis. |
estimate: np.ndarray
property
#
Get the position estimate of the object from the Kalman filter.
Returns:
Type | Description |
---|---|
np.ndarray
|
An array of shape (self.num_points, self.dim_points) containing the position estimate of the object on each axis. |
get_estimate(absolute=False)
#
Get the position estimate of the object from the Kalman filter in an absolute or relative format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
absolute |
bool, optional
|
If true the coordinates are returned in absolute format, by default False, by default False. |
False
|
Returns:
Type | Description |
---|---|
np.ndarray
|
An array of shape (self.num_points, self.dim_points) containing the position estimate of the object on each axis. |
Raises:
Type | Description |
---|---|
ValueError
|
Alert if the coordinates are requested in absolute format but the tracker has no coordinate transformation. |
Source code in norfair/tracker.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
|
hit(detection, period=1)
#
Update tracked object with a new detection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
detection |
Detection
|
the new detection matched to this tracked object |
required |
period |
int, optional
|
frames corresponding to the period of time since last update. |
1
|
Source code in norfair/tracker.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
|
merge(tracked_object)
#
Merge with a not yet initialized TrackedObject instance
Source code in norfair/tracker.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 |
|
Detection
#
Detections returned by the detector must be converted to a Detection
object before being used by Norfair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points |
np.ndarray
|
Points detected. Must be a rank 2 array with shape |
required |
scores |
np.ndarray, optional
|
An array of length This is used to inform the tracker of which points to ignore;
any point with a score below This useful for cases in which detections don't always have every point present, as is often the case in pose estimators. |
None
|
data |
Any, optional
|
The place to store any extra data which may be useful when calculating the distance function. Anything stored here will be available to use inside the distance function. This enables the development of more interesting trackers which can do things like assign an appearance embedding to each detection to aid in its tracking. |
None
|
label |
Hashable, optional
|
When working with multiple classes the detection's label can be stored to be used as a matching condition when associating tracked objects with new detections. Label's type must be hashable for drawing purposes. |
None
|
embedding |
Any, optional
|
The embedding for the reid_distance. |
None
|
Source code in norfair/tracker.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
|