diff --git a/MANIFEST.in b/MANIFEST.in index ee00970910914bfc8313f22271ff670bf746e7e5..7196e9f60d3039ff505005708ed53b46adf1819e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include README.rst bootstrap-buildout.py buildout.cfg COPYING version.txt requirements.txt recursive-include doc *.py *.rst *.ico *.png -recursive-include bob/pad/face/test/data *.hdf5 +recursive-include bob/pad/face/test/data *.hdf5 *.png diff --git a/bob/pad/face/__init__.py b/bob/pad/face/__init__.py index f42ae5389b813f1a2a9d7d9be7c1f78c5ad5200b..37b53c4ffc7dc1156ef21b4cb3352478828aefc6 100644 --- a/bob/pad/face/__init__.py +++ b/bob/pad/face/__init__.py @@ -1,4 +1,4 @@ -from . import algorithm, extractor, preprocessor, database +from . import algorithm, extractor, preprocessor, database, test def get_config(): diff --git a/bob/pad/face/test/data/test_image.png b/bob/pad/face/test/data/test_image.png new file mode 100644 index 0000000000000000000000000000000000000000..beabf86e61305f8bf66a578f2b9b4b7a4ca23ac9 Binary files /dev/null and b/bob/pad/face/test/data/test_image.png differ diff --git a/bob/pad/face/test/test.py b/bob/pad/face/test/test.py index 153e404b6ca1ec529f431c45a050d48ce50fdf21..7ec3460f88aba63b5cf5f2e7030ac38878410f29 100644 --- a/bob/pad/face/test/test.py +++ b/bob/pad/face/test/test.py @@ -3,14 +3,23 @@ """Test Units """ +#============================================================================== +# Import what is needed here: import numpy as np + from bob.io.base.test_utils import datafile + from bob.io.base import load + import bob.io.image # for image loading functionality + from bob.ip.color import rgb_to_gray + from ..extractor import LBPHistogram +from ..preprocessor import ImageFaceCrop +#============================================================================== def test_lbp_histogram(): lbp = LBPHistogram() img = load(datafile('testimage.jpg', 'bob.bio.face.test')) @@ -18,3 +27,25 @@ def test_lbp_histogram(): features = lbp(img) reference = load(datafile('lbp.hdf5', 'bob.pad.face.test')) 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