These are my routes and some functions:
from flask import Flask, render_template, Response
import cv2
import time
from sys import stdout
from flask_socketio import SocketIO
import math
import numpy as np
import logging
import os
from camera import VideoCamera
app = Flask(__name__)
app.logger.addHandler(logging.StreamHandler(stdout))
app.config['SECRET_KEY'] = 'b13ce0c6768bb0b280bab13ceb13ce0cde280ba0c676dfde280ba245676dfde280ba0c676dfde280ba245'
app.config['DEBUG'] = True
socketio = SocketIO(app)
@socketio.on('connect', namespace='/test')
def test_connect():
app.logger.info("client connected")
@app.route('/', methods = ['GET','POST'])
def index():
"""Video streaming home page."""
return render_template('index.html')
def gen(camera):
while True:
data= camera.get_frame()
frame=data[0]
yield (b'--frame
'
b'Content-Type: image/jpeg
' + frame + b'
')
@app.route('/video_feed')
def video_feed():
return Response(gen(VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/golden_ratio_calculating', methods = ['GET','POST'])
def calculate():
ratio = main()
return render_template('golden_calc_page.html' , ratio123 = ratio)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
socketio.run(app, port = port)
See Question&Answers more detail:os