Skip to content

trackforge / utils / geometry


Module geometry

Quick Reference

Item Kind Description
iou fn Calculate Intersection over Union (IoU) between two bounding boxes.
iou_batch fn Calculate IoU matrix between two lists of bounding boxes.
iou_cost_matrix fn Build an IoU association cost matrix between track boxes and detection boxes.
tlwh_to_tlbr fn Convert a bounding box from TLWH (Top-Left-Width-Height) to TLBR (Top-Left-Bottom-Right) format.
tlwh_to_xyah fn Convert a bounding box from TLWH to XYAH (center-x, center-y, aspect ratio, height).
xyah_to_tlwh fn Convert an XYAH vector back to a TLWH bounding box.

Functions

iou

fn iou(box1: &[f32; 4], box2: &[f32; 4]) -> f32

Calculate Intersection over Union (IoU) between two bounding boxes.

Arguments

Argument Description
box1 First bounding box in TLWH format.
box2 Second bounding box in TLWH format.

iou_batch

fn iou_batch(bboxes1: &[[f32; 4]], bboxes2: &[[f32; 4]]) -> Vec<Vec<f32>>

Calculate IoU matrix between two lists of bounding boxes.

Returns a 2D vector where result[i][j] is the IoU between bboxes1[i] and bboxes2[j].

iou_cost_matrix

fn iou_cost_matrix(tracks: &[[f32; 4]], dets: &[[f32; 4]]) -> Vec<Vec<f32>>

Build an IoU association cost matrix between track boxes and detection boxes.

result[i][j] = 1.0 - iou(tracks[i], dets[j]), the cost used by the IoU-based trackers. The shape mirrors iou_batch: one row per track, one column per detection (so an empty dets yields one empty row per track).

tlwh_to_tlbr

fn tlwh_to_tlbr(tlwh: &[f32; 4]) -> [f32; 4]

Convert a bounding box from TLWH (Top-Left-Width-Height) to TLBR (Top-Left-Bottom-Right) format.

tlwh_to_xyah

fn tlwh_to_xyah(tlwh: &[f32; 4]) -> crate::utils::kalman::MeasurementVector

Types: MeasurementVector

Convert a bounding box from TLWH to XYAH (center-x, center-y, aspect ratio, height).

The aspect ratio is width / height, guarded against division by zero.

xyah_to_tlwh

fn xyah_to_tlwh<const N: usize>(state: &nalgebra::SVector<f32, N>) -> [f32; 4]

Convert an XYAH vector back to a TLWH bounding box.

Accepts any vector with at least four components (e.g. the 8-dim Kalman state or the 4-dim measurement vector); only the first four elements are used.