D
D
Dnomin2018-11-26 18:53:22
Python
Dnomin, 2018-11-26 18:53:22

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

2 answer(s)
D
Dnomin, 2018-12-03
@Dnomin

the img variable cannot be used in different functions, due to flask. I entered the image in memcashed and everything worked.

A
aderes, 2018-11-27
@de-iure

and you don't use cv2?... isn't that why you have a white window...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question