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
95cb8853
Commit
95cb8853
authored
Sep 29, 2018
by
Kai Chen
Browse files
Merge branch 'master' of github.com:open-mmlab/mmcv
parents
e0422994
93620a28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
4 deletions
+42
-4
mmcv/video/io.py
mmcv/video/io.py
+8
-3
tests/test_video.py
tests/test_video.py
+34
-1
No files found.
mmcv/video/io.py
View file @
95cb8853
...
@@ -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,12 @@ class VideoReader(object):
...
@@ -240,7 +240,12 @@ class VideoReader(object):
def
__getitem__
(
self
,
index
):
def
__getitem__
(
self
,
index
):
if
isinstance
(
index
,
slice
):
if
isinstance
(
index
,
slice
):
raise
RuntimeError
(
'slice has not been supported yet'
)
return
[
self
.
get_frame
(
i
)
for
i
in
range
(
*
index
.
indices
(
self
.
frame_cnt
))]
# support negative indexing
if
index
<
0
:
index
+=
self
.
frame_cnt
if
index
<
0
:
raise
IndexError
(
'index out of range'
)
return
self
.
get_frame
(
index
)
return
self
.
get_frame
(
index
)
def
__iter__
(
self
):
def
__iter__
(
self
):
...
...
tests/test_video.py
View file @
95cb8853
...
@@ -62,12 +62,45 @@ class TestVideo(object):
...
@@ -62,12 +62,45 @@ class TestVideo(object):
assert
int
(
round
(
img
.
mean
()))
==
94
assert
int
(
round
(
img
.
mean
()))
==
94
img
=
v
[
64
]
img
=
v
[
64
]
assert
int
(
round
(
img
.
mean
()))
==
205
assert
int
(
round
(
img
.
mean
()))
==
205
img
=
v
[
-
104
]
assert
int
(
round
(
img
.
mean
()))
==
205
img
=
v
[
63
]
img
=
v
[
63
]
assert
int
(
round
(
img
.
mean
()))
==
94
assert
int
(
round
(
img
.
mean
()))
==
94
img
=
v
[
-
105
]
assert
int
(
round
(
img
.
mean
()))
==
94
img
=
v
.
read
()
img
=
v
.
read
()
assert
int
(
round
(
img
.
mean
()))
==
205
assert
int
(
round
(
img
.
mean
()))
==
205
with
pytest
.
raises
(
Value
Error
):
with
pytest
.
raises
(
Index
Error
):
v
.
get_frame
(
self
.
num_frames
+
1
)
v
.
get_frame
(
self
.
num_frames
+
1
)
with
pytest
.
raises
(
IndexError
):
v
[
-
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
assert
len
(
imgs
)
==
2
imgs
=
v
[
63
:
65
]
assert
int
(
round
(
imgs
[
0
].
mean
()))
==
94
assert
int
(
round
(
imgs
[
1
].
mean
()))
==
205
assert
len
(
imgs
)
==
2
imgs
=
v
[
64
:
62
:
-
1
]
assert
int
(
round
(
imgs
[
0
].
mean
()))
==
205
assert
int
(
round
(
imgs
[
1
].
mean
()))
==
94
assert
len
(
imgs
)
==
2
imgs
=
v
[:
5
]
assert
len
(
imgs
)
==
5
for
img
in
imgs
:
assert
int
(
round
(
img
.
mean
()))
==
94
imgs
=
v
[
165
:]
assert
len
(
imgs
)
==
3
for
img
in
imgs
:
assert
int
(
round
(
img
.
mean
()))
==
0
imgs
=
v
[
-
3
:]
assert
len
(
imgs
)
==
3
for
img
in
imgs
:
assert
int
(
round
(
img
.
mean
()))
==
0
def
test_current_frame
(
self
):
def
test_current_frame
(
self
):
v
=
mmcv
.
VideoReader
(
self
.
video_path
)
v
=
mmcv
.
VideoReader
(
self
.
video_path
)
...
...
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