Skip to content

Commit

Permalink
Merge pull request #830 from roboflow/feature/update_fps_monitor_api
Browse files Browse the repository at this point in the history
Update `FPSMonitor` API
  • Loading branch information
SkalskiP authored Jan 31, 2024
2 parents 5771a29 + 2280de7 commit 46426f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ These features are phased out due to better alternatives or potential issues in
- `Color.green()` is deprecated and will be removed in `supervision-0.22.0`. Use `Color.GREEN` instead.
- `Color.blue()` is deprecated and will be removed in `supervision-0.22.0`. Use `Color.BLUE` instead.
- [`ColorPalette.default()`](draw/color.md/#supervision.draw.color.ColorPalette.default) is deprecated and will be removed in `supervision-0.22.0`. Use [`ColorPalette.DEFAULT`](draw/color.md/#supervision.draw.color.ColorPalette.DEFAULT) instead.
- `BoxAnnotator` is deprecated and will be removed in `supervision-0.22.0`. Use [`BoundingBoxAnnotator`](annotators.md/#supervision.annotators.core.BoundingBoxAnnotator) and [`LabelAnnotator`](annotators.md/#supervision.annotators.core.LabelAnnotator) instead.
- `BoxAnnotator` is deprecated and will be removed in `supervision-0.22.0`. Use [`BoundingBoxAnnotator`](annotators.md/#supervision.annotators.core.BoundingBoxAnnotator) and [`LabelAnnotator`](annotators.md/#supervision.annotators.core.LabelAnnotator) instead.
- [`FPSMonitor.__call__`](utils/video.md/#supervision.utils.video.FPSMonitor.__call__) is deprecated and will be removed in `supervision-0.22.0`. Use [`FPSMonitor.fps`](utils/video.md/#supervision.utils.video.FPSMonitor.fps) instead.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "supervision"
version = "0.18.0"
version = "0.19.0rc1"
description = "A set of easy-to-use utils that will come in handy in any Computer Vision project"
authors = ["Piotr Skalski <[email protected]>"]
maintainers = ["Piotr Skalski <[email protected]>"]
Expand Down
26 changes: 23 additions & 3 deletions supervision/utils/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import cv2
import numpy as np

from supervision.utils.internal import deprecated


@dataclass
class VideoInfo:
Expand Down Expand Up @@ -219,25 +221,43 @@ def __init__(self, sample_size: int = 30):
```python
import supervision as sv
frames_generator = sv.get_video_frames_generator('source.mp4')
frames_generator = sv.get_video_frames_generator(source_path=<SOURCE_FILE_PATH>)
fps_monitor = sv.FPSMonitor()
for frame in frames_generator:
# your processing code here
fps_monitor.tick()
fps = fps_monitor()
fps = fps_monitor.fps
```
"""
""" # noqa: E501 // docs
self.all_timestamps = deque(maxlen=sample_size)

@deprecated(
"`FPSMonitor.__call__` is deprecated and will be removed in "
"`supervision-0.22.0`. Use `FPSMonitor.fps` instead."
)
def __call__(self) -> float:
"""
!!! failure "Deprecated"
`FPSMonitor.__call__` is deprecated and will be removed in
`supervision-0.22.0`. Use `FPSMonitor.fps` instead.
Computes and returns the average FPS based on the stored time stamps.
Returns:
float: The average FPS. Returns 0.0 if no time stamps are stored.
"""
return self.fps

@property
def fps(self) -> float:
"""
Computes and returns the average FPS based on the stored time stamps.
Returns:
float: The average FPS. Returns 0.0 if no time stamps are stored.
"""
if not self.all_timestamps:
return 0.0
taken_time = self.all_timestamps[-1] - self.all_timestamps[0]
Expand Down

0 comments on commit 46426f8

Please sign in to comment.