-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoperations.py
50 lines (35 loc) · 1.21 KB
/
operations.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
49
"""
:/helper class
"""
import numpy as np
import cv2
def resize(images, size=(100, 100)):
images_norm = []
for image in images:
is_color = len(image.shape) == 3
if is_color:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# using different OpenCV method if enlarging or shrinking
if image.shape < size:
image_norm = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
else:
image_norm = cv2.resize(image, size, interpolation=cv2.INTER_CUBIC)
images_norm.append(image_norm)
return images_norm
def normalize_intensity(images):
images_norm = []
for image in images:
is_color = len(image.shape) == 3
if is_color:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
images_norm.append(cv2.equalizeHist(image))
return images_norm
def cut_face_rectangle(image, face_coord):
images_rectangle = []
for (x, y, w, h) in face_coord:
images_rectangle.append(image[y: y + h, x: x + w])
return images_rectangle
def draw_face_rectangle(image, faces_coord):
for (x, y, w, h) in faces_coord:
cv2.rectangle(image, (x, y), (x + w, y + h), (206, 0, 209), 2)
return image