Skip to content

Commit

Permalink
Merge pull request #510 from luxonis/sdk_fps_update
Browse files Browse the repository at this point in the history
Add max ticks support for tickFPS computation
  • Loading branch information
VanDavv committed Oct 21, 2021
2 parents 1917446 + fd4ea6d commit e0f4c95
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
12 changes: 5 additions & 7 deletions depthai_sdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
opencv-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l"
opencv-contrib-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l"
opencv-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l"
opencv-contrib-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l"
blobconverter==1.2.2
pytube==11.0.1
depthai
opencv-python>4
opencv-contrib-python>4
blobconverter>=1.2.2
pytube>=11.0.1
depthai>2
2 changes: 1 addition & 1 deletion depthai_sdk/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='depthai-sdk',
version='1.1.1',
version='1.1.2',
description='This package contains convenience classes and functions that help in most common tasks while using DepthAI API',
long_description=io.open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
Expand Down
13 changes: 10 additions & 3 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
cap (cv2.VideoCapture, Optional): handler to the video file object
maxTicks (int, Optional): maximum ticks amount for FPS calculation
"""
self._timestamp = None
self._start = None
Expand All @@ -28,6 +30,11 @@ def __init__(self, cap=None):
self._iterCnt = 0
self._ticks = {}

if maxTicks < 2:
raise ValueError(f"Proviced maxTicks value must be 2 or higher (supplied: {maxTicks})")

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 +59,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
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ argcomplete==1.12.1
-e ./depthai_sdk
--extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/
depthai==2.10.0.0.dev+7a0749a61597c086c5fd6e579618ae33accec8df
opencv-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l"
opencv-contrib-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l"
opencv-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l"
opencv-contrib-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l"

0 comments on commit e0f4c95

Please sign in to comment.