Skip to content
Snippets Groups Projects
Commit 7e0056b4 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Merge branch 'dev_branch' into 'master'

This fixes the issue with negative coordinates in the face bounding box.

See merge request !4
parents ade99880 52b1f3f1
No related branches found
No related tags found
1 merge request!4This fixes the issue with negative coordinates in the face bounding box.
Pipeline #
...@@ -36,12 +36,23 @@ class FaceDetector(object): ...@@ -36,12 +36,23 @@ class FaceDetector(object):
""" """
assert image is not None assert image is not None
if len(image.shape) == 2:
rows, cols = image.shape
if len(image.shape) == 3:
_, rows, cols = image.shape
try: try:
rectangles = self.face_detector(bob_to_dlib_image_convertion(image), 1) rectangles = self.face_detector(bob_to_dlib_image_convertion(image), 1)
bbs = [] bbs = []
for r in rectangles: 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 # This detector does not have the `quality` of the detection so I will fill it up with 100
......
File added
...@@ -9,6 +9,10 @@ import numpy as np ...@@ -9,6 +9,10 @@ import numpy as np
from .. import FaceDetector from .. import FaceDetector
import pkg_resources
import bob.io.base
def test_face_detector(): def test_face_detector():
""" """
Test FaceDetector class. Test FaceDetector class.
...@@ -24,4 +28,19 @@ def test_face_detector(): ...@@ -24,4 +28,19 @@ def test_face_detector():
result = FaceDetector().detect_single_face(image) result = FaceDetector().detect_single_face(image)
assert result is None assert result is None
\ No newline at end of file
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment