13 lines
722 B
Python
13 lines
722 B
Python
"""Bounded per-camera frame window. No copying of image tensors across the BT API."""
|
|||
|
|
from collections import deque
|
||
|
|
class FrameWindow:
|
||
|
|
def __init__(self,maximum=32):self.frames=deque(maxlen=maximum)
|
||
|
|
def add(self,stamp,camera,path):
|
||
|
|
if self.frames and stamp<self.frames[-1]['stamp']:self.frames.clear()
|
||
|
|
if self.frames and stamp==self.frames[-1]['stamp']:
|
||
|
|
views=self.frames[-1]['views']
|
||
|
|
if camera in views or len(views)<3:views[camera]=path
|
||
|
|
else:self.frames.append(dict(stamp=stamp,views={camera:path}))
|
||
|
|
def since(self,after,now):
|
||
|
|
return [dict(stamp=f['stamp'],views=dict(f['views'])) for f in self.frames if after<=f['stamp']<=now and now-f['stamp']<=10]
|