Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
2ab73c85
Commit
2ab73c85
authored
Sep 26, 2018
by
xiongyu
Browse files
add slice support and unit test
parent
6d51a941
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
mmcv/video/io.py
mmcv/video/io.py
+3
-3
tests/test_video.py
tests/test_video.py
+6
-0
No files found.
mmcv/video/io.py
View file @
2ab73c85
...
@@ -163,8 +163,8 @@ class VideoReader(object):
...
@@ -163,8 +163,8 @@ class VideoReader(object):
ndarray or None: Return the frame if successful, otherwise None.
ndarray or None: Return the frame if successful, otherwise None.
"""
"""
if
frame_id
<
0
or
frame_id
>=
self
.
_frame_cnt
:
if
frame_id
<
0
or
frame_id
>=
self
.
_frame_cnt
:
raise
Value
Error
(
'"frame_id" must be between 0 and {}'
.
format
(
raise
Index
Error
(
'"frame_id" must be between 0 and {}'
.
format
(
self
.
_frame_cnt
))
self
.
_frame_cnt
-
1
))
if
frame_id
==
self
.
_position
:
if
frame_id
==
self
.
_position
:
return
self
.
read
()
return
self
.
read
()
if
self
.
_cache
:
if
self
.
_cache
:
...
@@ -240,7 +240,7 @@ class VideoReader(object):
...
@@ -240,7 +240,7 @@ class VideoReader(object):
def
__getitem__
(
self
,
index
):
def
__getitem__
(
self
,
index
):
if
isinstance
(
index
,
slice
):
if
isinstance
(
index
,
slice
):
r
aise
RuntimeError
(
'slice has not been supported yet'
)
r
eturn
[
self
.
get_frame
(
i
)
for
i
in
range
(
*
index
.
indices
(
self
.
frame_cnt
))]
return
self
.
get_frame
(
index
)
return
self
.
get_frame
(
index
)
def
__iter__
(
self
):
def
__iter__
(
self
):
...
...
tests/test_video.py
View file @
2ab73c85
...
@@ -69,6 +69,12 @@ class TestVideo(object):
...
@@ -69,6 +69,12 @@ class TestVideo(object):
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
v
.
get_frame
(
self
.
num_frames
+
1
)
v
.
get_frame
(
self
.
num_frames
+
1
)
def
test_slice
(
self
):
v
=
mmcv
.
VideoReader
(
self
.
video_path
)
imgs
=
v
[
-
105
:
-
103
]
assert
int
(
round
(
imgs
[
0
].
mean
()))
==
94
assert
int
(
round
(
imgs
[
1
].
mean
()))
==
205
def
test_current_frame
(
self
):
def
test_current_frame
(
self
):
v
=
mmcv
.
VideoReader
(
self
.
video_path
)
v
=
mmcv
.
VideoReader
(
self
.
video_path
)
assert
v
.
current_frame
()
is
None
assert
v
.
current_frame
()
is
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment