-
Notifications
You must be signed in to change notification settings - Fork 27
/
lipTester.py
48 lines (38 loc) · 1.44 KB
/
lipTester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import face_recognition
from pathlib import Path
from scipy import misc
margin = 25
maxWidth = 0
maxHeight = 0
# frames with my hand in front of my mouth
# 3197 - 3224
for i in range(0,131663):
strIndex = str(i)
while len(strIndex) < 4:
strIndex = "0"+strIndex
image_file = Path("3/origImages/frame"+strIndex+".jpg").resolve()
image = face_recognition.load_image_file(str(image_file))
face_landmarks_list = face_recognition.face_landmarks(image)
if(len(face_landmarks_list) >= 1):
xMin = 999999
xMax = -999999
yMin = 999999
yMax = -999999
points = face_landmarks_list[0]['bottom_lip']+face_landmarks_list[0]['top_lip']
for point in points:
if point[0] < xMin:
xMin = point[0]
if point[0] > xMax:
xMax = point[0]
if point[1] < yMin:
yMin = point[1]
if point[1] > yMax:
yMax = point[1]
if(yMax-yMin > maxHeight):
maxHeight = yMax-yMin
if(xMax-xMin > maxWidth):
maxWidth = xMax-xMin
arr = misc.imread("3/origImages/frame"+strIndex+".jpg")
Path("3/mouthImages").mkdir(exist_ok=True)
misc.imsave("3/mouthImages/frame"+strIndex+".jpg",arr[yMin-margin:yMax+margin,xMin-margin:xMax+margin])
print("FINISHED IMAGE #"+str(i)+". Also, the maximum dimensions are "+str(maxWidth)+" x "+str(maxHeight))