Skip to content

Commit

Permalink
Add max ticks support for tickFPS computation
Browse files Browse the repository at this point in the history
  • Loading branch information
tersekmatija committed Oct 21, 2021
1 parent e7ac84e commit 959704e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions depthai_sdk/src/depthai_sdk/fps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import time
import cv2
import warnings


class FPSHandler:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 959704e

Please sign in to comment.