-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.py
63 lines (53 loc) · 1.69 KB
/
webapp.py
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
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, render_template, Response
from flask_socketio import SocketIO
import time
import datetime
import threading
import random
from BlessRNG import RNG, RNGS
import system
import cv2
app = Flask('SecurityApp')
socketio = SocketIO(app)
clientthread = threading.Thread()
core = system.FullSystem()
numrngs = core.cameraNum
def imgtobytes(img):
return cv2.imencode('.jpg',img)[1].tobytes()
@app.route('/')
def home():
return render_template('test.html')
@app.route('/face/<camID>/<faceID>')
def face(camID, faceID):
global core
faceimg = core.cameras[int(camID)].faces[int(faceID)]
return Response((b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + imgtobytes(faceimg) + b'\r\n\r\n'),
mimetype='multipart/x-mixed-replace; boundary=frame')
def continuoussend():
global core
while True:
datas = []
# for i, gen in enumerate(rng.gens):
# number = gen.number
# data = {'id':i,'number':number}
# datas.append(data)
datas = core.get_faces()
socketio.emit('new numbers',datas,namespace='/time')
print("Send time")
time.sleep(4)
@socketio.on('connect',namespace='/time')
def connect():
global clientthread
print("A CLIENT CONNECTED")
if not clientthread.is_alive():
clientthread = threading.Thread(target=continuoussend)
clientthread.daemon = True
clientthread.start()
data = {'numrng':numrngs}
socketio.emit('info',data,namespace='/time')
@socketio.on('disconnect',namespace='/time')
def disconnect():
print("A Client has disconnected..")
if __name__ == "__main__":
socketio.run(app,port=6969)