Commit 95a37b6c authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'annot' into 'master'

Add annotation support and reorganize frame reading

See merge request !2
parents 0c8da8c0 a6acc17f
Pipeline #18376 passed with stages
in 80 minutes and 10 seconds
OULUNPU_FRAME_SHAPE = (3, 1920, 1080)
"Shape of the video frames in the oulunpu database."
from .query import Database, File
......
#!/usr/bin/env python
from . import Database
from bob.db.oulunpu import Database
database = Database(protocol='Protocol_1')
from pkg_resources import resource_filename
from bob.pad.base.database import FileListPadDatabase
from bob.pad.face.database import VideoPadFile
from bob.pad.face.utils import frames, number_of_frames
from bob.extension import rc
# documentation imports
import numpy
from bob.io.video import reader
from . import OULUNPU_FRAME_SHAPE
class File(VideoPadFile):
"""The file objects of the OULU-NPU dataset."""
pass
@property
def frames(self):
"""Yields the frames of the biofile one by one.
Yields
------
:any:`numpy.array`
A frame of the video. The size is (3, 1920, 1080).
"""
vfilename = self.make_path(directory=self.original_directory)
return iter(reader(vfilename))
@property
def number_of_frames(self):
"""Returns the number of frames in a video file.
Returns
-------
int
The number of frames.
"""
vfilename = self.make_path(directory=self.original_directory)
return reader(vfilename).number_of_frames
@property
def frame_shape(self):
"""Returns the size of each frame in this database.
Returns
-------
(int, int, int)
The (#Channels, Height, Width) which is :any:`OULUNPU_FRAME_SHAPE`.
"""
return OULUNPU_FRAME_SHAPE
class Database(FileListPadDatabase):
"""The database interface for the OULU-NPU dataset."""
def __init__(self, original_directory=rc['bob.db.oulunpu.directory'],
name='oulunpu', bio_file_class=None,
name='oulunpu', pad_file_class=None,
original_extension=".avi", **kwargs):
if bio_file_class is None:
bio_file_class = File
if pad_file_class is None:
pad_file_class = File
filelists_directory = resource_filename(__name__, 'lists')
super(Database, self).__init__(
filelists_directory=filelists_directory, name=name,
original_directory=original_directory,
bio_file_class=bio_file_class,
pad_file_class=pad_file_class,
original_extension=original_extension,
**kwargs)
def objects(self, groups=None, protocol=None, purposes=None,
model_ids=None, classes=None, **kwargs):
files = super(Database, self).objects(
groups=groups, protocol=protocol, purposes=purposes,
model_ids=model_ids, classes=classes, **kwargs)
for f in files:
f.original_directory = self.original_directory
return files
def frames(self, padfile):
"""Yields the frames of the padfile one by one.
return padfile.frames
Parameters
----------
padfile : :any:`File`
The high-level pad file
def number_of_frames(self, padfile):
return padfile.number_of_frames
Yields
------
:any:`numpy.array`
A frame of the video. The size is (3, 1920, 1080).
"""
vfilename = padfile.make_path(
directory=self.original_directory,
extension=self.original_extension)
for retval in frames(vfilename):
yield retval
@property
def frame_shape(self):
return OULUNPU_FRAME_SHAPE
def number_of_frames(self, padfile):
"""Returns the number of frames in a video file.
def annotations(self, padfile):
"""Reads the annotations for the given padfile.
Parameters
----------
padfile : :any:`File`
The high-level pad file
Returns
-------
int
The number of frames.
"""
vfilename = padfile.make_path(
directory=self.original_directory,
extension=self.original_extension)
return number_of_frames(vfilename)
@property
def frame_shape(self):
"""Returns the size of each frame in this database.
The file object for which the annotations should be read.
Returns
-------
(int, int, int)
The (#Channels, Height, Width) which is (3, 1920, 1080).
dict
The annotations as a dictionary, e.g.:
``{'0': {'reye':(re_y,re_x), 'leye':(le_y,le_x)}, ...}``
"""
return (3, 1920, 1080)
path = padfile.make_path(
directory=self.original_directory, extension='.txt')
annotations = {}
with open(path) as f:
for line in f:
line = line.strip()
if not line:
continue
num_frame, x_eye_left, y_eye_left, x_eye_right, y_eye_right = \
line.split(',')
annotations[num_frame] = {
'reye': (int(y_eye_right), int(x_eye_right)),
'leye': (int(y_eye_left), int(x_eye_left)),
}
return annotations
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment