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

Github Link here



Artificial Intelligence and Data Science

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store