Answer the question
In order to leave comments, you need to log in
Flask video streaming?
There is a task: we will receive a photo with a post request, then place it on a web page with MIME: x-mixed-replace (streaming technology via http).
Previously, the photo was taken from the webcam in the get_frame function directly and everything worked.
Now - a white box in the place where the video should be.
from flask import Flask, render_template, Response, request
import cv2
app = Flask(__name__)
img = b''
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get_frame', methods=['GET', 'POST'])
def get():
img = request.data
return "OK"
def get_frame():
while True:
stringData=img
yield (b'--frame\r\n'
b'Content-Type: text/plain\r\n\r\n'+stringData+b'\r\n')
@app.route('/calc')
def calc():
return Response(get_frame(),mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=6789)
Answer the question
In order to leave comments, you need to log in
the img variable cannot be used in different functions, due to flask. I entered the image in memcashed and everything worked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question