Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kornia Kornia BoxMOT Tracker

From Leeroopedia


Knowledge Sources
Domains Vision, Object_Tracking
Last Updated 2026-02-09 15:00 GMT

Overview

Wraps a detector and a multi-object tracker from the BoxMot library to provide end-to-end object tracking on video frames.

Description

The BoxMotTracker class in the Kornia contrib package combines an object detector (by default RT-DETR) with a multi-object tracker from the BoxMot library. It supports multiple tracker algorithms including BoTSORT, DeepOCSORT, OCSORT, HybridSORT, ByteTrack, StrongSORT, and ImprAssoc. The class provides an update method to feed new frames, a visualize method to render tracking trajectories, and a save method to write output images to disk. The tracker requires at least 4 frames to initialize tracking positions.

Usage

Import this module when you need to perform multi-object tracking across video frames, combining a detector with a tracking algorithm that maintains object identities across frames.

Code Reference

Source Location

Signature

class BoxMotTracker:
    def __init__(
        self,
        detector: Union[ObjectDetector, str] = "rtdetr_r18vd",
        tracker_model_name: str = "DeepOCSORT",
        tracker_model_weights: str = "osnet_x0_25_msmt17.pt",
        device: str = "cpu",
        fp16: bool = False,
        **kwargs: Any,
    ) -> None: ...

    def update(self, image: torch.Tensor) -> None: ...

    def visualize(self, image: torch.Tensor, show_trajectories: bool = True) -> torch.Tensor: ...

    def save(self, image: torch.Tensor, show_trajectories: bool = True,
             directory: Optional[str] = None) -> None: ...

Import

from kornia.contrib import BoxMotTracker

I/O Contract

Inputs (__init__)

Name Type Required Description
detector ObjectDetector or str No Detector model or name string (default: "rtdetr_r18vd")
tracker_model_name str No Tracking algorithm name: "BoTSORT", "DeepOCSORT", "OCSORT", "HybridSORT", "ByteTrack", "StrongSORT", or "ImprAssoc" (default: "DeepOCSORT")
tracker_model_weights str No ReID model weights filename (default: "osnet_x0_25_msmt17.pt")
device str No Device for inference, e.g. "cpu" or "cuda" (default: "cpu")
fp16 bool No Whether to use half-precision inference (default: False)

Inputs (update)

Name Type Required Description
image torch.Tensor Yes Input image tensor with shape (1, 3, H, W) or (3, H, W)

Outputs

Name Type Description
tracking_results (from update) numpy.ndarray Array of shape (M, 8) with columns (x1, y1, x2, y2, id, conf, cls, ind)
visualization (from visualize) torch.Tensor Image tensor with shape (3, H, W) with drawn tracking results

Usage Examples

import torch
from kornia.contrib import BoxMotTracker

# Initialize tracker with default RT-DETR detector and DeepOCSORT tracker
tracker = BoxMotTracker(detector="rtdetr_r18vd", tracker_model_name="DeepOCSORT")

# Process video frames (at least 4 frames needed for initialization)
for frame_idx in range(10):
    image = torch.rand(1, 3, 640, 640)  # simulated frame
    results = tracker.update(image)

# Visualize the last frame with trajectories
vis_output = tracker.visualize(image, show_trajectories=True)

# Save output to disk
tracker.save(image, show_trajectories=True, directory="output_tracking")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment