fix coral fps value

This commit is contained in:
Blake Blackshear 2020-09-12 22:29:53 -05:00
parent e26308a05b
commit 5e77436d39
2 changed files with 8 additions and 2 deletions

View File

@ -126,12 +126,16 @@ class EventsPerSecond:
self._start = datetime.datetime.now().timestamp() self._start = datetime.datetime.now().timestamp()
def update(self): def update(self):
if self._start is None:
self.start()
self._timestamps.append(datetime.datetime.now().timestamp()) self._timestamps.append(datetime.datetime.now().timestamp())
# truncate the list when it goes 100 over the max_size # truncate the list when it goes 100 over the max_size
if len(self._timestamps) > self._max_events+100: if len(self._timestamps) > self._max_events+100:
self._timestamps = self._timestamps[(1-self._max_events):] self._timestamps = self._timestamps[(1-self._max_events):]
def eps(self, last_n_seconds=10): def eps(self, last_n_seconds=10):
if self._start is None:
self.start()
# compute the (approximate) events in the last n seconds # compute the (approximate) events in the last n seconds
now = datetime.datetime.now().timestamp() now = datetime.datetime.now().timestamp()
seconds = min(now-self._start, last_n_seconds) seconds = min(now-self._start, last_n_seconds)

View File

@ -219,7 +219,7 @@ def track_camera(name, config, frame_queue, frame_shape, detection_queue, detect
plasma_client = PlasmaFrameManager() plasma_client = PlasmaFrameManager()
process_frames(name, frame_queue, frame_shape, plasma_client, motion_detector, object_detector, process_frames(name, frame_queue, frame_shape, plasma_client, motion_detector, object_detector,
object_tracker, detected_objects_queue, fps, detection_frame, objects_to_track, object_filters, mask, stop_event) object_tracker, detected_objects_queue, fps, detection_fps, detection_frame, objects_to_track, object_filters, mask, stop_event)
print(f"{name}: exiting subprocess") print(f"{name}: exiting subprocess")
@ -255,7 +255,7 @@ def detect(object_detector, frame, region, objects_to_track, object_filters, mas
def process_frames(camera_name: str, frame_queue: mp.Queue, frame_shape, def process_frames(camera_name: str, frame_queue: mp.Queue, frame_shape,
frame_manager: FrameManager, motion_detector: MotionDetector, frame_manager: FrameManager, motion_detector: MotionDetector,
object_detector: RemoteObjectDetector, object_tracker: ObjectTracker, object_detector: RemoteObjectDetector, object_tracker: ObjectTracker,
detected_objects_queue: mp.Queue, fps: mp.Value, current_frame_time: mp.Value, detected_objects_queue: mp.Queue, fps: mp.Value, detection_fps: mp.Value, current_frame_time: mp.Value,
objects_to_track: List[str], object_filters: Dict, mask, stop_event: mp.Event, objects_to_track: List[str], object_filters: Dict, mask, stop_event: mp.Event,
exit_on_empty: bool = False): exit_on_empty: bool = False):
@ -352,3 +352,5 @@ def process_frames(camera_name: str, frame_queue: mp.Queue, frame_shape,
# add to the queue # add to the queue
detected_objects_queue.put((camera_name, frame_time, object_tracker.tracked_objects)) detected_objects_queue.put((camera_name, frame_time, object_tracker.tracked_objects))
detection_fps.value = object_detector.fps.eps()