Showing
1 changed file
with
29 additions
and
4 deletions
... | @@ -23,6 +23,7 @@ class DetectFace: | ... | @@ -23,6 +23,7 @@ class DetectFace: |
23 | # detect faces in the grayscale image | 23 | # detect faces in the grayscale image |
24 | self.rects = self.detector(self.gray, 1) | 24 | self.rects = self.detector(self.gray, 1) |
25 | 25 | ||
26 | + # init face parts | ||
26 | self.mouth = [] | 27 | self.mouth = [] |
27 | self.right_eyebrow = [] | 28 | self.right_eyebrow = [] |
28 | self. left_eyebrow = [] | 29 | self. left_eyebrow = [] |
... | @@ -31,7 +32,7 @@ class DetectFace: | ... | @@ -31,7 +32,7 @@ class DetectFace: |
31 | self.nose = [] | 32 | self.nose = [] |
32 | self.jaw = [] | 33 | self.jaw = [] |
33 | 34 | ||
34 | - # detect the face parts and save the value | 35 | + # detect the face parts and set the variables |
35 | self.detect_face_part() | 36 | self.detect_face_part() |
36 | 37 | ||
37 | 38 | ||
... | @@ -80,12 +81,36 @@ class DetectFace: | ... | @@ -80,12 +81,36 @@ class DetectFace: |
80 | cv2.imshow("Image", output) | 81 | cv2.imshow("Image", output) |
81 | cv2.waitKey(0) | 82 | cv2.waitKey(0) |
82 | 83 | ||
84 | + | ||
83 | # set the variables | 85 | # set the variables |
84 | - # Caution: this coordinates fits on the resized image. | 86 | + # Caution: this coordinates fits on the RESIZED image. |
85 | self.mouth = face_parts[0] | 87 | self.mouth = face_parts[0] |
86 | self.right_eyebrow = face_parts[1] | 88 | self.right_eyebrow = face_parts[1] |
87 | - self. left_eyebrow = face_parts[2] | 89 | + self.left_eyebrow = face_parts[2] |
88 | self.right_eye = face_parts[3] | 90 | self.right_eye = face_parts[3] |
89 | - self. left_eye = face_parts[4] | 91 | + self.left_eye = face_parts[4] |
90 | self.nose = face_parts[5] | 92 | self.nose = face_parts[5] |
91 | self.jaw = face_parts[6] | 93 | self.jaw = face_parts[6] |
94 | + | ||
95 | + # parameter example : self.right_eye | ||
96 | + def extract_face_part(self, part): | ||
97 | + pts = part | ||
98 | + | ||
99 | + # Create an mask | ||
100 | + mask = np.zeros((self.img.shape[0], self.img.shape[1])) | ||
101 | + cv2.fillConvexPoly(mask, pts, 1) | ||
102 | + mask = mask.astype(np.bool) | ||
103 | + | ||
104 | + # extract right eye by applying polygon mask | ||
105 | + out = np.zeros_like(self.img) | ||
106 | + out[mask] = self.img[mask] | ||
107 | + #cv2.imshow("Image2", out) | ||
108 | + #cv2.waitKey(0) | ||
109 | + | ||
110 | + # crop the image | ||
111 | + (x, y, w, h) = cv2.boundingRect(pts) | ||
112 | + extracted_part = out[y:y + h, x:x + w] | ||
113 | + #cv2.imshow("Image2", extracted_part) | ||
114 | + #cv2.waitKey(0) | ||
115 | + | ||
116 | + return extracted_part | ... | ... |
-
Please register or login to post a comment