-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathface_normalisation.py
More file actions
38 lines (28 loc) · 980 Bytes
/
face_normalisation.py
File metadata and controls
38 lines (28 loc) · 980 Bytes
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
import cv2
def cut_face(image, face_coord):
faces = []
for (x, y, w, h) in face_coord:
per = int(0.2 * w / 2)
faces.append(image[y: y+h, x+per: x+w-per])
return faces
def normalise_intensity(images):
norm_image = []
for image in images:
if len(image) == 3:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
norm_image.append(cv2.equalizeHist(image))
return norm_image
def resize(images, size=(280, 280)):
norm_image = []
for image in images:
if image.shape < size:
image = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
else:
image = cv2.resize(image, size, interpolation=cv2.INTER_CUBIC)
norm_image.append(image)
return norm_image
def get_normalised_faces(frame, face_coord):
faces = cut_face(frame, face_coord)
faces = normalise_intensity(faces)
faces = resize(faces)
return faces