Created
April 20, 2019 05:03
-
-
Save dario61081/9aac5c7051d83ab5ed9890e33858e2f6 to your computer and use it in GitHub Desktop.
Servidor de video desde la webcam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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