This code initializes a defaultdict
called tracked_persons
that stores information about tracked individuals.
defaultdict
Usagedefaultdict
(from collections
) is a dictionary that provides a default value for missing keys.lambda: { ... }
defines what each new entry will contain when a non-existent key is accessed.None
, it pre-allocates empty NumPy arrays for efficiency.Each entry has:
"age"
: An integer (initialized to 0
) representing how long the person has been tracked."last_bbox"
: A bounding box stored as a NumPy array of shape (4,)
(for [x1, y1, x2, y2]
).
np.empty((4,), dtype=np.float32)
allocates uninitialized memory (faster than np.zeros
if values will be overwritten immediately)."last_keypoints"
: Pose keypoints stored as a (17, 2)
array (e.g., for COCO-format 17-keypoint skeletons).
(x, y)
coordinates.This approach balances flexibility (dynamic key creation) with performance (pre-allocated memory).