From 959704ed4f24ede7174b4229c57243b3465216bf Mon Sep 17 00:00:00 2001 From: tersekmatija Date: Thu, 21 Oct 2021 13:25:17 +0200 Subject: [PATCH] Add max ticks support for tickFPS computation --- depthai_sdk/src/depthai_sdk/fps.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/depthai_sdk/src/depthai_sdk/fps.py b/depthai_sdk/src/depthai_sdk/fps.py index 83a53121b..8a5e0dd43 100644 --- a/depthai_sdk/src/depthai_sdk/fps.py +++ b/depthai_sdk/src/depthai_sdk/fps.py @@ -1,6 +1,7 @@ import collections import time import cv2 +import warnings class FPSHandler: @@ -15,10 +16,11 @@ class FPSHandler: _fpsType = cv2.FONT_HERSHEY_SIMPLEX _fpsLineType = cv2.LINE_AA - def __init__(self, cap=None): + def __init__(self, cap=None, maxTicks = 100): """ Args: cap (cv2.VideoCapture): handler to the video file object + maxTicks (int): maximum queue length in tickFps computation """ self._timestamp = None self._start = None @@ -28,6 +30,12 @@ def __init__(self, cap=None): self._iterCnt = 0 self._ticks = {} + if maxTicks < 2: + warnings.warn(f"FPSHandler maxTicks value must be 2 or higher. " + f"It will automatically be set to 2 instead of {maxTicks}") + maxTicks = 2 + self._maxTicks = maxTicks + def nextIter(self): """ Marks the next iteration of the processing loop. Will use :obj:`time.sleep` method if initialized with video file @@ -52,7 +60,7 @@ def tick(self, name): name (str): Specifies timestamp name """ if name not in self._ticks: - self._ticks[name] = collections.deque(maxlen=100) + self._ticks[name] = collections.deque(maxlen=self._maxTicks) self._ticks[name].append(time.monotonic()) def tickFps(self, name):