Object tracking¶
Object trackers use information from object detectors to track the position and velocity of unique objects in a scene.
API reference¶
This module contains generic components for tracking algorithms.
- class videoanalytics.pipeline.sinks.object_tracking.TrackedObjectsAnnotator(name, context)¶
Annotates the tracked objects in a frame displaying a bounding box around each identified object with its numeric Id.
This component READS the following entries in the global context:
Variable name
Description
TRACKED_OBJS
Output of an object tracker.
FRAME
Numpy array representing the frame.
This component WRITES the following entries in the global context:
Variable name
Description
FRAME
Numpy array representing the frame.
- Parameters
name (str) – the component unique name.
context (dict) – The global context.
- process()¶
This method is called for each active component in the pipeline.
- setup()¶
This method is called after all components from the pipeline are instanced.
- shutdown()¶
This method is called after the process finished.
- class videoanalytics.pipeline.sinks.object_tracking.TrackedObjectsCSVWriter(name, context, filename)¶
Writes the trackings to a CSV file.
This component READS the following entries in the global context:
Variable name
Description
TRACKED_OBJS
Output of an object tracker.
FRAME
Numpy array representing the frame.
- Parameters
name (str) – the component unique name.
context (dict) – The global context.
filename (str) – CSV output file.
- process()¶
This method is called for each active component in the pipeline.
- setup()¶
This method is called after all components from the pipeline are instanced.
- shutdown()¶
This method is called after the process finished.
SORT¶
Implementation of SORT tracking algorithm.
Note
The code included in this module is only a wrapper class for the original paper’s code with minor changes to adjust documentation format or minor refactoring.
- class videoanalytics.pipeline.sinks.object_tracking.sort.SORT(name, context, max_age=1, min_hits=3, iou_threshold=0.3)¶
Wrapper class for the SORT algorithm.
This component READS the following entries in the global context:
Variable name
Description
DETECTIONS
Output of an object detection model.
START_FRAME
Initial frame index.
This component WRITES the following entries in the global context:
Variable name
Description
TRACKED_OBJS
Object trackings.
- Parameters
name (str) – the component unique name.
context (dict) – The global context.
max_age (int) – age limit for a tracklet without being updated before removing it.
min_hits (int) – minimum hits required to start a new track.
iou_threshold (float) – minimum IoU to consider overlapping boxes.
- process()¶
This method is called for each active component in the pipeline.
- setup()¶
This method is called after all components from the pipeline are instanced.
- shutdown()¶
This method is called after the process finished.
- class videoanalytics.pipeline.sinks.object_tracking.sort.Sort(max_age=1, min_hits=3, iou_threshold=0.3)¶
SORT algorithm implementation.
- Parameters
name (str) – the component unique name.
context (dict) – The global context.
max_age (int) – age limit for a tracklet without being updated before removing it.
min_hits (int) – minimum hits required to start a new track.
iou_threshold (float) – minimum IoU to consider overlapping boxes.
- __init__(max_age=1, min_hits=3, iou_threshold=0.3)¶
Sets key parameters for SORT
- update(dets=array([], shape=(0, 5), dtype=float64))¶
Updates the internal state of the tracked objects. This method must be called once for each frame even with empty detections (use np.empty((0, 5)) for frames without detections).
- Parameters
- a numpy array of detections in the format [[x1 (dets) –
y1 –
x2 –
y2 –
score] –
[x1 –
y1 –
x2 –
y2 –
score] –
...] –
- Returns
A similar array, where the last column is the object ID.
Note: The number of objects returned may differ from the number of detections provided.
- videoanalytics.pipeline.sinks.object_tracking.sort.associate_detections_to_trackers(detections, trackers, iou_threshold=0.3)¶
Assigns detections to tracked object (both represented as bounding boxes) Returns 3 lists of matches, unmatched_detections and unmatched_trackers
DeepSORT¶
Implementation of DeepSORT tracking algorithm.
Note
The code included in this module is only a wrapper class for the original paper’s code with minor changes to adjust documentation format or minor refactoring.
- class videoanalytics.pipeline.sinks.object_tracking.deepsort.DeepSORT(name, context, model_filename, max_cosine_distance=0.4, nn_budget=None, max_iou_distance=0.7, max_age=60, n_init=3)¶
Wrapper class for the DeepSORT algorithm.
This component READS the following entries in the global context:
Variable name
Description
DETECTIONS
Output of an object detection model.
START_FRAME
Initial frame index.
This component WRITES the following entries in the global context:
Variable name
Description
TRACKED_OBJS
Object trackings.
- Parameters
name (str) – the component unique name.
context (dict) – The global context.
model_filename (str) – filename for the reidentification model.
- process()¶
This method is called for each active component in the pipeline.
- setup()¶
This method is called after all components from the pipeline are instanced.
- shutdown()¶
This method is called after the process finished.