swarmsort.core module
SwarmSort Core Implementation
This module contains the core SwarmSort multi-object tracking algorithm implementation. SwarmSort combines Kalman filtering, Hungarian algorithm assignment, and deep learning embeddings for robust real-time object tracking.
- Classes:
SwarmSortTracker: Main tracking class implementing the full algorithm
- class swarmsort.core.SwarmSortTracker(config=None, embedding_type=None, use_gpu=None, **kwargs)[source]
Bases:
objectMain SwarmSort multi-object tracker implementation.
This class implements a sophisticated tracking algorithm that combines: - Kalman filtering for motion prediction - Hungarian/Greedy assignment for detection-track matching - Deep learning embeddings for appearance-based matching - Re-identification for recovering lost tracks
- __init__(config=None, embedding_type=None, use_gpu=None, **kwargs)[source]
Initialize the SwarmSort tracker with configuration.
- Parameters:
config (
Union[SwarmSortConfig,dict,None]) – Configuration object or dictionaryembedding_type (
Optional[str]) – Type of embedding extractor to use (overrides config)use_gpu (
Optional[bool]) – Whether to use GPU for embeddings (overrides config)**kwargs – Additional keyword arguments (ignored for compatibility)
- property frame_count
Get current frame count.
- get_statistics()[source]
Get tracker statistics for benchmarking and analysis.
- Returns:
next_id: Next track ID to be assigned (= total tracks created)
active_tracks: Number of currently active tracks
confirmed_tracks: Number of confirmed tracks
pending_detections: Number of pending detections
frame_count: Total frames processed
- Return type:
Dictionary containing
- reset()[source]
Reset the tracker to initial state.
This clears all tracks, pending detections, and resets the embedding scaler statistics. Use when starting a new video or scene.
- update(detections)[source]
Main update function for the tracker.
- Parameters:
detections (
List[Detection]) – List of Detection objects for current frame- Return type:
- Returns:
List of TrackedObject instances representing current tracks
- Raises:
TypeError – If detections is not a list
ValueError – If any detection has invalid data