Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pad.face
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.pad.face
Commits
3db8b6ab
Commit
3db8b6ab
authored
5 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Allow loading annotations of files without the db object
parent
a7ce9f80
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!104
Improve high level database interfaces
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/pad/face/database/database.py
+103
-6
103 additions, 6 deletions
bob/pad/face/database/database.py
with
103 additions
and
6 deletions
bob/pad/face/database/database.py
+
103
−
6
View file @
3db8b6ab
from
bob.pad.base.database
import
PadFile
import
bob.bio.video
import
bob.io.video
from
bob.db.base.annotations
import
read_annotation_file
class
VideoPadFile
(
PadFile
):
...
...
@@ -9,14 +11,15 @@ class VideoPadFile(PadFile):
def
__init__
(
self
,
attack_type
,
client_id
,
path
,
file_id
=
None
):
super
(
VideoPadFile
,
self
).
__init__
(
attack_type
=
attack_type
,
client_id
=
client_id
,
path
=
path
,
file_id
=
file_id
,
attack_type
=
attack_type
,
client_id
=
client_id
,
path
=
path
,
file_id
=
file_id
)
def
load
(
self
,
directory
=
None
,
extension
=
'
.avi
'
,
frame_selector
=
bob
.
bio
.
video
.
FrameSelector
(
selection_style
=
'
all
'
)):
def
load
(
self
,
directory
=
None
,
extension
=
"
.avi
"
,
frame_selector
=
bob
.
bio
.
video
.
FrameSelector
(
selection_style
=
"
all
"
),
):
"""
Loads the video file and returns in a :any:`bob.bio.video.FrameContainer`.
Parameters
...
...
@@ -34,3 +37,97 @@ class VideoPadFile(PadFile):
The loaded frames inside a frame container.
"""
return
frame_selector
(
self
.
make_path
(
directory
,
extension
))
def
check_original_directory_and_extension
(
self
):
if
not
hasattr
(
self
,
"
original_directory
"
):
raise
RuntimeError
(
"
Please set the original_directory attribute of files in your
"
"
database
'
s object method.
"
)
if
not
hasattr
(
self
,
"
original_extension
"
):
raise
RuntimeError
(
"
Please set the original_extension attribute of files in your
"
"
database
'
s object method.
"
)
@property
def
frames
(
self
):
"""
Returns an iterator of frames in the video.
If your database video files need to be loaded in a special way, you need to
override this property.
Returns
-------
collection.Iterator
An iterator returning frames of the video.
Raises
------
RuntimeError
In your database implementation, the original_directory and
original_extension attributes of the files need to be set when database
'
s
object method is called.
"""
self
.
check_original_directory_and_extension
()
path
=
self
.
make_path
(
directory
=
self
.
original_directory
,
extension
=
self
.
original_extension
)
return
iter
(
bob
.
io
.
video
.
reader
(
path
))
@property
def
number_of_frames
(
self
):
self
.
check_original_directory_and_extension
()
path
=
self
.
make_path
(
directory
=
self
.
original_directory
,
extension
=
self
.
original_extension
)
return
bob
.
io
.
video
.
reader
(
path
).
number_of_frames
@property
def
frame_shape
(
self
):
"""
Returns the size of each frame in this database.
This implementation assumes all videos and frames have the same shape.
It
'
s best to override this method in your database implementation and return
a constant.
Returns
-------
(int, int, int)
The (Channels, Height, Width) sizes.
"""
self
.
check_original_directory_and_extension
()
path
=
self
.
make_path
(
directory
=
self
.
original_directory
,
extension
=
self
.
original_extension
)
frame
=
next
(
bob
.
io
.
video
.
reader
(
path
))
return
frame
.
shape
@property
def
annotations
(
self
):
"""
Reads the annotations
For this property to work, you need to set ``annotation_directory``,
``annotation_extension``, and ``annotation_type`` attributes of the files when
database
'
s object method is called.
Returns
-------
dict
The annotations as a dictionary.
"""
if
not
(
hasattr
(
self
,
"
annotation_directory
"
)
and
hasattr
(
self
,
"
annotation_extension
"
)
and
hasattr
(
self
,
"
annotation_type
"
)
):
raise
RuntimeError
(
"
For this property to work, you need to set ``annotation_directory``,
"
"
``annotation_extension``, and ``annotation_type`` attributes of the
"
"
files when database
'
s object method is called.
"
)
if
self
.
annotation_directory
is
None
:
return
None
annotation_file
=
self
.
make_path
(
directory
=
self
.
annotation_directory
,
extension
=
self
.
annotation_extension
)
return
read_annotation_file
(
annotation_file
,
self
.
annotation_type
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment