BraUndress commited on
Commit
6d37881
·
verified ·
1 Parent(s): 9c0af3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -8,12 +8,6 @@ import imageio
8
 
9
  class FaceSwapper:
10
  def __init__(self):
11
- self.face_mesh = mp.solutions.face_mesh.FaceMesh(
12
- static_image_mode=True,
13
- max_num_faces=1,
14
- refine_landmarks=True,
15
- min_detection_confidence=0.5
16
- )
17
  self.landmarks_a = None
18
  self.landmarks_b = None
19
  self.image_a = None
@@ -22,17 +16,18 @@ class FaceSwapper:
22
  self.image_b_origin = None
23
 
24
  def get_face_landmarks(self, image):
25
- with self.mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=1, refine_landmarks=True, min_detection_confidence=0.5) as face_mesh:
26
- image_np = np.array(image)
27
- results = face_mesh.process(cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB))
28
-
 
 
 
29
  if not results.multi_face_landmarks:
30
  return None
31
-
32
  landmarks = results.multi_face_landmarks[0].landmark
33
  w, h = image.size
34
  face_landmarks = [(int(p.x * w), int(p.y * h)) for p in landmarks]
35
-
36
  return face_landmarks
37
 
38
  def load_images(self, image_a, image_b):
 
8
 
9
  class FaceSwapper:
10
  def __init__(self):
 
 
 
 
 
 
11
  self.landmarks_a = None
12
  self.landmarks_b = None
13
  self.image_a = None
 
16
  self.image_b_origin = None
17
 
18
  def get_face_landmarks(self, image):
19
+ with mp.solutions.face_mesh.FaceMesh(
20
+ static_image_mode=True,
21
+ max_num_faces=1,
22
+ refine_landmarks=True,
23
+ min_detection_confidence=0.5
24
+ ) as face_mesh:
25
+ results = face_mesh.process(cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB))
26
  if not results.multi_face_landmarks:
27
  return None
 
28
  landmarks = results.multi_face_landmarks[0].landmark
29
  w, h = image.size
30
  face_landmarks = [(int(p.x * w), int(p.y * h)) for p in landmarks]
 
31
  return face_landmarks
32
 
33
  def load_images(self, image_a, image_b):