Showing
1 changed file
with
15 additions
and
25 deletions
... | @@ -24,29 +24,24 @@ print('Running on device: {}'.format(device)) | ... | @@ -24,29 +24,24 @@ print('Running on device: {}'.format(device)) |
24 | 24 | ||
25 | mtcnn = MTCNN(keep_all=True, device=device) | 25 | mtcnn = MTCNN(keep_all=True, device=device) |
26 | 26 | ||
27 | -uri = 'ws://169.56.95.131:8765' | 27 | +uri = 'ws://localhost:8765' |
28 | 28 | ||
29 | -async def send_face(face_list): | 29 | +async def send_face(face_list, image_list): |
30 | global uri | 30 | global uri |
31 | async with websockets.connect(uri) as websocket: | 31 | async with websockets.connect(uri) as websocket: |
32 | - for face in face_list: | 32 | + for face, image in zip(face_list, image_list): |
33 | #type: np.float32 | 33 | #type: np.float32 |
34 | - print(face.shape) | 34 | + send = json.dumps({"action": "verify", "MTCNN": face.tolist()}) |
35 | - data = json.dumps({"action": "verify", "MTCNN": face.tolist()}) | 35 | + await websocket.send(send) |
36 | - await websocket.send(data) | 36 | + recv = await websocket.recv() |
37 | - print('send: verify', len(face_list), 'face(s)') | 37 | + data = json.loads(recv) |
38 | - code = await websocket.recv() | 38 | + if data['status'] == 'success': |
39 | - print('code:', code) | 39 | + # 성공 |
40 | - | 40 | + print(data['student_id'], 'is attend') |
41 | -async def send_image(image_list): | 41 | + else: |
42 | - global uri | 42 | + print('verification failed') |
43 | - async with websockets.connect(uri) as websocket: | 43 | + send = json.dumps({'action': 'save_image', 'image': image.tolist()}) |
44 | - for image in image_list: | 44 | + await websocket.send(send) |
45 | - data = json.dumps({"action": "save_image", "image": image.tolist(), "shape": image.shape}) | ||
46 | - await websocket.send(data) | ||
47 | - print('send', len(image_list), 'image(s)') | ||
48 | - code = await websocket.recv() | ||
49 | - print('code:', code) | ||
50 | 45 | ||
51 | def detect_face(frame): | 46 | def detect_face(frame): |
52 | # If required, create a face detection pipeline using MTCNN: | 47 | # If required, create a face detection pipeline using MTCNN: |
... | @@ -89,12 +84,7 @@ while True: | ... | @@ -89,12 +84,7 @@ while True: |
89 | image_list = detect_face(frame) | 84 | image_list = detect_face(frame) |
90 | ##embedding server로 전송## | 85 | ##embedding server로 전송## |
91 | if face_list: | 86 | if face_list: |
92 | - asyncio.get_event_loop().run_until_complete(send_face(face_list)) | 87 | + asyncio.get_event_loop().run_until_complete(send_face(face_list, image_list)) |
93 | - ################### | ||
94 | - ##image server로 전송## | ||
95 | - if image_list: | ||
96 | - asyncio.get_event_loop().run_until_complete(send_image(image_list)) | ||
97 | - ################### | ||
98 | #end = timeit.default_timer() | 88 | #end = timeit.default_timer() |
99 | #print('delta time: ', end - start) | 89 | #print('delta time: ', end - start) |
100 | except Exception as ex: | 90 | except Exception as ex: | ... | ... |
-
Please register or login to post a comment