diff --git a/bob/pad/face/test/test.py b/bob/pad/face/test/test.py index ac1078e42c5fb5509af2a2ea0d7a124bb6a3afeb..799d8efb2b6a0506776dfd07e4b10516b6fd8c83 100644 --- a/bob/pad/face/test/test.py +++ b/bob/pad/face/test/test.py @@ -35,8 +35,40 @@ from ..algorithm import VideoSvmPadAlgorithm from ..algorithm import VideoGmmPadAlgorithm +from ..utils import face_detection_utils + import random + + +def test_detect_face_landmarks_in_image(): + + img = load(datafile('testimage.jpg', 'bob.bio.face.test')) + assert len(img) == 3 + annotations = face_detection_utils.detect_face_landmarks_in_image(img) + assert len(annotations['landmarks']) == 68 + assert len(annotations['left_eye']) == 2 + assert len(annotations['right_eye']) == 2 + assert len(annotations['topleft']) == 2 + assert len(annotations['bottomright']) == 2 + + #assert len(annotations['left_eye']) == (176, 220) + + + +def test_detect_face_landmarks_in_video(): + + img = load(datafile('testimage.jpg', 'bob.bio.face.test')) + assert len(img) == 3 + frame_container= bob.bio.video.FrameContainer() + frame_container.add(1,img) + frame_container.add(2,img) + + annotations = face_detection_utils.detect_face_landmarks_in_video(frame_container) + assert len(annotations) == 2 + assert len(annotations['1']['landmarks']) == 68 + + #============================================================================== def test_lbp_histogram(): lbp = LBPHistogram() diff --git a/bob/pad/face/utils/face_detection_utils.py b/bob/pad/face/utils/face_detection_utils.py index aaa26da0a49e98143eb6dbda5693b80239c972da..0ba1f2308344618aaba65a889722d90acc2731ed 100644 --- a/bob/pad/face/utils/face_detection_utils.py +++ b/bob/pad/face/utils/face_detection_utils.py @@ -122,11 +122,11 @@ def getEyePos(lm): # Mean position of eye corners as eye centers , casted to int() - left_eye_t=(lm[36,:]+lm[39,:])/2.0 - right_eye_t=(lm[42,:]+lm[45,:])/2.0 + left_eye_t = (lm[36,:] + lm[39,:])/2.0 + right_eye_t = (lm[42,:] + lm[45,:])/2.0 - right_eye=(int(left_eye_t[1]),int(left_eye_t[0])) - left_eye=(int(right_eye_t[1]),int(right_eye_t[0])) + right_eye = (int(left_eye_t[1]),int(left_eye_t[0])) + left_eye = (int(right_eye_t[1]),int(right_eye_t[0])) return right_eye,left_eye @@ -173,18 +173,18 @@ def detect_face_landmarks_in_image(image, method = "dlib"): if kp is not None: - lm=np.vstack((kp.landmarks[:,1],kp.landmarks[:,0])).T + lm = np.vstack((kp.landmarks[:,1],kp.landmarks[:,0])).T - right_eye,left_eye=getEyePos(lm) + right_eye,left_eye = getEyePos(lm) - points=[] + points = [] for i in range(lm.shape[0]): points.append((int(lm[i,0]),int(lm[i,1]))) - annotations['topleft']=kp.bounding_box.topleft - annotations['bottomright']=kp.bounding_box.bottomright - annotations['landmarks']=points # list of landmarks + annotations['topleft'] = kp.bounding_box.topleft + annotations['bottomright'] = kp.bounding_box.bottomright + annotations['landmarks'] = points # list of landmarks annotations['left_eye'] = left_eye annotations['right_eye'] = right_eye