About using webcamera live stream

I’m using flask with login system, in this code. After running I get this error:
[ WARN:1@5.165] global cap_msmf.cpp:1759 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -1072873821

# main.py
import cv2
import imutils
from flask import Blueprint, render_template, Response
from flask_login import login_required, current_user
from imutils.video import WebcamVideoStream
from create import create_app

vs = WebcamVideoStream(src=0).start()
main = Blueprint('main', __name__)
app = create_app()


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/profile')
@login_required
def profile():
    return render_template('profile.html', name=current_user.name)


@app.route('/kamera')
@login_required
def video_feed():
    return Response(gen(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')


def gen():
    while True:
        frame = vs.read()
        frame = imutils.resize(frame, height=720, width=1280)
        ret, jpeg = cv2.imencode('.jpg', frame)
        if ret:
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + jpeg.tobytes() + b'\r\n\r\n')


if __name__ == '__main__':
    app.run(host='0.0.0.0', threaded=True)

welcome.

that code is using imutils. for support with imutils, please contact the author of that library:

just curious – where & how would you run that ?