정희원

Upload new file

1 +import cv2
2 +import dlib
3 +import numpy as np
4 +
5 +IMG_SIZE = (34, 26)
6 +
7 +def crop_eye(img, eye_points):
8 + x1, y1 = np.amin(eye_points, axis=0)
9 + x2, y2 = np.amax(eye_points, axis=0)
10 + cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
11 +
12 + w = (x2 - x1) * 1.2
13 + h = w * IMG_SIZE[1] / IMG_SIZE[0]
14 +
15 + margin_x, margin_y = w / 2, h / 2
16 +
17 + min_x, min_y = int(cx - margin_x), int(cy - margin_y)
18 + max_x, max_y = int(cx + margin_x), int(cy + margin_y)
19 +
20 + eye_rect = np.rint([min_x, min_y, max_x, max_y]).astype(np.int)
21 +
22 + gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
23 +
24 +
25 +
26 +
27 + eye_img = gray[eye_rect[1]:eye_rect[3], eye_rect[0]:eye_rect[2]]
28 +
29 +
30 +
31 +
32 + return eye_img, eye_rect
33 +