cv2ext.tracking package

Subpackages

Module contents

Submodule containing tools for tracking objects in videos.

Submodules

cv_trackers

Contains the wrapped OpenCV trackers.

trackers

Contains trackers implemented in cv2ext.

Classes

AbstractTracker

An abstract class for tracking objects in videos.

AbstractMultiTracker

An abstract class for tracking multiple objects in videos.

CVTrackerInterface

A class for making OpenCV trackers compatible with the AbstractTracker interface.

MultiTracker

A class for tracking multiple objects in videos.

TrackerType

An enumeration of the available tracker types.

MultiTrackerType

An enumeration of available multi-tracker types without MultiTracker wrapper.

Tracker

A generic class, which allows many tracking algorithm backends.

class cv2ext.tracking.AbstractMultiTracker[source]

Bases: ABC

abstract init(image: np.ndarray, bboxes: list[tuple[int, int, int, int]]) None[source]
abstract update(image: np.ndarray) list[tuple[bool, tuple[int, int, int, int]]][source]
class cv2ext.tracking.AbstractTracker[source]

Bases: ABC

abstract init(image: np.ndarray, bbox: tuple[int, int, int, int]) None[source]
abstract update(image: np.ndarray) tuple[bool, tuple[int, int, int, int]][source]
class cv2ext.tracking.CVTrackerInterface(tracker: cv2.Tracker)[source]

Bases: AbstractTracker

class cv2ext.tracking.MultiTracker(tracker_type: TrackerType | type[AbstractTracker] = TrackerType.KCF, *, use_threads: bool | None = None)[source]

Bases: AbstractMultiTracker

Handles multiple trackers for tracking multiple objects in a video.

init(image: np.ndarray, bboxes: list[tuple[int, int, int, int]]) None[source]

Initialize the trackers with the initial bounding boxes.

Parameters:
  • image (np.ndarray) – The first frame of the video.

  • bboxes (list[tuple[int, int, int, int]]) – The initial bounding boxes of the targets. Each bbox is represented as (x1, y1, x2, y2).

update(image: np.ndarray) list[tuple[bool, tuple[int, int, int, int]]][source]

Update the trackers with the next frame of the video.

Parameters:

image (np.ndarray) – The next frame of the video.

Returns:

The updated success values and bounding boxes of the targets. Each bbox is represented as (x1, y1, x2, y2).

Return type:

list[tuple[bool, tuple[int, int, int, int]]]

class cv2ext.tracking.MultiTrackerType(value)[source]

Bases: Enum

An enumeration of available multi-tracker types without MultiTracker wrapper.

KLT = <class 'cv2ext.tracking.trackers._klt.KLTMultiTracker'>
class cv2ext.tracking.Tracker(tracker: TrackerType = TrackerType.MIL)[source]

Bases: AbstractTracker

Handles tracking an object in a video.

init(image: np.ndarray, bbox: tuple[int, int, int, int]) None[source]

Initialize the tracker with an image and bounding box.

Parameters:
  • image (np.ndarray) – The image to use for tracking.

  • bbox (tuple[int, int, int, int]) – The bounding box of the object to track. Bounding box is format (x, y, x, y), where (x, y) is the top-left/bottom-right corner of the box.

update(image: np.ndarray) tuple[bool, tuple[int, int, int, int]][source]

Update the tracker with a new image.

Parameters:

image (np.ndarray) – The new image to use for tracking.

Returns:

A tuple containing a boolean indicating if the update was successful and a tuple containing the bounding box of the tracked object.

Return type:

tuple[bool, tuple[int, int, int, int]]

class cv2ext.tracking.TrackerType(value)[source]

Bases: Enum

An enumeration of the available tracker types.

BOOSTING = <class 'cv2ext.tracking.cv_trackers._boosting.BoostingTracker'>
CSRT = <class 'cv2ext.tracking.cv_trackers._csrt.CSRTTracker'>
KCF = <class 'cv2ext.tracking.cv_trackers._kcf.KCFTracker'>
MEDIAN_FLOW = <class 'cv2ext.tracking.cv_trackers._medianflow.MedianFlowTracker'>
MIL = <class 'cv2ext.tracking.cv_trackers._mil.MILTracker'>
MOSSE = <class 'cv2ext.tracking.cv_trackers._mosse.MOSSETracker'>
TLD = <class 'cv2ext.tracking.cv_trackers._tld.TLDTracker'>
KLT = <class 'cv2ext.tracking.trackers._klt.KLTTracker'>