  #!/usr/bin python3
  """ Face and landmarks detection for faceswap.py """
  
  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)
  
  
  class DetectedFace():
      """ Detected face and landmark information """
      def __init__(self, image=None, r=0, x=None,
 
</s> remove     def __init__(self, image=None, r=0, x=None,
                 w=None, y=None, h=None, landmarksXY=None):
 </s> add     def __init__(self, image=None, x=None, w=None, y=None, h=None,
                 landmarksXY=None): </s> remove         self.r = r
 </s> add  </s> remove         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}
 </s> add         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} </s> remove class DetectedFace():
    """ Detected face and landmark information """
    def __init__(self):
        self.image = None
        self.x = None
        self.w = None
        self.y = None
        self.h = None
        self.landmarksXY = None

    def alignment_to_face(self, image, alignment):
        """ Convert a face alignment to detected face object """
        self.image = image
        self.x = alignment["x"]
        self.w = alignment["w"]
        self.y = alignment["y"]
        self.h = alignment["h"]
        self.landmarksXY = alignment["landmarksXY"]

    def face_to_alignment(self, alignment):
        """ Convert a face alignment to detected face object """
        alignment["x"] = self.x
        alignment["w"] = self.w
        alignment["y"] = self.y
        alignment["h"] = self.h
        alignment["landmarksXY"] = self.landmarksXY
        return alignment

    def landmarks_as_xy(self):
        """ Landmarks as XY """
        return self.landmarksXY


 </s> add  </s> remove     def have_face(self, filename):
        """ return path of images that have faces """
        return os.path.basename(filename) in self.faces_detected

    def get_faces(self, image, rotation=0):
        """ Extract the faces from an image """
        faces_count = 0
        faces = detect_faces(image,
                             self.args.detector,
                             self.args.verbose,
                             rotation=rotation,
                             dlib_buffer=self.args.dlib_buffer,
                             mtcnn_kwargs=self.mtcnn_kwargs)

        for face in faces:
            if self.filter and not self.filter.check(face):
                if self.args.verbose:
                    print("Skipping not recognized face!")
                continue
            yield faces_count, face

            self.num_faces_detected += 1
            faces_count += 1

        if faces_count > 1 and self.args.verbose:
            self.verify_output = True

    def get_faces_alignments(self, filename, image):
        """ Retrieve the face alignments from an image """
        faces_count = 0
        faces = self.faces_detected[os.path.basename(filename)]
        for rawface in faces:
            face = DetectedFace(**rawface)
            # Rotate the image if necessary
            # NB: Rotation of landmarks now occurs at extract stage
            # This is here for legacy alignments
            if face.r != 0:
                image, _ = rotate_image_by_angle(image, face.r)
            face.image = image[face.y: face.y + face.h,
                               face.x: face.x + face.w]
            if self.filter and not self.filter.check(face):
                if self.args.verbose:
                    print("Skipping not recognized face!")
                continue
 </s> add class Images():
    """ Holds the full frames/images """
    def __init__(self, arguments):
        self.args = arguments
        self.input_images = self.get_input_images()
        self.images_found = len(self.input_images)
from dlib import rectangle as d_rectangle
  #!/usr/bin python3
  """ Face and landmarks detection for faceswap.py """
  
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
from dlib import rectangle as d_rectangle
  
  
  class DetectedFace():
      """ Detected face and landmark information """
      def __init__(self, image=None, r=0, x=None,
keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace 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 
lib/faces_detect.py