          self.last_move = (pt_x, pt_y)
  
      def update_landmarks(self):
          """ Update the landmarks """
          self.extract.execute(self.media["image"],
                               manual_face=self.media["bounding_box"])
          landmarks = self.extract.landmarks[0][1]
          left, top, right, bottom = self.media["bounding_box"]
          alignment = {"x": left,
                       "w": right - left,
                       "y": top,
                       "h": bottom - top,
                       "landmarksXY": landmarks}
          frame = self.media["frame_id"]
  
          if self.interface.get_selected_face_id() is None:
              idx = self.alignments.add_alignment(frame, alignment)
              self.interface.set_state_value("edit", "selected", idx)
 
</s> remove from lib import face_alignment


def detect_faces(frame, detector, verbose, rotation=0,
                 dlib_buffer=64, mtcnn_kwargs=None):
    """ Detect faces and draw landmarks in an image """
    face_detect = face_alignment.Extract(frame,
                                         detector,
                                         dlib_buffer,
                                         mtcnn_kwargs,
                                         verbose)
    for face in face_detect.landmarks:
        ax_x, ax_y = face[0][0], face[0][1]
        right, bottom = face[0][2], face[0][3]
        landmarks = face[1]

        yield DetectedFace(frame[ax_y: bottom, ax_x: right],
                           rotation,
                           ax_x,
                           right - ax_x,
                           ax_y,
                           bottom - ax_y,
                           landmarksXY=landmarks)
 </s> add from dlib import rectangle as d_rectangle </s> remove             landmarks = face_alignment.Extract(
                input_image_bgr=cv2.imread(img),
                detector='dlib-cnn',
                verbose=True,
                input_is_predetected_face=True).landmarks
            img_list.append([img, np.array(landmarks[0][1])
 </s> add             landmarks = self.get_landmarks(img)
            img_list.append([img, np.array(landmarks) </s> remove             landmarks = face_alignment.Extract(
                input_image_bgr=cv2.imread(img),
                detector='dlib-cnn',
                verbose=True,
                input_is_predetected_face=True).landmarks
            img_list.append([img, np.array(landmarks[0][1])
 </s> add             landmarks = self.get_landmarks(img)
            img_list.append([img, np.array(landmarks) </s> remove     pnt_x = min([pnt[0] for pnt in rotated[0]])
    pnt_y = min([pnt[1] for pnt in rotated[0]])
    pnt_x1 = max([pnt[0] for pnt in rotated[0]])
    pnt_y1 = max([pnt[1] for pnt in rotated[0]])
    face.x = int(pnt_x)
    face.y = int(pnt_y)
    face.w = int(pnt_x1 - pnt_x)
    face.h = int(pnt_y1 - pnt_y)
    face.r = 0
    face.landmarksXY = [tuple(point) for point in rotated[1].tolist()]
 </s> add     pt_x = min([pnt[0] for pnt in rotated[0]])
    pt_y = min([pnt[1] for pnt in rotated[0]])
    pt_x1 = max([pnt[0] for pnt in rotated[0]])
    pt_y1 = max([pnt[1] for pnt in rotated[0]])

    if isinstance(face, DetectedFace):
        face.x = int(pt_x)
        face.y = int(pt_y)
        face.w = int(pt_x1 - pt_x)
        face.h = int(pt_y1 - pt_y)
        face.r = 0
        if len(rotated) > 1:
            face.landmarksXY = [tuple(point) for point in rotated[1].tolist()]
    elif isinstance(face, dict):
        face["x"] = int(pt_x)
        face["y"] = int(pt_y)
        face["w"] = int(pt_x1 - pt_x)
        face["h"] = int(pt_y1 - pt_y)
        face["r"] = 0
        if len(rotated) > 1:
            face["landmarksXY"] = [tuple(point)
                                   for point in rotated[1].tolist()]
    else:
        face = dlib.rectangle(int(pt_x), int(pt_y), int(pt_x1), int(pt_y1))
 </s> remove         self.rotation_width = 0
        self.rotation_height = 0

    def get_rotation_angles(self):
        """ Set the rotation angles. Includes backwards compatibility for the
            'on' and 'off' options:
                - 'on' - increment 90 degrees
                - 'off' - disable
                - 0 is prepended to the list, as whatever happens, we want to
                  scan the image in it's upright state """
        rotation_angles = [0]

        if (not hasattr(self.args, 'rotate_images')
                or not self.args.rotate_images
                or self.args.rotate_images == "off"):
            return rotation_angles

        if self.args.rotate_images == "on":
            rotation_angles.extend(range(90, 360, 90))
        else:
            passed_angles = [int(angle)
                             for angle in self.args.rotate_images.split(",")]
            if len(passed_angles) == 1:
                rotation_step_size = passed_angles[0]
                rotation_angles.extend(range(rotation_step_size,
                                             360,
                                             rotation_step_size))
            elif len(passed_angles) > 1:
                rotation_angles.extend(passed_angles)

        return rotation_angles

    def get_already_processed(self):
        """ Return the images that already exist in the output directory """
        print("Output Directory: {}".format(self.args.output_dir))

        if (not hasattr(self.args, 'skip_existing')
                or not self.args.skip_existing):
            return None
 </s> add     def frames_count(self):
        """ Return current frames count """
        return len(self.data)
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
          self.last_move = (pt_x, pt_y)
  
      def update_landmarks(self):
          """ Update the landmarks """
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
        queue_manager.get_queue("in").put((self.media["image"],
                                           self.media["bounding_box"]))
        landmarks = queue_manager.get_queue("out").get()
        if landmarks == "EOF":
            exit(0)
        face = landmarks["detected_faces"][0]
        alignment = {"x": face.x,
                     "w": face.w,
                     "y": face.y,
                     "h": face.h,
                     "landmarksXY": face.landmarksXY}
          frame = self.media["frame_id"]
  
          if self.interface.get_selected_face_id() is None:
              idx = self.alignments.add_alignment(frame, alignment)
              self.interface.set_state_value("edit", "selected", idx)
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Extraction - Speed improvements (#522) (#523)

* Extraction - Speed improvements (#522)

* Initial Plugin restructure

* Detectors to plugins. Detector speed improvements

* Re-implement dlib aligner, remove models, FAN to TF. Parallel processing

* Update manual, update convert, implement parallel/serial switching

* linting + fix cuda check (setup.py). requirements update keras 2.2.4

* Add extract size option. Fix dlib hog init

* GUI: Increase tooltip width

* Update alignment tool to support new DetectedFace

* Add skip existing faces option

* Fix sort tool to new plugin structure

* remove old align plugin

* fix convert -skip faces bug

* Fix convert skipping no faces frames

* Convert - draw onto transparent layer

* Fix blur threshold bug

* fix skip_faces convert bug

* Fix training 
tools/lib_alignments/jobs_manual.py