24 lines
649 B
Python
24 lines
649 B
Python
from flask import Flask, render_template, Response
|
|
import cv2
|
|
|
|
app = Flask(__name__)
|
|
|
|
def stream(camera_index):
|
|
cam = cv2.VideoCapture(camera_index)
|
|
while True:
|
|
_, frame = cam.read()
|
|
ret, jpg = cv2.imencode('.jpg', frame)
|
|
jpg2bytes = jpg.tobytes()
|
|
yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + jpg2bytes + b'\r\n\r\n'
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/stream_feed')
|
|
def stream_fedd():
|
|
return Response(stream(0), mimetype='multipart/x-mixed-replace; boundary=frame')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, port=5000, host='0.0.0.0')
|