-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (42 loc) · 1.74 KB
/
main.py
File metadata and controls
54 lines (42 loc) · 1.74 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
52
53
from flask import Flask, render_template, Response, jsonify
from multiprocessing import Process, Queue
import FaceRecog
if __name__ == '__main__':
app = Flask(__name__)
qFrame = Queue()
qStatus = Queue()
qPlayer = Queue()
@app.route('/')
def index():
return render_template('index.html')
@app.route('/video_feed')
def video_feed():
# Run FaceRecog multiprocessor
process = Process(target=FaceRecog.main, args=(
qFrame, qStatus, qPlayer))
process.start()
def gen():
while True:
yield qFrame.get()
# Get frame or player info from FaceRecog module
# getFrameOrInfo function will keep yielding jpeg frame until all player information is found
return Response(gen(),
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/audio_feed')
def audio_feed():
# Server Send Event for sending current status to frontend
# status will then be converted to speech afterwards
def gen():
while True:
yield 'data: {}\n\n'.format(qStatus.get())
return Response(gen(), mimetype='text/event-stream')
@app.route('/player_info')
def player_info():
# FaceRecog.getFrameOrInfo() will return values after all players' faces found for 2 seconds
# player_info = {'Player 1': [location(cm), angle(degree)], 'Player 2': ...}
# format: DICTIONARY = {STRING: [float, float]}
def gen():
while True:
yield 'data: {}\n\n'.format(qPlayer.get())
return Response(gen(), mimetype='text/event-stream')
app.run(host='0.0.0.0', debug=True, threaded=True)