diff --git a/bob/ip/dlib/FaceDetector.py b/bob/ip/dlib/FaceDetector.py index 492eab78b57b08daba4476eebb57b6aebc258bd3..27f4cb6ef8fd7685658d45ab19dfef3027d01b48 100644 --- a/bob/ip/dlib/FaceDetector.py +++ b/bob/ip/dlib/FaceDetector.py @@ -36,12 +36,23 @@ class FaceDetector(object): """ assert image is not None + if len(image.shape) == 2: + rows, cols = image.shape + if len(image.shape) == 3: + _, rows, cols = image.shape + try: rectangles = self.face_detector(bob_to_dlib_image_convertion(image), 1) bbs = [] for r in rectangles: - bbs.append(BoundingBox((r.top(), r.left()), - (r.width(), r.height()), + + top = numpy.max( [0, r.top()] ) + left = numpy.max( [0, r.left()]) + height = numpy.min( [rows-top, r.height()] ) + width = numpy.min( [cols-left, r.width() ] ) + + bbs.append(BoundingBox((top, left), + (height, width), )) # This detector does not have the `quality` of the detection so I will fill it up with 100 diff --git a/bob/ip/dlib/data/test_image.hdf5 b/bob/ip/dlib/data/test_image.hdf5 new file mode 100644 index 0000000000000000000000000000000000000000..97e8729b28be23c925eca537ce3aaf8e5e519eb9 Binary files /dev/null and b/bob/ip/dlib/data/test_image.hdf5 differ diff --git a/bob/ip/dlib/test/test.py b/bob/ip/dlib/test/test.py index 235eec21de88f0e6e2fd9958ed930f03e21b00e4..7862e28988c6de178ef725f4648ad3c463edfae6 100644 --- a/bob/ip/dlib/test/test.py +++ b/bob/ip/dlib/test/test.py @@ -9,6 +9,10 @@ import numpy as np from .. import FaceDetector +import pkg_resources + +import bob.io.base + def test_face_detector(): """ Test FaceDetector class. @@ -24,4 +28,19 @@ def test_face_detector(): result = FaceDetector().detect_single_face(image) - assert result is None \ No newline at end of file + assert result is None + + # test on the actual image: + test_file = pkg_resources.resource_filename('bob.ip.dlib', 'data/test_image.hdf5') + + f = bob.io.base.HDF5File(test_file) #read only + image = f.read('image') #reads integer + del f + + result = FaceDetector().detect_single_face(image) + + assert result[0].topleft == (0, 236) + + assert result[0].bottomright == (84, 312) + +