estimate_ego_mask

estimate_ego_mask#

rapidtools.processing.street_localization.estimate_ego_mask(observations: Iterable[Observation], min_recurrence: float = 0.5, iou_threshold: float = 0.5, min_frames: int = 3) → set[int][source]#

Find detections of the collection vehicle itself.

A parked car drifts across the frame as the camera drives past; the vehicle carrying the camera does not. Within each sequence, a detection whose box recurs (IoU above iou_threshold) in at least min_recurrence of the frames is flagged as ego. Sequences with fewer than min_frames frames are left alone, since recurrence cannot be judged.

Parameters:
  • observations – Observations of one label, in any order.

  • min_recurrence – Fraction of a sequence’s frames the box must recur in.

  • iou_threshold – Box overlap that counts as “the same place”.

  • min_frames – Minimum frames in a sequence before flagging anything.

Returns:

set[int] – Indices into observations (in iteration order) that belong to the ego vehicle.

Example

>>> from rapidtools.core import Observation
>>> ego = [(0.40, 0.80), (0.60, 0.80), (0.60, 1.00), (0.40, 1.00)]
>>> frames = [
...     Observation(str(i), 'car', ego, 0.0, 0.0, 0.0, sequence_id='s')
...     for i in range(4)
... ]
>>> box = [(0.1, 0.5), (0.2, 0.5), (0.2, 0.6), (0.1, 0.6)]
>>> parked = Observation('9', 'car', box, 0.0, 0.0, 0.0, sequence_id='s')
>>> sorted(estimate_ego_mask(frames + [parked]))
[0, 1, 2, 3]