Skip to content
Snippets Groups Projects
Commit f4f3bb3a authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Open-source release

parents
Branches
Tags
No related merge requests found
Showing
with 894 additions and 0 deletions
*~
*.swp
*.pyc
bin
eggs
parts
build
.installed.cfg
*.egg-info
develop-eggs
sphinx
dist
.nfs*
*.egg
.coverage
*.aux
*.bbl
*.blg
*.log
*.out
*.vrb
*.nav
*.snm
*.toc
.~lock.*
*.pyg
.DS_Store
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.web module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
===========================================================
Authors of the Biometrics Evaluation and Testing Platform
===========================================================
Andre Anjos <andre.anjos@idiap.ch>
Flavio Tarsetti <flavio.tarsetti@idiap.ch>
Laurent El-Shafey <laurent.el-shafey@idiap.ch>
Philip Abbet <philip.abbet@idiap.ch>
Samuel Gaist <samuel.gaist@idiap.ch>
Sebastien Marcel <sebastien.marcel@idiap.ch>
This diff is collapsed.
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
====================
BEAT Contributions
====================
This package contains a set of contributions for different domains to which the
BEAT platform is applicable. It contains databases, dataformats, algorithms,
experiments and toolchain definitions for a variety of experiments.
Installation
------------
Include this package into your ``buildout.cfg`` to make use of it. Use
``mr.developer`` to fetch it from `our git repository`_.
Support
-------
For support, contact the platform developers through `our mailing list`_.
.. External links
.. _our mailing list: https://groups.google.com/forum/#!forum/beat-devel
.. _our git repository: https://gitlab.idiap.ch/biometric/beat.databases.git
{
"parameters": {
"radius": {
"default": 1,
"type": "uint32",
"description": "LBP radius in pixels"
},
"num-neighbors": {
"default": 8,
"type": "uint32",
"description": "Number of points to be used for the LBP operator"
}
},
"language": "python",
"uses": {},
"groups": [
{
"inputs": {
"input_frames": {
"type": "system/array_3d_uint8/1"
}
},
"name": "main",
"outputs": {
"lbp_feature_vector": {
"type": "system/array_1d_floats/1"
}
}
}
],
"splittable": true,
"description": "Computes normalized LBP histogram, averaged over frames of the video"
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import bob.ip.base
class Algorithm:
def __init__(self):
self.radius = 1
self.num_neighbors = 8
def setup(self, parameters):
self.radius = int(parameters.get('radius', self.radius))
self.num_neighbors = int(parameters.get('num-neighbors', self.num_neighbors))
return True
def process(self, inputs, outputs):
frames = inputs["input_frames"].data.value
lbp = bob.ip.base.LBP(neighbors=self.num_neighbors, uniform=True, circular=True, radius=self.radius)
feat_vector = numpy.zeros(lbp.max_label, dtype='float64')
for i in range(frames.shape[0]):
frame = frames[0]
lbpimage = numpy.zeros(lbp.get_lbp_shape(frame), 'uint16') # allocating the image with lbp codes
lbp(frame, lbpimage) # calculating the lbp image
hist = bob.ip.base.histogram(lbpimage, 0, lbp.max_label-1, lbp.max_label)
hist = hist / sum(hist)
feat_vector = feat_vector + hist
feat_vector = feat_vector / frames.shape[0]
outputs["lbp_feature_vector"].write({
'value': feat_vector,
})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm computes LBP-based feature vector. For a given input set of frames in a video,
it computes the normalized LBP histogram. Then, it computes the final feature vector on video
level, by averaging the normalized LBP histograms.
The used LBP operator is computed over a circular neighborhood and is uniform.
Details about LBP operator can be found in [Ojala02]_
This algorithm relies on the `Bob <http://www.idiap.ch/software/bob>`_ library.
.. [Ojala02] Ojala, Pietikainen and Maenpaa: Multiresolution gray-scale and rotation invariant texture classification with Local Binary Patterns. IEEE Transactions on Pattern Analysis and Machine inteligence 2002
{
"description": "Implements the Linear and Mel Frequency Cepstal Coefficients (MFCC and LFCC)",
"language": "python",
"splittable": true,
"groups": [
{
"inputs": {
"speech": {
"type": "{{ system_user.username }}/array_1d_floats/1"
},
"vad": {
"type": "{{ system_user.username }}/array_1d_integers/1"
}
},
"outputs": {
"features": {
"type": "{{ system_user.username }}/array_2d_floats/1"
}
}
}
],
"parameters": {
"rate": {
"default": "16000.0",
"type": "float64",
"description": "sampling rate"
}
}
}
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import bob.ap
def normalize_std_array(vector):
"""Applies a unit mean and variance normalization to an arrayset"""
# Initializes variables
length = 1
n_samples = len(vector)
mean = numpy.ndarray((length,), 'float64')
std = numpy.ndarray((length,), 'float64')
mean.fill(0)
std.fill(0)
# Computes mean and variance
for array in vector:
x = array.astype('float64')
mean += x
std += (x ** 2)
mean /= n_samples
std /= n_samples
std -= (mean ** 2)
std = std ** 0.5
arrayset = numpy.ndarray(shape=(n_samples,mean.shape[0]), dtype=numpy.float64)
for i in range (0, n_samples):
arrayset[i,:] = (vector[i]-mean) / std
return arrayset
class Algorithm:
def __init__(self):
self.win_length_ms = 20
self.win_shift_ms = 10
self.n_filters = 24
self.n_ceps = 19
self.f_min = 0
self.f_max = 4000
self.delta_win = 2
self.pre_emphasis_coef = 0.95
self.dct_norm = False
self.mel_scale = True
self.withEnergy = True
self.withDelta = True
self.withDeltaDelta = True
#TODO: find a way to compute this automatically
self.rate = 16000
self.features_mask = numpy.arange(0,60)
self.normalizeFeatures = True
def setup(self, parameters):
self.rate = parameters.get('rate', self.rate)
wl = self.win_length_ms
ws = self.win_shift_ms
nf = self.n_filters
nc = self.n_ceps
f_min = self.f_min
f_max = self.f_max
dw = self.delta_win
pre = self.pre_emphasis_coef
rate = self.rate
normalizeFeatures = self.normalizeFeatures
self.extractor = bob.ap.Ceps(rate, wl, ws, nf, nc, f_min, f_max, dw, pre)
self.extractor.dct_norm = self.dct_norm
self.extractor.mel_scale = self.mel_scale
self.extractor.with_energy = self.withEnergy
self.extractor.with_delta = self.withDelta
self.extractor.with_delta_delta = self.withDeltaDelta
return True
def normalize_features(self, params):
#########################
## Initialisation part ##
#########################
normalized_vector = [ [ 0 for i in range(params.shape[1]) ] for j in range(params.shape[0]) ]
for index in range(params.shape[1]):
vector = numpy.array([row[index] for row in params])
n_samples = len(vector)
norm_vector = normalize_std_array(vector)
for i in range(n_samples):
normalized_vector[i][index]=numpy.asscalar(norm_vector[i])
data = numpy.array(normalized_vector)
return data
def process(self, inputs, outputs):
float_wav = inputs["speech"].data.value
labels = inputs["vad"].data.value
cepstral_features = self.extractor(float_wav)
features_mask = self.features_mask
filtered_features = numpy.ndarray(shape=((labels == 1).sum(),len(features_mask)), dtype=numpy.float64)
i=0
cur_i=0
for row in cepstral_features:
if i < len(labels):
if labels[i]==1:
for k in range(len(features_mask)):
filtered_features[cur_i,k] = row[features_mask[k]]
cur_i = cur_i + 1
i = i+1
else:
if labels[-1]==1:
if cur_i == cepstral_features.shape[0]:
for k in range(len(features_mask)):
filtered_features[cur_i,k] = row[features_mask[k]]
cur_i = cur_i + 1
i = i+1
if self.normalizeFeatures:
normalized_features = self.normalize_features(filtered_features)
else:
normalized_features = filtered_features
if normalized_features.shape[0] == 0:
#print("Warning: no speech found in: %s" % input_file)
# But do not keep it empty!!! This avoids errors in next steps
normalized_features=numpy.array([numpy.zeros(len(features_mask))])
outputs["features"].write({
'value': numpy.vstack(normalized_features)
})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm implements Mel-frequency cepstral coefficients (MFCC) and
linear-frequency cepstral coefficients (LFCC) feature extraction.
This algorithm relies on the `Bob <http://www.idiap.ch/software/bob/>`_ library.
The following parameters are set inside the algorithm and could be modified by forking
this algorithm:
* `win_length_ms`: length of the processing window
* `win_shift_ms`: length of the shift
* `n_filters`: number of filters
* `n_ceps`: number of cepstal coefficients
* `f_min`: minimum frequency
* `f_max`: maximum frequency
* `delta_win`: window on which first and second derivatives are computed
* `pre_emphasis_coeff`: pre-emphasis coefficient
* `mel_scale`: flag for Mel scale
* `dct_norm`: DCT normalization
* `with_delta`: flag for computing the first derivatives
* `with_delta_delta`: flag for computing the second derivatives
* `with_energy`: flag for computing the energy
* `features_mask`: mask to use only a sub-set of features
* `normalizeFeatures`: flag to do zero-mean and variance normalization
{
"parameters": {},
"language": "python",
"uses": {},
"groups": [
{
"inputs": {
"feature_vectors": {
"type": "system/array_1d_floats/1"
}
},
"name": "probes",
"outputs": {
"scores": {
"type": "system/float/1"
}
}
},
{
"inputs": {
"machine": {
"type": "system/array_1d_floats/1"
}
},
"name": "train"
}
],
"splittable": true,
"description": "Compares a histogram to a histogram model using a Chi-2 distance"
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
class Algorithm:
def __init__(self):
self.data = []
self.machine = None
def process(self, inputs, outputs):
if self.machine == None:
inputs['machine'].next()
self.machine = inputs["machine"].data.value
sample = inputs['feature_vectors'].data.value
tmp = numpy.square(sample - self.machine)
tmp = numpy.nan_to_num(numpy.divide(tmp, self.machine))
score = -numpy.sum(tmp)
outputs["scores"].write({'value': score})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm compares an input histogram to a histogram model.
It computes a score between the input histogram and the model using Chi-2 distance measurement.
{
"parameters": {
"normed-height": {
"default": 64,
"type": "uint32",
"description": "Height of the face bounding box after size normalization"
},
"normed-width": {
"default": 64,
"type": "uint32",
"description": "Width of the face bounding box after size normalization"
},
"minimum-face-size": {
"default": 50,
"type": "uint32",
"description": "Frames with face bounding box smaller than this will be discarded"
}
},
"language": "python",
"uses": {},
"groups": [
{
"inputs": {
"video": {
"type": "system/array_4d_uint8/1"
},
"annotations": {
"type": "system/bounding_box_video/1"
}
},
"name": "main",
"outputs": {
"cropped_faces": {
"type": "system/array_3d_uint8/1"
}
}
}
],
"splittable": true,
"description": "Crops face bounding boxes on videos and normalises them by size"
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import bob.ip.base
import bob.ip.color
class Algorithm:
def __init__(self):
self.normed_height = 64
self.normed_width = 64
self.minimum_face_size = 50 # minimum size of a valid face
def setup(self, parameters):
self.normed_height = parameters.get('crop-height', self.normed_height)
self.normed_width = parameters.get('crop-width', self.normed_width)
self.minimum_face_size = parameters.get('minimum-face-size', self.minimum_face_size)
return True
def process(self, inputs, outputs):
video = inputs["video"].data.value
annotations = inputs["annotations"].data.value
output = []
for i in range(video.shape[0]): #range(video.shape[0], -1, -1):
frame = bob.ip.color.rgb_to_gray(video[i,:,:,:])
if annotations[i].height < self.minimum_face_size or annotations[i].width < self.minimum_face_size:
continue # don't add the invalid frames
cropped_face = bob.ip.base.crop(frame,
int(getattr(annotations[i], 'top-left-y')),
int(getattr(annotations[i], 'top-left-x')),
int(annotations[i].height),
int(annotations[i].width),
)
tempbbx = numpy.zeros((self.normed_height, self.normed_width), dtype='float64')
bob.ip.base.scale(cropped_face, tempbbx) # normalization
tempbbx += 0.5
output.append(numpy.floor(tempbbx).astype('uint8'))
outputs["cropped_faces"].write({'value': numpy.array(output)})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm performs pre-processing of the input videos in two steps:
1. Cropping the face bounding box from each frame of the video based on the input face files.
Faces with face bounding box smaller than `minimum-face-size` parameter will be discarded.
2. Normalizes the face bouding boxes by size, depending on the parameters `normed-width` and `normed-height`.
This algorithm relies on the `Bob <http://www.idiap.ch/software/bob/>`_ library for cropping
and scaling the video frame images.
{
"description": "Crop and normalize a face from an RGB image",
"language": "python",
"splittable": true,
"groups": [
{
"inputs": {
"image": {
"type": "{{ system_user.username }}/array_3d_uint8/1"
},
"eye_centers": {
"type": "{{ system_user.username }}/eye_positions/1"
}
},
"outputs": {
"cropped_image": {
"type": "{{ system_user.username }}/array_2d_floats/1"
}
}
}
],
"parameters": {
"crop-height": {
"default": "80",
"type": "uint32",
"description": "height of the resulting cropped image"
},
"crop-width": {
"default": "64",
"type": "uint32",
"description": "width of the resulting cropped image"
},
"right-eye-y": {
"default": "16",
"type": "uint32",
"description": "y-coordinate of the right eye on the cropped image"
},
"right-eye-x": {
"default": "15",
"type": "uint32",
"description": "x-coordinate of the right eye on the cropped image"
},
"left-eye-y": {
"default": "16",
"type": "uint32",
"description": "y-coordinate of the left eye on the cropped image"
},
"left-eye-x": {
"default": "48",
"type": "uint32",
"description": "x-coordinate of the left eye on the cropped image"
}
}
}
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import bob.ip.base
import bob.ip.color
class Algorithm:
def __init__(self):
self.crop_height = 80
self.crop_width = 64
self.right_eye_y = 16
self.right_eye_x = 15
self.left_eye_y = 16
self.left_eye_x = 48
def setup(self, parameters):
self.crop_height = parameters.get('crop-height', self.crop_height)
self.crop_width = parameters.get('crop-width', self.crop_width)
self.right_eye_y = parameters.get('right-eye-y', self.right_eye_y)
self.right_eye_x = parameters.get('right-eye-x', self.right_eye_x)
self.left_eye_y = parameters.get('left-eye-y', self.left_eye_y)
self.left_eye_x = parameters.get('left-eye-x', self.left_eye_x)
self.cropper = bob.ip.base.FaceEyesNorm(self.crop_height,
self.crop_width, self.right_eye_y, self.right_eye_x,
self.left_eye_y, self.left_eye_x)
return True
def process(self, inputs, outputs):
image = bob.ip.color.rgb_to_gray(inputs["image"].data.value)
eye_positions = inputs["eye_centers"].data
outputs["cropped_image"].write({
'value': self.cropper(
image,
float(eye_positions.right.y),
float(eye_positions.right.x),
float(eye_positions.left.y),
float(eye_positions.left.x)
)
})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm performs a RGB to grayscale conversion of an image
followed by a face cropping, given the eye center coordinates.
This implementation relies on the `Bob <http://www.idiap.ch/software/bob>`_ library.
The inputs are:
* `image`: an RGB image as a three-dimensional array of uint8, the first dimension
being the number of color planes (3), and the second and third dimensions
corresponding to the height and width of the original image, respectively.
* `eye_centers`: the coordinates of the eye centers in the original image space
The output `cropped_image` is a grayscale cropped image as a two-dimensional array
of floats (64 bits).
{
"description":"Extract DCT features for the parts-based Face Recognition",
"language": "python",
"splittable": true,
"groups": [
{
"inputs": {
"image": {
"type": "{{ system_user.username }}/array_2d_floats/1"
}
},
"outputs": {
"features": {
"type": "{{ system_user.username }}/array_2d_floats/1"
}
}
}
],
"parameters": {
"block-size": {
"default": "12",
"type": "uint32",
"description":"Size of the block (in pixels)"
},
"block-overlap": {
"default": "11",
"type": "uint32",
"description":"Size of the block overlap (in pixels)"
},
"number-of-components": {
"default": "45",
"type": "uint32",
"description":"Number of the DCT components kept per block (using the zig-zag ordering)"
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment