temp5.py
2.21 KB
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
65
import cv2
from detect_face import DetectFace
from dominant_colors import DominantColors
from tone_analysis import ToneAnalysis
import imutils
from colormath.color_objects import LabColor, sRGBColor, HSVColor
from colormath.color_conversions import convert_color
predictor = 'shape_predictor_68_face_landmarks.dat'
seasons = ['spring', 'summer', 'fall', 'winter']
a = [30, 20, 5] # 가중치
tone_analysis = ToneAnalysis()
for j in range(4): # j = season
path = "res/tc2/" + seasons[j] + "/"
for i in range(6):
img = path + str(i+1) + '.jpg'
print("")
print(img)
df = DetectFace(predictor, img)
# Try: Extract left eye part
l_eye = df.extract_face_part(df.left_eye)
# Try: Extract left eyebrow part
l_eyebrow = df.extract_face_part(df.left_eyebrow)
# Try : Extract cheek part
l_cheek = df.cheek_img[0]
# Create an DominantColors instance on left cheek image
clusters = 5
lc_dc = DominantColors(l_cheek, clusters)
lc_dc.dominantColors()
lc_colors = lc_dc.plotHistogram()
leb_dc = DominantColors(l_eyebrow, clusters)
leb_dc.dominantColors()
leb_colors = leb_dc.plotHistogram()
le_dc = DominantColors(l_eye, clusters)
le_dc.dominantColors()
le_colors = le_dc.plotHistogram()
cy_rgb = [lc_colors[0], leb_colors[0], le_colors[0]]
lab_b = [] #skin, eyebr, eye
hsv_s = [] #skin, eyebr, eye
for color in cy_rgb:
rgb = sRGBColor(color[0], color[1], color[2], is_upscaled=True)
lab = convert_color(rgb, LabColor, through_rgb_type=sRGBColor)
lab_b.append(float(format(lab.lab_b,".2f")))
hsv = convert_color(rgb, HSVColor, through_rgb_type=sRGBColor)
hsv_s.append(float(format(hsv.hsv_s*100,".2f")))
print("lab_b ", lab_b)
print("hsv_s ", hsv_s)
if(tone_analysis.is_warm(lab_b, a)):
if(tone_analysis.is_spr(hsv_s, a)):
print("봄웜톤")
else:
print("가을웜톤")
else:
if(tone_analysis.is_smr(hsv_s, a)):
print("여름쿨톤")
else:
print("겨울쿨톤")