query.py 2.2 KB
Newer Older
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
1
from pkg_resources import resource_filename
2 3 4
from bob.pad.base.database import FileListPadDatabase
from bob.pad.face.database import VideoPadFile
from bob.pad.face.utils import frames, number_of_frames
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
5 6
# documentation imports
import numpy
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
7 8


9
class File(VideoPadFile):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
10 11 12 13 14 15 16 17
    """The file objects of the OULU-NPU dataset."""
    pass


class Database(FileListPadDatabase):
    """The database interface for the OULU-NPU dataset."""

    def __init__(self, original_directory=None,
18
                 name='oulunpu', bio_file_class=None,
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
19
                 original_extension=".avi", **kwargs):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
20 21 22 23 24 25 26
        if bio_file_class is None:
            bio_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,
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
27
            original_extension=original_extension,
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
28
            **kwargs)
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
29 30

    def frames(self, padfile):
31
        """Yields the frames of the padfile one by one.
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
32 33 34 35

        Parameters
        ----------
        padfile : :any:`File`
36
            The high-level pad file
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
37 38 39 40

        Yields
        ------
        :any:`numpy.array`
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
41
            A frame of the video. The size is (3, 1920, 1080).
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
42 43 44 45 46 47
        """
        vfilename = padfile.make_path(
            directory=self.original_directory,
            extension=self.original_extension)
        for retval in frames(vfilename):
            yield retval
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    def number_of_frames(self, padfile):
        """Returns the number of frames in a video file.

        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.

        Returns
        -------
        (int, int, int)
            The (#Channels, Height, Width) which is (3, 1920, 1080).
        """
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
76
        return (3, 1920, 1080)