-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (54 loc) · 1.73 KB
/
main.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
# main.py
# import the necessary packages
from flask import Flask, render_template, Response, request, redirect, url_for, jsonify
from WebCamera import VideoCamera
from flask_socketio import SocketIO
import logging
from sys import stdout
from camera import VideoCamera
app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(stdout))
app.config['DEBUG'] = True
socketio = SocketIO(app)
Cam = VideoCamera()
@socketio.on('input image', namespace='/test')
def test_message(input):
input = input.split(",")[1]
Cam.enqueue_input(input)
#camera.enqueue_input(base64_to_pil_image(input))
@socketio.on('connect', namespace='/test')
def test_connect():
app.logger.info("client connected")
@app.route('/run')
def run_demo():
return render_template('run.html')
@app.route('/')
def index():
# rendering webpage
return render_template('index.html')
def gen(Camera):
while True:
# get camera frame
frame = Camera.get_frame()[0]
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
@app.route('/video_feed')
def video_feed():
frame = gen(Cam)
return Response(frame,
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/video', methods=["GET", "POST"])
def video():
r = None
if request.method == "POST":
req = request.form
r = str(req['video_url'])
if r == None:
return redirect('index.html')
#format received: https://www.youtube.com/watch?v=iSMbRGTBOHU
print("url recieved: " + str(r))
return render_template('video.html', url=r[32:])
if __name__ == '__main__':
# defining server ip address and port
#app.run(host='0.0.0.0', port='5000', debug=True)
socketio.run(app)