feat: Integrate pyrsistent for enhanced tracking state management

- Added `pyrsistent` as a dependency to manage historical detections in the `Tracking` class, improving data integrity and immutability.
- Updated the `GlobalTrackingState` to include historical detections using `PVector`, facilitating better tracking of past detections.
- Introduced a new `update_tracking` function to handle timestamp updates for tracking objects, enhancing the tracking logic.
- Refactored imports and type hints for improved organization and clarity across the codebase.
This commit is contained in:
2025-04-30 10:04:39 +08:00
parent cea21dc434
commit 072bf1c46f
4 changed files with 54 additions and 2 deletions

View File

@ -46,6 +46,7 @@ from jaxtyping import Array, Float, Num, jaxtyped
from matplotlib import pyplot as plt
from numpy.typing import ArrayLike
from optax.assignment import hungarian_algorithm as linear_sum_assignment
from pyrsistent import v, pvector
from scipy.spatial.transform import Rotation as R
from typing_extensions import deprecated
@ -544,7 +545,10 @@ class GlobalTrackingState:
kps_3d, latest_timestamp = triangle_from_cluster(cluster)
next_id = self._last_id + 1
tracking = Tracking(
id=next_id, keypoints=kps_3d, last_active_timestamp=latest_timestamp
id=next_id,
keypoints=kps_3d,
last_active_timestamp=latest_timestamp,
historical_detections=v(*cluster),
)
self._trackings[next_id] = tracking
self._last_id = next_id
@ -1027,4 +1031,10 @@ affinities = calculate_affinity_matrix(
)
display(affinities)
# %%
def update_tracking(tracking: Tracking, detection: Detection):
delta_t_ = detection.timestamp - tracking.last_active_timestamp
delta_t = max(delta_t_, DELTA_T_MIN)
return tracking