Skip to content

Commit

Permalink
Add cv2 get(CAP_PROP_POS_FRAMES)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Oct 28, 2024
1 parent f9b8786 commit fafe087
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions snake-pit/test_cv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def test_constants():
assert ocv_cv2.CAP_PROP_FRAME_WIDTH == vf_cv2.CAP_PROP_FRAME_WIDTH
assert ocv_cv2.CAP_PROP_FRAME_HEIGHT == vf_cv2.CAP_PROP_FRAME_HEIGHT
assert ocv_cv2.CAP_PROP_FPS == vf_cv2.CAP_PROP_FPS
assert ocv_cv2.CAP_PROP_FRAME_COUNT == vf_cv2.CAP_PROP_FRAME_COUNT

assert ocv_cv2.FONT_HERSHEY_SIMPLEX == vf_cv2.FONT_HERSHEY_SIMPLEX
assert ocv_cv2.FONT_HERSHEY_PLAIN == vf_cv2.FONT_HERSHEY_PLAIN
Expand Down
5 changes: 5 additions & 0 deletions vidformer-py/vidformer/cv2/vf_cv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CAP_PROP_FRAME_WIDTH = 3
CAP_PROP_FRAME_HEIGHT = 4
CAP_PROP_FPS = 5
CAP_PROP_FRAME_COUNT = 7

FONT_HERSHEY_SIMPLEX = 0
FONT_HERSHEY_PLAIN = 1
Expand Down Expand Up @@ -128,6 +129,10 @@ def get(self, prop):
return self._source.fmt()["width"]
elif prop == CAP_PROP_FRAME_HEIGHT:
return self._source.fmt()["height"]
elif prop == CAP_PROP_FRAME_COUNT:
return len(self._source.ts())
elif prop == CAP_PROP_POS_FRAMES:
return self._next_frame_idx

raise Exception(f"Unknown property {prop}")

Expand Down
2 changes: 1 addition & 1 deletion vidformer-py/vidformer/vf.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def __init__(self, source):

def __getitem__(self, idx):
if type(idx) != int:
raise Exception("Source iloc index must be an integer")
raise Exception(f"Source iloc index must be an integer, got a {type(idx)}")
return SourceExpr(self._source, idx, True)


Expand Down

0 comments on commit fafe087

Please sign in to comment.