ObjectTracking

class CorrelationTracker(max_objects=None, deregister_frames=30, max_distance=50, enter_cb=None, exit_cb=None)

Track objects based on a correlation tracking algorithm.

Typical usage:

obj_detect = edgeiq.ObjectDetection(
        'alwaysai/res10_300x300_ssd_iter_140000')
obj_detect.load(engine=edgeiq.Engine.DNN)

tracker = edgeiq.CorrelationTracker()

while True:
    <get video frame>
    results = obj_detect.detect_objects(frame)

    objects = tracker.update(results.predictions, frame)

    # Use the object dictionary to create a new prediction list
    for (object_id, prediction) in objects.items():
        new_label = 'object {}'.format(object_id)
        prediction.label = new_label
        predictions.append(prediction)

    frame = edgeiq.markup_image(frame, predictions)
Parameters
  • max_objects (integer) – The maximum number of objects to track.

  • deregister_frames (integer) – The number of frames before deregistering an object that can no longer be found.

  • max_distance (integer) – The maximum distance between two centroids to associate an object.

  • enter_cb (function that takes the object ID and ObjectDetectionPrediction as arguments.) – A callback function to be called each time a new object is detected.

  • exit_cb (function that takes the object ID and ObjectDetectionPrediction as arguments.) – A callback function to be called each time an existing object is removed from the tracking list. This event occurs deregister_frames after the object is last detected.

update(predictions, image)

Update tracked objects based on a new set of predictions and a new image.

Parameters

predictions (list of ObjectDetectionPrediction) – The list of bounding boxes to track.

Returns

A dictionary with object ID as the key and the ObjectDetectionPrediction as the value.

class CentroidTracker(deregister_frames=30, max_distance=50, enter_cb=None, exit_cb=None)

Associate a bounding box with an object ID based on distances from previous detections.

Typical usage:

obj_detect = edgeiq.ObjectDetection(
        'alwaysai/res10_300x300_ssd_iter_140000')
obj_detect.load(engine=edgeiq.Engine.DNN)

centroid_tracker = edgeiq.CentroidTracker(
        deregister_frames=20, max_distance=50)

while True:
    <get video frame>
    results = obj_detect.detect_objects(frame)

    objects = centroid_tracker.update(results.predictions)

    # Use the object dictionary to create a new prediction list
    for (object_id, prediction) in objects.items():
        new_label = 'object {}'.format(object_id)
        prediction.label = new_label
        predictions.append(prediction)

    frame = edgeiq.markup_image(frame, predictions)
Parameters
  • deregister_frames (integer) – The number of frames before deregistering an object that can no longer be found.

  • max_distance (integer) – The maximum distance between two centroids to associate an object.

  • enter_cb (function that takes the object ID and ObjectDetectionPrediction as arguments.) – A callback function to be called each time a new object is detected.

  • exit_cb (function that takes the object ID and ObjectDetectionPrediction as arguments.) – A callback function to be called each time an existing object is removed from the tracking list. This event occurs deregister_frames after the object is last detected.

update(predictions)

Update tracked objects based on a new set of predictions.

Parameters

predictions (list of ObjectDetectionPrediction) – The list of bounding boxes to track.

Returns

A dictionary with object ID as the key and the ObjectDetectionPrediction as the value.