-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_tracker.py
41 lines (30 loc) · 1.12 KB
/
object_tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import datetime
from region import Region
from track import Track
from log import log
class ObjectTracker:
ttl = datetime.timedelta(seconds=2)
def __init__(self):
self.tracks = []
def process(self, region_proposals):
birthed, promoted, reaped = [], [], []
region_proposals = Region.merge_regions(region_proposals)
for region in region_proposals:
if not region.is_car():
continue
# associate with existing track
for track in self.tracks:
if track.matches(region):
track.update(region)
continue
birthed.append(Track(region))
# existing tracks are either promoted or reaped
for track in self.tracks:
if track.age() > ObjectTracker.ttl:
reaped.append(track)
else:
promoted.append(track.promote())
log.debug(f'birthed={len(birthed)} promoted={len(promoted)} reaped={len(reaped)}')
self.tracks = birthed + promoted
# return the reaped tracks so they can be saved
return reaped