Live Webcam Flask Opencv Python


from flask import Flask, Response
import cv2
app = Flask(__name__)
video = cv2.VideoCapture(0)
def index():
return "Default Message"
def gen(video):
while True:
success, image =
ret, jpeg = cv2.imencode('.jpg', image)
frame = jpeg.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
def video_feed():
global video
return Response(gen(video),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':'', port=2204, threaded=True)

RUN: python

Artificial Intelligence and Data Science

Love podcasts or audiobooks? Learn on the go with our new app.