mirror of
https://github.com/m5stack/M5Unit-V2-AICamera.git
synced 2026-05-20 10:57:45 -07:00
Update: Create stream.py
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import cv2
|
||||||
|
from flask import Flask, Response
|
||||||
|
import threading
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
cap = cv2.VideoCapture(0)
|
||||||
|
#cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M','J','P','G'))
|
||||||
|
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('Y','U','Y','V'))
|
||||||
|
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
|
||||||
|
|
||||||
|
current_frame = None
|
||||||
|
|
||||||
|
def capture_loop():
|
||||||
|
global current_frame
|
||||||
|
while True:
|
||||||
|
ret, frame = cap.read()
|
||||||
|
if not ret:
|
||||||
|
break
|
||||||
|
ret, jpeg = cv2.imencode('.jpg', frame)
|
||||||
|
current_frame = jpeg.tobytes()
|
||||||
|
|
||||||
|
threading.Thread(target=capture_loop, daemon=True).start()
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def video_feed():
|
||||||
|
def generate():
|
||||||
|
while True:
|
||||||
|
yield (b'--frame\r\n'
|
||||||
|
b'Content-Type: image/jpeg\r\n\r\n' + current_frame + b'\r\n')
|
||||||
|
return Response(generate(),
|
||||||
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host='0.0.0.0', port=8000)
|
||||||
Reference in New Issue
Block a user