starbucksdolcelatte

Created class var 'cheek' and set the area by the function 'detect_cheek()'

...@@ -6,6 +6,8 @@ import numpy as np ...@@ -6,6 +6,8 @@ import numpy as np
6 import imutils 6 import imutils
7 import dlib 7 import dlib
8 import cv2 8 import cv2
9 +import matplotlib.pyplot as plt
10 +
9 11
10 class DetectFace: 12 class DetectFace:
11 13
...@@ -31,9 +33,11 @@ class DetectFace: ...@@ -31,9 +33,11 @@ class DetectFace:
31 self. left_eye = [] 33 self. left_eye = []
32 self.nose = [] 34 self.nose = []
33 self.jaw = [] 35 self.jaw = []
36 + self.cheek = [[],[]] # index 0 : left, 1 : right
34 37
35 # detect the face parts and set the variables 38 # detect the face parts and set the variables
36 self.detect_face_part() 39 self.detect_face_part()
40 + self.cheek = self.detect_cheek()
37 41
38 42
39 def detect_face_part(self): 43 def detect_face_part(self):
...@@ -70,18 +74,17 @@ class DetectFace: ...@@ -70,18 +74,17 @@ class DetectFace:
70 (x, y, w, h) = cv2.boundingRect(np.array([shape[i:j]])) 74 (x, y, w, h) = cv2.boundingRect(np.array([shape[i:j]]))
71 roi = self.img[y:y + h, x:x + w] 75 roi = self.img[y:y + h, x:x + w]
72 roi = imutils.resize(roi, width=250, inter=cv2.INTER_CUBIC) 76 roi = imutils.resize(roi, width=250, inter=cv2.INTER_CUBIC)
73 - 77 + '''
74 # show the particular face part 78 # show the particular face part
75 cv2.imshow("ROI", roi) 79 cv2.imshow("ROI", roi)
76 cv2.imshow("Image", clone) 80 cv2.imshow("Image", clone)
77 cv2.waitKey(0) 81 cv2.waitKey(0)
78 - 82 + '''
79 # visualize all facial landmarks with a transparent overlay 83 # visualize all facial landmarks with a transparent overlay
80 output = face_utils.visualize_facial_landmarks(self.img, shape) 84 output = face_utils.visualize_facial_landmarks(self.img, shape)
81 cv2.imshow("Image", output) 85 cv2.imshow("Image", output)
82 cv2.waitKey(0) 86 cv2.waitKey(0)
83 87
84 -
85 # set the variables 88 # set the variables
86 # Caution: this coordinates fits on the RESIZED image. 89 # Caution: this coordinates fits on the RESIZED image.
87 self.mouth = face_parts[0] 90 self.mouth = face_parts[0]
...@@ -92,6 +95,8 @@ class DetectFace: ...@@ -92,6 +95,8 @@ class DetectFace:
92 self.nose = face_parts[5] 95 self.nose = face_parts[5]
93 self.jaw = face_parts[6] 96 self.jaw = face_parts[6]
94 97
98 +
99 +
95 # parameter example : self.right_eye 100 # parameter example : self.right_eye
96 def extract_face_part(self, part): 101 def extract_face_part(self, part):
97 pts = part 102 pts = part
...@@ -104,13 +109,34 @@ class DetectFace: ...@@ -104,13 +109,34 @@ class DetectFace:
104 # extract right eye by applying polygon mask 109 # extract right eye by applying polygon mask
105 out = np.zeros_like(self.img) 110 out = np.zeros_like(self.img)
106 out[mask] = self.img[mask] 111 out[mask] = self.img[mask]
107 - #cv2.imshow("Image2", out) 112 + '''
108 - #cv2.waitKey(0) 113 + cv2.imshow("Image2", out)
114 + cv2.waitKey(0)
115 + '''
109 116
110 # crop the image 117 # crop the image
111 (x, y, w, h) = cv2.boundingRect(pts) 118 (x, y, w, h) = cv2.boundingRect(pts)
112 extracted_part = out[y:y + h, x:x + w] 119 extracted_part = out[y:y + h, x:x + w]
113 - #cv2.imshow("Image2", extracted_part) 120 + '''
114 - #cv2.waitKey(0) 121 + cv2.imshow("Image2", extracted_part)
115 - 122 + cv2.waitKey(0)
123 + '''
116 return extracted_part 124 return extracted_part
125 +
126 +
127 + def detect_cheek(self):
128 + cheek = [[],[]]
129 +
130 + #rect is the face detected
131 + shape = self.predictor(self.gray, self.rects[0])
132 + shape = face_utils.shape_to_np(shape)
133 +
134 + left = self.img[shape[29][1]:shape[33][1],
135 + shape[4][0]:shape[48][0]] #left cheek
136 + right = self.img[shape[29][1]:shape[33][1],
137 + shape[54][0]:shape[12][0]] #right cheek
138 +
139 + cheek[0] = left
140 + cheek[1] = right
141 +
142 + return cheek
......