Graduate

Modify register.py

##################################################
#1. webcam에서 얼굴을 인식합니다. #
#2. 얼굴일 확률이 95% 이상인 이미지를 이미지 서버로 전송합니다. #
#3. 전처리 된 데이터를 verification 서버에 전송합니다. #
#1. webcam에서 얼굴을 인식합니다
#2. 인식한 얼굴을 등록합니다
##################################################
import torch
import numpy as np
......@@ -55,27 +54,33 @@ def detect_face(frame):
image_list.append(image)
return image_list
def make_face_list(frame):
global mtcnn
results, prob = mtcnn(frame, return_prob = True)
def detect_face(frame):
results = mtcnn.detect(frame)
faces = mtcnn(frame, return_prob = False)
image_list = []
face_list = []
if prob[0] == None:
return []
for result, prob in zip(results, prob):
if prob < 0.95:
if results[1][0] == None:
return [], []
for box, face, prob in zip(results[0], faces, results[1]):
if prob < 0.97:
continue
#np.float32
face_list.append(result.numpy())
return face_list
print('face detected. prob:', prob)
x1, y1, x2, y2 = box
if (x2-x1) * (y2-y1) < 15000:
# 얼굴 해상도가 너무 낮으면 무시
continue
# 얼굴 주변 ±3 영역 저장
image = frame[int(y1-3):int(y2+3), int(x1-3):int(x2+3)]
image_list.append(image)
# MTCNN 데이터 저장
face_list.append(face.numpy())
return image_list, face_list
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cap.set(3, 720)
cap.set(4, 480)
ret, frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#img = Image.open('3.jpg')
#frame = np.array(img)
face_list = make_face_list(frame)
image_list = detect_face(frame)
face_list, image_list = detect_face(frame)
if face_list:
asyncio.get_event_loop().run_until_complete(send_face(face_list, image_list))
\ No newline at end of file
......