update crop face
Showing
22 changed files
with
17 additions
and
6 deletions
No preview for this file type
No preview for this file type
... | @@ -203,7 +203,8 @@ class Face_Detector(object): | ... | @@ -203,7 +203,8 @@ class Face_Detector(object): |
203 | (resize_b[13], resize_b[14])]) | 203 | (resize_b[13], resize_b[14])]) |
204 | 204 | ||
205 | # import time | 205 | # import time |
206 | # cv2.imwrite('results/0.jpg', frame) | 206 | # image_name = str(time.time()) + '.jpg' |
207 | # cv2.imwrite('results/{}'.format(image_name), frame) | ||
207 | return face_bboxes, face_landmarks, max_index | 208 | return face_bboxes, face_landmarks, max_index |
208 | 209 | ||
209 | 210 | ... | ... |
... | @@ -17,7 +17,7 @@ class Face_Recognizer(object): | ... | @@ -17,7 +17,7 @@ class Face_Recognizer(object): |
17 | for i in range(len(imgs)): | 17 | for i in range(len(imgs)): |
18 | img = imgs[i] | 18 | img = imgs[i] |
19 | 19 | ||
20 | # img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | 20 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
21 | img = img.astype(np.float) | 21 | img = img.astype(np.float) |
22 | img = (img / 255. - 0.5) / 0.5 | 22 | img = (img / 255. - 0.5) / 0.5 |
23 | img = img.transpose(2, 0, 1) | 23 | img = img.transpose(2, 0, 1) | ... | ... |
... | @@ -24,10 +24,16 @@ def preprocess(image, landmarks): | ... | @@ -24,10 +24,16 @@ def preprocess(image, landmarks): |
24 | warped = cv2.warpAffine(image, M, (112, 112), borderValue=0.0) | 24 | warped = cv2.warpAffine(image, M, (112, 112), borderValue=0.0) |
25 | return warped | 25 | return warped |
26 | 26 | ||
27 | def get_face(image, bbox): | ||
28 | print(bbox) | ||
29 | face_area = image[bbox[1]:bbox[3], bbox[0]:bbox[2], ] | ||
30 | norm_image = cv2.cvtColor(face_area, cv2.COLOR_BGR2RGB).astype(np.float32) | ||
31 | norm_image = cv2.resize(norm_image, (112, 112)) | ||
32 | return norm_image | ||
27 | 33 | ||
28 | def get_norm_face(image, landmarks): | 34 | def get_norm_face(image, landmarks): |
29 | norm_image = preprocess(image, landmarks) | 35 | norm_image = preprocess(image, landmarks) |
30 | norm_image = cv2.cvtColor(norm_image, cv2.COLOR_BGR2RGB).astype(np.float32) | 36 | # norm_image = cv2.cvtColor(norm_image, cv2.COLOR_BGR2RGB).astype(np.float32) |
31 | norm_image = cv2.resize(norm_image, (112, 112)) | 37 | norm_image = cv2.resize(norm_image, (112, 112)) |
32 | # norm_image = norm_image.transpose((2, 0, 1)) | 38 | # norm_image = norm_image.transpose((2, 0, 1)) |
33 | # norm_image = norm_image.transpose((1,2,0)) | 39 | # norm_image = norm_image.transpose((1,2,0)) |
... | @@ -47,7 +53,7 @@ if __name__ == '__main__': | ... | @@ -47,7 +53,7 @@ if __name__ == '__main__': |
47 | 53 | ||
48 | face_detector = Face_Detector(det_face_model_path) | 54 | face_detector = Face_Detector(det_face_model_path) |
49 | face_recognizer = Face_Recognizer(reg_face_id_model_path) | 55 | face_recognizer = Face_Recognizer(reg_face_id_model_path) |
50 | for i in range(10): | 56 | for i in range(1): |
51 | id_image = cv2.imread(id_image_path) | 57 | id_image = cv2.imread(id_image_path) |
52 | life_image = cv2.imread(life_image_path) | 58 | life_image = cv2.imread(life_image_path) |
53 | 59 | ||
... | @@ -55,13 +61,17 @@ if __name__ == '__main__': | ... | @@ -55,13 +61,17 @@ if __name__ == '__main__': |
55 | life_face_bboxes, life_face_landmarks, life_max_idx = face_detector.detect(life_image, face_det_thr) | 61 | life_face_bboxes, life_face_landmarks, life_max_idx = face_detector.detect(life_image, face_det_thr) |
56 | print(id_face_bboxes) | 62 | print(id_face_bboxes) |
57 | print(life_face_bboxes) | 63 | print(life_face_bboxes) |
64 | # id_norm_image = get_face(id_image, id_face_bboxes[id_max_idx]) | ||
58 | id_norm_image = get_norm_face(id_image, id_face_landmarks[id_max_idx]) | 65 | id_norm_image = get_norm_face(id_image, id_face_landmarks[id_max_idx]) |
59 | id_norm_image = np.transpose(id_norm_image, (2, 0, 1)) | 66 | cv2.imwrite('results/face1.jpg', id_norm_image) |
67 | # id_norm_image = np.transpose(id_norm_image, (2, 0, 1)) | ||
60 | norm_images = [id_norm_image] | 68 | norm_images = [id_norm_image] |
61 | 69 | ||
62 | for j in range(len(life_face_landmarks)): | 70 | for j in range(len(life_face_landmarks)): |
63 | life_norm_image = get_norm_face(life_image, life_face_landmarks[j]) | 71 | life_norm_image = get_norm_face(life_image, life_face_landmarks[j]) |
64 | life_norm_image = np.transpose(life_norm_image, (2, 0, 1)) | 72 | cv2.imwrite('results/face2.jpg', life_norm_image) |
73 | # life_norm_image = np.transpose(life_norm_image, (2, 0, 1)) | ||
74 | # life_norm_image = get_face(life_image, life_face_bboxes[j]) | ||
65 | norm_images.append(life_norm_image) | 75 | norm_images.append(life_norm_image) |
66 | 76 | ||
67 | embeddings = face_recognizer.recognize(norm_images) | 77 | embeddings = face_recognizer.recognize(norm_images) | ... | ... |
results/1638790432.2726755.jpg
0 → 100644

2.54 MB
results/1638790444.305009.jpg
0 → 100644

2.54 MB
results/1638790444.7681723.jpg
0 → 100644

173 KB
results/1638790791.235839.jpg
0 → 100644

2.54 MB
results/1638790791.6991258.jpg
0 → 100644

173 KB
results/1638790829.9781895.jpg
0 → 100644

2.54 MB
results/1638790830.441715.jpg
0 → 100644

173 KB
results/1638790862.8459556.jpg
0 → 100644

2.54 MB
results/1638790863.3102262.jpg
0 → 100644

173 KB
results/1638790896.028853.jpg
0 → 100644

2.54 MB
results/1638790896.49208.jpg
0 → 100644

173 KB
results/1638790925.8013053.jpg
0 → 100644

2.54 MB
results/1638790926.2648418.jpg
0 → 100644

27.8 KB
results/1638793618.6382208.jpg
0 → 100644

2.54 MB
results/1638793619.1024578.jpg
0 → 100644

27.8 KB
results/face1.jpg
0 → 100644

6.04 KB
results/face2.jpg
0 → 100644

5.77 KB
-
Please register or sign in to post a comment