Showing
1 changed file
with
23 additions
and
18 deletions
1 | ################################################## | 1 | ################################################## |
2 | -#1. webcam에서 얼굴을 인식합니다. # | 2 | +#1. webcam에서 얼굴을 인식합니다 |
3 | -#2. 얼굴일 확률이 95% 이상인 이미지를 이미지 서버로 전송합니다. # | 3 | +#2. 인식한 얼굴을 등록합니다 |
4 | -#3. 전처리 된 데이터를 verification 서버에 전송합니다. # | ||
5 | ################################################## | 4 | ################################################## |
6 | import torch | 5 | import torch |
7 | import numpy as np | 6 | import numpy as np |
... | @@ -55,27 +54,33 @@ def detect_face(frame): | ... | @@ -55,27 +54,33 @@ def detect_face(frame): |
55 | image_list.append(image) | 54 | image_list.append(image) |
56 | return image_list | 55 | return image_list |
57 | 56 | ||
58 | -def make_face_list(frame): | 57 | +def detect_face(frame): |
59 | - global mtcnn | 58 | + results = mtcnn.detect(frame) |
60 | - results, prob = mtcnn(frame, return_prob = True) | 59 | + faces = mtcnn(frame, return_prob = False) |
60 | + image_list = [] | ||
61 | face_list = [] | 61 | face_list = [] |
62 | - if prob[0] == None: | 62 | + if results[1][0] == None: |
63 | - return [] | 63 | + return [], [] |
64 | - for result, prob in zip(results, prob): | 64 | + for box, face, prob in zip(results[0], faces, results[1]): |
65 | - if prob < 0.95: | 65 | + if prob < 0.97: |
66 | continue | 66 | continue |
67 | - #np.float32 | 67 | + print('face detected. prob:', prob) |
68 | - face_list.append(result.numpy()) | 68 | + x1, y1, x2, y2 = box |
69 | - return face_list | 69 | + if (x2-x1) * (y2-y1) < 15000: |
70 | + # 얼굴 해상도가 너무 낮으면 무시 | ||
71 | + continue | ||
72 | + # 얼굴 주변 ±3 영역 저장 | ||
73 | + image = frame[int(y1-3):int(y2+3), int(x1-3):int(x2+3)] | ||
74 | + image_list.append(image) | ||
75 | + # MTCNN 데이터 저장 | ||
76 | + face_list.append(face.numpy()) | ||
77 | + return image_list, face_list | ||
70 | 78 | ||
71 | -cap = cv2.VideoCapture(0) | 79 | +cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) |
72 | cap.set(3, 720) | 80 | cap.set(3, 720) |
73 | cap.set(4, 480) | 81 | cap.set(4, 480) |
74 | ret, frame = cap.read() | 82 | ret, frame = cap.read() |
75 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | 83 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
76 | -#img = Image.open('3.jpg') | 84 | +face_list, image_list = detect_face(frame) |
77 | -#frame = np.array(img) | ||
78 | -face_list = make_face_list(frame) | ||
79 | -image_list = detect_face(frame) | ||
80 | if face_list: | 85 | if face_list: |
81 | asyncio.get_event_loop().run_until_complete(send_face(face_list, image_list)) | 86 | asyncio.get_event_loop().run_until_complete(send_face(face_list, image_list)) |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment