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
a5529848
Commit
a5529848
authored
Sep 21, 2018
by
xiongyu
Browse files
change video reader to 0-based indexing
parent
27c81690
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
mmcv/video/io.py
mmcv/video/io.py
+11
-11
No files found.
mmcv/video/io.py
View file @
a5529848
...
@@ -136,9 +136,9 @@ class VideoReader(object):
...
@@ -136,9 +136,9 @@ class VideoReader(object):
Returns:
Returns:
ndarray or None: Return the frame if successful, otherwise None.
ndarray or None: Return the frame if successful, otherwise None.
"""
"""
pos
=
self
.
_position
+
1
#
pos = self._position
if
self
.
_cache
:
if
self
.
_cache
:
img
=
self
.
_cache
.
get
(
pos
)
img
=
self
.
_cache
.
get
(
self
.
_position
)
if
img
is
not
None
:
if
img
is
not
None
:
ret
=
True
ret
=
True
else
:
else
:
...
@@ -150,34 +150,34 @@ class VideoReader(object):
...
@@ -150,34 +150,34 @@ class VideoReader(object):
else
:
else
:
ret
,
img
=
self
.
_vcap
.
read
()
ret
,
img
=
self
.
_vcap
.
read
()
if
ret
:
if
ret
:
self
.
_position
=
pos
self
.
_position
+
=
1
return
img
return
img
def
get_frame
(
self
,
frame_id
):
def
get_frame
(
self
,
frame_id
):
"""Get frame by index.
"""Get frame by index.
Args:
Args:
frame_id (int): Index of the expected frame,
1
-based.
frame_id (int): Index of the expected frame,
0
-based.
Returns:
Returns:
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
ValueError
(
'"frame_id" must be between
1
and {}'
.
format
(
raise
ValueError
(
'"frame_id" must be between
0
and {}'
.
format
(
self
.
_frame_cnt
))
self
.
_frame_cnt
))
if
frame_id
==
self
.
_position
+
1
:
if
frame_id
==
self
.
_position
:
return
self
.
read
()
return
self
.
read
()
if
self
.
_cache
:
if
self
.
_cache
:
img
=
self
.
_cache
.
get
(
frame_id
)
img
=
self
.
_cache
.
get
(
frame_id
)
if
img
is
not
None
:
if
img
is
not
None
:
self
.
_position
=
frame_id
self
.
_position
=
frame_id
+
1
return
img
return
img
self
.
_set_real_position
(
frame_id
-
1
)
self
.
_set_real_position
(
frame_id
)
ret
,
img
=
self
.
_vcap
.
read
()
ret
,
img
=
self
.
_vcap
.
read
()
if
ret
:
if
ret
:
self
.
_position
+=
1
if
self
.
_cache
:
if
self
.
_cache
:
self
.
_cache
.
put
(
self
.
_position
,
img
)
self
.
_cache
.
put
(
self
.
_position
,
img
)
self
.
_position
+=
1
return
img
return
img
def
current_frame
(
self
):
def
current_frame
(
self
):
...
@@ -189,7 +189,7 @@ class VideoReader(object):
...
@@ -189,7 +189,7 @@ class VideoReader(object):
"""
"""
if
self
.
_position
==
0
:
if
self
.
_position
==
0
:
return
None
return
None
return
self
.
_cache
.
get
(
self
.
_position
)
return
self
.
_cache
.
get
(
self
.
_position
-
1
)
def
cvt2frames
(
self
,
def
cvt2frames
(
self
,
frame_dir
,
frame_dir
,
...
...
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