From 54a5c9b59fc0bf598a0d1075eb05cff5ac4ac51b Mon Sep 17 00:00:00 2001 From: Brandon Amos Date: Thu, 9 Jun 2016 14:45:39 -0400 Subject: [PATCH] Add align_dlib.align for backwards compatibility. --- openface/align_dlib.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/openface/align_dlib.py b/openface/align_dlib.py index df4cac0..8ac1e10 100644 --- a/openface/align_dlib.py +++ b/openface/align_dlib.py @@ -146,6 +146,39 @@ class AlignDlib: points = self.predictor(rgbImg, bb) return list(map(lambda p: (p.x, p.y), points.parts())) + def align(self, imgDim, rgbImg, bb=None, + landmarks=None, landmarkIndices=INNER_EYES_AND_BOTTOM_LIP, + skipMulti=False, version=1): + r"""align(imgDim, rgbImg, bb=None, landmarks=None, landmarkIndices=INNER_EYES_AND_BOTTOM_LIP, version=1) + + Transform and align a face in an image. + + :param imgDim: The edge length in pixels of the square the image is resized to. + :type imgDim: int + :param rgbImg: RGB image to process. Shape: (height, width, 3) + :type rgbImg: numpy.ndarray + :param bb: Bounding box around the face to align. \ + Defaults to the largest face. + :type bb: dlib.rectangle + :param landmarks: Detected landmark locations. \ + Landmarks found on `bb` if not provided. + :type landmarks: list of (x,y) tuples + :param landmarkIndices: The indices to transform to. + :type landmarkIndices: list of ints + :param skipMulti: Skip image if more than one face detected. + :type skipMulti: bool + :param version: int + :return: The aligned RGB image. Shape: (imgDim, imgDim, 3) + :rtype: numpy.ndarray + """ + + if version == 1: + self.align_v1(imgDim, rgbImg, bb, landmarks, landmarkIndices, skipMulti) + elif version == 2: + self.align_v2(imgDim, rgbImg, bb, landmarks, landmarkIndices, skipMulti) + else: + assert False + def align_v1(self, imgDim, rgbImg, bb=None, landmarks=None, landmarkIndices=INNER_EYES_AND_BOTTOM_LIP, skipMulti=False):