In [1]:
from PythonWrapper.face_detection import *
In [2]:
import numpy as np
from landmarks_datasets import BioId
dataset = BioId()
images = dataset.loadImages()
ground_truth = dataset.loadGroundTruth()
bounding_boxes = dataset.loadBoundingBoxes()
training_set_size = 900
training_landmarks = ground_truth[:training_set_size]
mean_shape = np.zeros((20, 2))
face_detector = FaceDetector()
for i in range(training_set_size):
mean_shape += (training_landmarks[i] - bounding_boxes[i][:2]) / (bounding_boxes[i][2:] - np.asarray(bounding_boxes[i][:2]))
mean_shape /= training_set_size
In [3]:
import cv2
from tools import *
imgs = images[:20]
faces = bounding_boxes[:20]
for img, face in zip(imgs, faces):
cv2.rectangle(img, face[:2], face[2:], (0,0,0), 3)
adapted_mean_shape = (mean_shape * (face[2:] - np.asarray(face[:2]))) + face[:2]
for landmark in adapted_mean_shape:
cv2.circle(img, tuple(landmark.astype(np.int)), 3, (255,255,255), -1)
showMosaic(imgs, ncols=5)
In [4]:
%timeit face_detector.detectFaces(images[0])
In [5]: