                             [self.size - 1, self.size - 1],
                             [self.size - 1, 0]], np.int32)
          points = points.reshape((-1, 1, 2))
  
          mat = matrix * (self.size - 2 * self.padding)
          mat[:, 2] += self.padding
          mat = cv2.invertAffineTransform(mat)
          return [cv2.transform(points, mat)]
  
      def get_faces_for_frame(self, frame, update=False):
          """ Return the faces for the selected frame """
          if self.current_frame != frame or update:
              self.get_faces(frame)
          return self.faces
  
 
</s> remove         return self.extractor.extract(image, face, self.size, self.align_eyes)

    def original_roi(self, matrix):
        """ Return the original ROI of an extracted face """
        points = np.array([[0, 0], [0, self.size - 1],
                           [self.size - 1, self.size - 1],
                           [self.size - 1, 0]], np.int32)
        points = points.reshape((-1, 1, 2))
 </s> add         face.load_aligned(image,
                          size=self.size,
                          padding=self.padding,
                          align_eyes=self.align_eyes)
        return face </s> remove     def get_roi_for_frame(self, frame, update=False):
        """ Return the original rois for the selected frame """
        if self.current_frame != frame or update:
            self.get_faces(frame)
        return [self.original_roi(matrix) for matrix in self.matrices]

 </s> add  </s> remove 

class Extract():
    """ Based on the original https://www.reddit.com/r/deepfakes/
        code sample + contribs """

    def extract(self, image, face, size, align_eyes):
        """ Extract a face from an image """
        alignment = get_align_mat(face, size, align_eyes)
        extracted = self.transform(image, alignment, size, 48)
        return extracted, alignment

    @staticmethod
    def transform(image, mat, size, padding=0):
        """ Transform Image """
        matrix = mat * (size - 2 * padding)
        matrix[:, 2] += padding
        return cv2.warpAffine(image, matrix, (size, size))

    @staticmethod
    def transform_points(points, mat, size, padding=0):
        """ Transform points along matrix """
        matrix = mat * (size - 2 * padding)
        matrix[:, 2] += padding
        points = np.expand_dims(points, axis=1)
        points = cv2.transform(points, matrix, points.shape)
        points = np.squeeze(points)
        return points

    @staticmethod
    def get_feature_mask(aligned_landmarks_68, size,
                         padding=0, dilation=30):
        """ Return the face feature mask """
        scale = size - 2*padding
        translation = padding
        pad_mat = np.matrix([[scale, 0.0, translation],
                             [0.0, scale, translation]])
        aligned_landmarks_68 = np.expand_dims(aligned_landmarks_68, axis=1)
        aligned_landmarks_68 = cv2.transform(aligned_landmarks_68,
                                             pad_mat,
                                             aligned_landmarks_68.shape)
        aligned_landmarks_68 = np.squeeze(aligned_landmarks_68)

        (l_start, l_end) = FACIAL_LANDMARKS_IDXS["left_eye"]
        (r_start, r_end) = FACIAL_LANDMARKS_IDXS["right_eye"]
        (m_start, m_end) = FACIAL_LANDMARKS_IDXS["mouth"]
        (n_start, n_end) = FACIAL_LANDMARKS_IDXS["nose"]
        (lb_start, lb_end) = FACIAL_LANDMARKS_IDXS["left_eyebrow"]
        (rb_start, rb_end) = FACIAL_LANDMARKS_IDXS["right_eyebrow"]
        (c_start, c_end) = FACIAL_LANDMARKS_IDXS["chin"]

        l_eye_points = aligned_landmarks_68[l_start:l_end].tolist()
        l_brow_points = aligned_landmarks_68[lb_start:lb_end].tolist()
        r_eye_points = aligned_landmarks_68[r_start:r_end].tolist()
        r_brow_points = aligned_landmarks_68[rb_start:rb_end].tolist()
        nose_points = aligned_landmarks_68[n_start:n_end].tolist()
        chin_points = aligned_landmarks_68[c_start:c_end].tolist()
        mouth_points = aligned_landmarks_68[m_start:m_end].tolist()
        l_eye_points = l_eye_points + l_brow_points
        r_eye_points = r_eye_points + r_brow_points
        mouth_points = mouth_points + nose_points + chin_points

        l_eye_hull = cv2.convexHull(np.array(l_eye_points).reshape(
            (-1, 2)).astype(int)).flatten().reshape((-1, 2))
        r_eye_hull = cv2.convexHull(np.array(r_eye_points).reshape(
            (-1, 2)).astype(int)).flatten().reshape((-1, 2))
        mouth_hull = cv2.convexHull(np.array(mouth_points).reshape(
            (-1, 2)).astype(int)).flatten().reshape((-1, 2))

        mask = np.zeros((size, size, 3), dtype=float)
        cv2.fillConvexPoly(mask, l_eye_hull, (1, 1, 1))
        cv2.fillConvexPoly(mask, r_eye_hull, (1, 1, 1))
        cv2.fillConvexPoly(mask, mouth_hull, (1, 1, 1))

        if dilation > 0:
            kernel = np.ones((dilation, dilation), np.uint8)
            mask = cv2.dilate(mask, kernel, iterations=1)

        return mask
 </s> add  </s> remove 
    def get_aligned_landmarks_for_frame(self, frame, landmarks_xy,
                                        update=False):
        """ Return the transposed landmarks for the selected face """
        if self.current_frame != frame or update:
            self.get_faces(frame)
        aligned_landmarks = list()
        if not self.matrices:
            return aligned_landmarks
        for idx, landmarks in enumerate(landmarks_xy):
            matrix = self.matrices[idx]
            aligned_landmarks.append(
                self.extractor.transform_points(landmarks,
                                                matrix,
                                                self.size,
                                                self.padding))
        return aligned_landmarks
 </s> add  </s> remove         for matrix in self.matrices:
            original_roi = self.original_roi(matrix)[0].squeeze()
            top_left, top_right = original_roi[0], original_roi[3]
 </s> add         for face in self.faces:
            top_left, top_right = face.original_roi[0], face.original_roi[3]
    def get_faces_in_frame(self, frame, update=False):
                             [self.size - 1, self.size - 1],
                             [self.size - 1, 0]], np.int32)
          points = points.reshape((-1, 1, 2))
  
    def get_faces_in_frame(self, frame, update=False):
    def get_faces_in_frame(self, frame, update=False):
    def get_faces_in_frame(self, frame, update=False):
    def get_faces_in_frame(self, frame, update=False):
    def get_faces_in_frame(self, frame, update=False):
    def get_faces_in_frame(self, frame, update=False):
          """ Return the faces for the selected frame """
          if self.current_frame != frame or update:
              self.get_faces(frame)
          return self.faces
  
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Fix convert-adjust (#531)

* Add dimensions to alignments + refactor

* Add frame_dims + funcs to DetectFaces. Add alignments lib

* Convert Adjust working

* Refactor and tidy up 
tools/lib_alignments/media.py