Skip to content
Snippets Groups Projects
Commit dcaa964d authored by Olegs NIKISINS's avatar Olegs NIKISINS
Browse files

Added unit test for the ImageFaceCrop preprocessor

parent 26095950
No related branches found
No related tags found
1 merge request!8Added unit tests for all preprocessors, extractors, algorithms, excluding qualitymeasure related stuff
Pipeline #
include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt requirements.txt include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt requirements.txt
recursive-include doc *.py *.rst *.ico *.png recursive-include doc *.py *.rst *.ico *.png
recursive-include bob/pad/face/test/data *.hdf5 recursive-include bob/pad/face/test/data *.hdf5 *.png
from . import algorithm, extractor, preprocessor, database from . import algorithm, extractor, preprocessor, database, test
def get_config(): def get_config():
......
bob/pad/face/test/data/test_image.png

190 KiB

...@@ -3,14 +3,23 @@ ...@@ -3,14 +3,23 @@
"""Test Units """Test Units
""" """
#==============================================================================
# Import what is needed here:
import numpy as np import numpy as np
from bob.io.base.test_utils import datafile from bob.io.base.test_utils import datafile
from bob.io.base import load from bob.io.base import load
import bob.io.image # for image loading functionality import bob.io.image # for image loading functionality
from bob.ip.color import rgb_to_gray from bob.ip.color import rgb_to_gray
from ..extractor import LBPHistogram from ..extractor import LBPHistogram
from ..preprocessor import ImageFaceCrop
#==============================================================================
def test_lbp_histogram(): def test_lbp_histogram():
lbp = LBPHistogram() lbp = LBPHistogram()
img = load(datafile('testimage.jpg', 'bob.bio.face.test')) img = load(datafile('testimage.jpg', 'bob.bio.face.test'))
...@@ -18,3 +27,25 @@ def test_lbp_histogram(): ...@@ -18,3 +27,25 @@ def test_lbp_histogram():
features = lbp(img) features = lbp(img)
reference = load(datafile('lbp.hdf5', 'bob.pad.face.test')) reference = load(datafile('lbp.hdf5', 'bob.pad.face.test'))
assert np.allclose(features, reference) assert np.allclose(features, reference)
#==============================================================================
def test_image_face_crop():
"""
Test ImageFaceCrop preprocessor, which is designed to crop faces in the images.
"""
image = load(datafile('test_image.png', 'bob.pad.face.test'))
annotations = {'topleft': (95, 155), 'bottomright': (215, 265)}
preprocessor = ImageFaceCrop(face_size = 64, rgb_output_flag = False)
face = preprocessor(image, annotations)
assert face.shape == (64, 64)
assert np.sum(face) == 429158
preprocessor = ImageFaceCrop(face_size = 64, rgb_output_flag = True)
face = preprocessor(image, annotations)
assert face.shape == (3, 64, 64)
assert np.sum(face) == 1215525
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment