-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
38 lines (30 loc) · 1.17 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
from flask import Flask, render_template, Response, request, redirect, url_for
from flask_socketio import SocketIO
from camera import VideoCamera
import cv2
app = Flask(__name__)
socketio = SocketIO(app)
@app.route('/', methods=['GET', 'POST'])
def hello():
if request.method == 'POST':
curls = request.form['curlCount']
return redirect(url_for('base', curls=curls))
return render_template('index.html')
def gen(camera, total_curls):
while True:
jpeg, remaining_curls = camera.get_frame(total_curls)
if cv2.waitKey(1) & 0xFF == 27:
break
socketio.emit('update', {'remaining_curls': remaining_curls})
yield (b'--frame\r\n'
b'Content-type: image/jpeg\r\n\r\n' + jpeg
+ b'\r\n\r\n')
@app.route('/base')
def base():
curls = request.args.get('curls', '')
return render_template('index3.html', curls=curls, remaining_curls='remaining_curls')
@app.route('/video_feed/<int:total_curls>')
def video_feed(total_curls):
return Response(gen(VideoCamera(), total_curls), mimetype='multipart/x-mixed-replace;boundary=frame')
if __name__ == '__main__':
socketio.run(app, debug=True)