Detection Dataclass¶
Defined in ObjectDetection/detection.py. Replaces the implicit dict schema with a typed, slotted dataclass while preserving full dict-style access for backward compatibility.
Fields¶
| Field | Type | Default | Description |
|---|---|---|---|
class_name |
str | (required) | YOLO class name (e.g. "person", "chair") |
cls_id |
int | (required) | YOLO class index |
conf |
float | (required) | Detection confidence score (0.0--1.0) |
x1 |
int | (required) | Bounding box left |
y1 |
int | (required) | Bounding box top |
x2 |
int | (required) | Bounding box right |
y2 |
int | (required) | Bounding box bottom |
ghost |
bool | False |
Whether this is a persisted (ghost) detection from ObjectPersistenceCache |
_face_idx |
int or None | None |
Internal index used when faces are treated as objects (not shown in repr) |
Dict-Compatible API¶
Existing code that treated detections as dicts continues to work unchanged.
__getitem__(key)¶
det = Detection(class_name="person", cls_id=0, conf=0.92, x1=10, y1=20, x2=100, y2=200)
det['x1'] # 10
det['_ghost'] # False (aliased from 'ghost' via _KEY_MAP)
get(key, default=None)¶
__contains__(key)¶
__setitem__(key, value)¶
update(**kwargs)¶
keys(), values(), items()¶
These allow iteration and unpacking, matching dict behaviour. keys() returns field names including _face_idx but excluding other private fields.
list(det.keys()) # ['class_name', 'cls_id', 'conf', 'x1', 'y1', 'x2', 'y2', 'ghost', '_face_idx']
dict(det.items()) # full dict representation
Key Alias Map¶
The _KEY_MAP class variable maps legacy dict keys to dataclass field names:
| Dict Key | Field Name |
|---|---|
_ghost |
ghost |
All other keys map to themselves.
Properties¶
center¶
Returns the bounding-box centre as a float numpy array [cx, cy].
Notes¶
- The dataclass uses
slots=Truefor memory efficiency. Detectionsupports__iter__, which yields keys -- sodict(det, _ghost=True)patterns work.- Ghost detections are created by
ObjectPersistenceCachewhen a previously-seen object is not detected for up toobj_persistenceframes.