-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.py
92 lines (69 loc) · 2.16 KB
/
app.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
from flask import Flask, render_template, Response, jsonify, request
from camera import VideoCamera
from scoring import get_score
app = Flask(__name__)
video_camera = None
global_frame = None
category = 'Hammer Strike'
@app.route('/record_status', methods=['POST'])
def record_status():
global video_camera
if video_camera == None:
video_camera = VideoCamera()
json = request.get_json()
status = json['status']
if status == "true":
video_camera.start_record()
return jsonify(result="started")
else:
video_camera.stop_record()
return jsonify(result="stopped")
def video_stream():
global video_camera
global global_frame
if video_camera == None:
video_camera = VideoCamera()
while True:
frame = video_camera.get_frame()
if frame != None:
global_frame = frame
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
else:
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + global_frame + b'\r\n\r\n')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/elements')
def elements():
return render_template('elements.html')
@app.route('/generic')
def generic():
return render_template('generic.html')
@app.route('/k')
def leaderboard():
return render_template('k.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/quiz')
def quiz():
return render_template('quiz.html')
@app.route('/video_viewer')
def video_viewer():
return Response(video_stream(),
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/pose', methods=['GET', 'POST'])
def pose():
global category
"""Video streaming"""
category = request.form.get('detect')
return render_template('pose.html')
@app.route('/update', methods=['GET', 'POST'])
def update_score():
return render_template('score.html', score=get_score(category))
if __name__ == '__main__':
app.run(debug=True, threaded=True)