-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_conversion_left.py
65 lines (43 loc) · 1.63 KB
/
image_conversion_left.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# coding: utf-8
# In[1]:
# img - 이미지 파일
def image_conversion_left(img):
import dlib
import cv2
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('../shape_predictor_68_face_landmarks.dat')
src_img =img
img_bgr = cv2.imread(src_img)
img_show = img_bgr.copy()
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
# range는 끝값이 포함안됨
ALL = list(range(0, 68))
RIGHT_EYEBROW = list(range(17, 22))
LEFT_EYEBROW = list(range(22, 27))
RIGHT_EYE = list(range(36, 42))
LEFT_EYE = list(range(42, 48))
NOSE = list(range(27, 36))
MOUTH_OUTLINE = list(range(48, 61))
MOUTH_INNER = list(range(61, 68))
JAWLINE = list(range(0, 17))
index = ALL
#ret, img_frame = src_img.read()
dets = detector(img_rgb, 1)
for face in dets:
shape = predictor(img_rgb, face) #얼굴에서 68개 점 찾기
list_points = []
#list_hsv = []
for p in shape.parts():
list_points.append([p.x, p.y])
list_points = np.array(list_points)
img_all_left = img_rgb[min(list_points[17:27,[1]])[0]:list_points[8][1],list_points[0][0]:list_points[8][0],:]
# 왼쪽 기준으로 대칭 만들어주는 부분
left_symmetry = img_all_left[:,::-1]
img_left_symmetry =np.concatenate((img_all_left,left_symmetry), axis=1)
# 왼쪽 기준으로 변환된 이미지 저장
im = Image.fromarray(img_left_symmetry)
im.save("image_left.jpg")