Skip to content
Snippets Groups Projects

Replace FrameCOntainer

Merged Anjith GEORGE requested to merge bob9 into master
3 files
+ 40
57
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 13
37
@@ -2,7 +2,7 @@
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import pkg_resources
import pkg_resources
import numpy
import numpy as np
from sqlalchemy import Table, Column, Integer, String, Boolean, Sequence, ForeignKey
from sqlalchemy import Table, Column, Integer, String, Boolean, Sequence, ForeignKey
from sqlalchemy.orm import backref
from sqlalchemy.orm import backref
@@ -11,8 +11,10 @@ from sqlalchemy.ext.declarative import declarative_base
@@ -11,8 +11,10 @@ from sqlalchemy.ext.declarative import declarative_base
from bob.db.base import File
from bob.db.base import File
from bob.db.base.sqlalchemy_migration import Enum, relationship
from bob.db.base.sqlalchemy_migration import Enum, relationship
 
from bob.bio.video import VideoLikeContainer
 
from bob.io.stream import StreamFile
from bob.io.stream import StreamFile
from bob.bio.video import FrameContainer
import bob.ip.stereo # It defines some streams operations (eg warp) that could be needed.
from .attack_dictionaries import idiap_type_id_config, idiap_subtype_id_config, idiap_pai_id_config
from .attack_dictionaries import idiap_type_id_config, idiap_subtype_id_config, idiap_pai_id_config
@@ -129,57 +131,31 @@ class VideoFile(Base, File):
@@ -129,57 +131,31 @@ class VideoFile(Base, File):
-------
-------
dict:
dict:
Dictionary where the key is the stream and
Dictionary where the key is the stream and
value is the data (i.e a FrameContainer).
value is the data (i.e a VideoLikeContainer).
"""
"""
def convert_arrays_to_frame_container(data):
""" Convert an input into Frame Container. Inputs is an iterable.
.. warning:: This function already exists in ``bob.pad.face`` !
Parameters
----------
data: :py:class:`numpy.ndarray`
Array containing the data, where the first dimension is the frame
Returns
-------
bob.bio.video:FrameContainer
FrameContainer containing the frames data.
"""
frame_container = FrameContainer()
for idx, item in enumerate(data):
frame_container.add(idx, item)
return frame_container
stream_config_path = pkg_resources.resource_filename('bob.io.stream', 'config/idiap_face_streams.json')
stream_config_path = pkg_resources.resource_filename('bob.io.stream', 'config/idiap_face_streams.json')
camera_config_path = pkg_resources.resource_filename('bob.ip.stereo', 'config/idiap_face_calibration.json')
camera_config_path = pkg_resources.resource_filename('bob.ip.stereo', 'config/idiap_face_calibration.json')
 
file_path = self.make_path(directory, extension)
file_path = self.make_path(directory, extension)
ret = {}
ret = {}
assert isinstance(streams, dict)
assert isinstance(streams, dict)
# set source
stream_file = StreamFile(file_path, stream_config_path)
stream_file.set_camera_configs(camera_config_path) # bob.ip.stereo adds this method to StreamFile
stream_file = StreamFile(file_path, stream_config_path, camera_config_path)
for name, video in streams.items():
video.set_source(stream_file)
# load and process
for name, video in streams.items():
step = video.shape[0] // n_frames
for name, stream in streams.items():
 
stream.set_source(stream_file)
 
step = stream.shape[0] // n_frames
# load data in format <frame, channel, height, width>
# load data in format <frame, channel, height, width>
data = video.load(slice(0, video.shape[0], step))
data = stream.load(slice(0, stream.shape[0], step))
# remove the empty dimension if there is only one channel
# remove the empty dimension if there is only one channel
if data.shape[1] == 1:
if data.shape[1] == 1:
data = data[:, 0, :, :]
data = data[:, 0, :, :]
ret[name] = convert_arrays_to_frame_container(data)
ret[name] = VideoLikeContainer(data, range(data.shape[0])) # Keep a trace of the indices in the original array ?
return ret
return ret
Loading