sportslabkit.matching.base#

assignment cost calculation & matching methods.

Overview#

Classes#

BaseMatchingFunction

A base class for matching functions.

Function#

linear_sum_assignment_with_inf(cost_matrix)

Solve the linear sum assignment problem with inf values.

Attributes#

EPS

-

Classes#

class sportslabkit.matching.base.BaseMatchingFunction[source]#

Bases: abc.ABC

A base class for matching functions.

A matching function takes a list of trackers and a list of detections and returns a list of matches. Subclasses should implement the compute_cost_matrix() method.

Overview

Methods#

compute_cost_matrix(trackers, detections)

abc Calculate the matching cost between trackers and detections.

match_cost_matrix(cost_matrix)

Match trackers and detections based on a cost matrix.

Members

abstract compute_cost_matrix(trackers: collections.abc.Sequence[sportslabkit.Tracklet], detections: collections.abc.Sequence[sportslabkit.types.detection.Detection]) numpy.ndarray[source]#

Calculate the matching cost between trackers and detections.

Parameters:
  • trackers – A list of trackers.

  • detections – A list of detections.

Returns:

A 2D numpy array of matching costs between trackers and detections.

match_cost_matrix(cost_matrix: numpy.ndarray) numpy.ndarray[source]#

Match trackers and detections based on a cost matrix.

While this method implements a hungarian algorithm, it is can be overriden by subclasses that implement different matching strategies. :param cost_matrix: A 2D numpy array of matching costs between trackers and detections.

Returns:

A 2D numpy array of shape (n, 2) containing indices of matching pairs of trackers and detections.

Functions#

sportslabkit.matching.base.linear_sum_assignment_with_inf(cost_matrix: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]#

Solve the linear sum assignment problem with inf values.

Parameters:

cost_matrix (np.ndarray) – The cost matrix to solve.

Raises:
  • ValueError – Raises an error if the cost matrix contains both inf and -inf.

  • ValueError – Raises an error if the cost matrix contains only inf or -inf.

Returns:

The row and column indices of the assignment.

Return type:

Tuple[np.ndarray, np.ndarray]

Attributes#

sportslabkit.matching.base.EPS = 1e-07[source]#