Graduate

Modify client.py

......@@ -24,29 +24,24 @@ print('Running on device: {}'.format(device))
mtcnn = MTCNN(keep_all=True, device=device)
uri = 'ws://169.56.95.131:8765'
uri = 'ws://localhost:8765'
async def send_face(face_list):
async def send_face(face_list, image_list):
global uri
async with websockets.connect(uri) as websocket:
for face in face_list:
for face, image in zip(face_list, image_list):
#type: np.float32
print(face.shape)
data = json.dumps({"action": "verify", "MTCNN": face.tolist()})
await websocket.send(data)
print('send: verify', len(face_list), 'face(s)')
code = await websocket.recv()
print('code:', code)
async def send_image(image_list):
global uri
async with websockets.connect(uri) as websocket:
for image in image_list:
data = json.dumps({"action": "save_image", "image": image.tolist(), "shape": image.shape})
await websocket.send(data)
print('send', len(image_list), 'image(s)')
code = await websocket.recv()
print('code:', code)
send = json.dumps({"action": "verify", "MTCNN": face.tolist()})
await websocket.send(send)
recv = await websocket.recv()
data = json.loads(recv)
if data['status'] == 'success':
# 성공
print(data['student_id'], 'is attend')
else:
print('verification failed')
send = json.dumps({'action': 'save_image', 'image': image.tolist()})
await websocket.send(send)
def detect_face(frame):
# If required, create a face detection pipeline using MTCNN:
......@@ -89,12 +84,7 @@ while True:
image_list = detect_face(frame)
##embedding server로 전송##
if face_list:
asyncio.get_event_loop().run_until_complete(send_face(face_list))
###################
##image server로 전송##
if image_list:
asyncio.get_event_loop().run_until_complete(send_image(image_list))
###################
asyncio.get_event_loop().run_until_complete(send_face(face_list, image_list))
#end = timeit.default_timer()
#print('delta time: ', end - start)
except Exception as ex:
......