From b82d75b79ef02452d3c8aac45314a11cdf38408f Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Sun, 6 Feb 2022 13:28:53 -0600 Subject: [PATCH] avoid rare divide by zero --- frigate/util.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frigate/util.py b/frigate/util.py index 85835e933..f11c0b0f9 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -567,6 +567,9 @@ class EventsPerSecond: # compute the (approximate) events in the last n seconds now = datetime.datetime.now().timestamp() seconds = min(now - self._start, last_n_seconds) + # avoid divide by zero + if seconds == 0: + seconds = 1 return ( len([t for t in self._timestamps if t > (now - last_n_seconds)]) / seconds ) @@ -601,6 +604,7 @@ def add_mask(mask, mask_img): ) cv2.fillPoly(mask_img, pts=[contour], color=(0)) + def load_labels(path, encoding="utf-8"): """Loads labels from file (with or without index numbers). Args: @@ -620,6 +624,7 @@ def load_labels(path, encoding="utf-8"): else: return {index: line.strip() for index, line in enumerate(lines)} + class FrameManager(ABC): @abstractmethod def create(self, name, size) -> AnyStr: