wissemkarous commited on
Commit
6cffbb3
β€’
1 Parent(s): 1c32def
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ shape_predictor_68_face_landmarks_GTX.dat filter=lfs diff=lfs merge=lfs -text
extract_lip_coordinates.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import dlib
3
+ import glob
4
+ import numpy as np
5
+ import torch
6
+ import streamlit as st
7
+
8
+ detector = dlib.get_frontal_face_detector()
9
+ predictor = dlib.shape_predictor("scripts/shape_predictor_68_face_landmarks_GTX.dat")
10
+
11
+
12
+ def extract_lip_coordinates(detector, predictor, img_path):
13
+ image = cv2.imread(img_path)
14
+ image = cv2.resize(image, (600, 500))
15
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
16
+
17
+ rects = detector(gray)
18
+ retries = 3
19
+ while retries > 0:
20
+ try:
21
+ assert len(rects) == 1
22
+ break
23
+ except AssertionError as e:
24
+ retries -= 1
25
+
26
+ for rect in rects:
27
+ # apply the shape predictor to the face ROI
28
+ shape = predictor(gray, rect)
29
+ x = []
30
+ y = []
31
+ for n in range(48, 68):
32
+ x.append(shape.part(n).x)
33
+ y.append(shape.part(n).y)
34
+ return [x, y]
35
+
36
+
37
+ @st.cache_data(show_spinner=False, persist=True)
38
+ def generate_lip_coordinates(frame_images_directory):
39
+ frames = glob.glob(frame_images_directory + "/*.jpg")
40
+ frames.sort()
41
+
42
+ img = cv2.imread(frames[0])
43
+ height, width, layers = img.shape
44
+
45
+ coords = []
46
+ for frame in frames:
47
+ x_coords, y_coords = extract_lip_coordinates(detector, predictor, frame)
48
+ normalized_coords = []
49
+ for x, y in zip(x_coords, y_coords):
50
+ normalized_x = x / width
51
+ normalized_y = y / height
52
+ normalized_coords.append((normalized_x, normalized_y))
53
+ coords.append(normalized_coords)
54
+ coords_array = np.array(coords, dtype=np.float32)
55
+ coords_array = torch.from_numpy(coords_array)
56
+ return coords_array
shape_predictor_68_face_landmarks_GTX.dat ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:249a69a1d5f2d7c714a92934d35367d46eb52dc308d46717e82d49e8386b3b80
3
+ size 66435981