-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlive_face_detection.py
More file actions
51 lines (37 loc) · 1.12 KB
/
live_face_detection.py
File metadata and controls
51 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from socketIO_client import SocketIO, LoggingNamespace
import cv2
import hashlib
import base64
import time
token = "paste_your_api_key"
g_url = 'http://api.giscle.ml'
frame = 0
def extract_data(args):
print(args)
font = cv2.FONT_HERSHEY_SIMPLEX
for key in args['Output'][2].keys():
x,y,h,w = args['Output'][2][str(key)]['rect_coordinate']
cv2.rectangle(frame, (x,y),(x+h,y+w), (255,255,255))
cv2.imshow("frame",frame)
socketio = SocketIO(g_url, 80, LoggingNamespace)
socketio.emit('authenticate', {'token': token})
cam = cv2.VideoCapture(0)
frame_count = 1
while True:
global t
ret, frame = cam.read()
if not ret:
continue
frame = cv2.resize(frame, (900, 600))
encoded, buffer = cv2.imencode('.jpg', frame)
encoded_frame = base64.b64encode(buffer)
encoded_frame = encoded_frame.decode('utf-8')
t = time.time()
socketio.emit('faged', {'data': encoded_frame,'store':0})
socketio.on('response', extract_data)
socketio.wait(0.1)
print(time.time() - t)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
socketio.disconnect()
cam.release()