Skip to content

Instantly share code, notes, and snippets.

@dario61081
Created April 20, 2019 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dario61081/9aac5c7051d83ab5ed9890e33858e2f6 to your computer and use it in GitHub Desktop.
Save dario61081/9aac5c7051d83ab5ed9890e33858e2f6 to your computer and use it in GitHub Desktop.
Servidor de video desde la webcam
import cv2
from flask import *
class Camera:
def __init__(self, index):
self.index = index
self.cap = cv2.VideoCapture(0)
def __del__(self):
self.cap.release()
def getFrame(self):
while True:
_, frame = self.cap.read()
_, image = cv2.imencode('.jpeg', frame)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + image.tobytes() + b'\r\n')
app = Flask(__name__)
app.jinja_env.cache = None
@app.route('/cam1')
def cam():
return Response(Camera(0).getFrame(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', port='15000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment