proof of concept
This commit is contained in:
29
live_flask.py
Normal file
29
live_flask.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import gphoto2 as gp
|
||||
from flask import Flask, Response
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
camera = gp.Camera()
|
||||
camera.init()
|
||||
|
||||
def generate():
|
||||
while True:
|
||||
file = camera.capture_preview()
|
||||
data = file.get_data_and_size()
|
||||
frame = np.frombuffer(data, dtype=np.uint8)
|
||||
frame = cv2.imdecode(frame, cv2.IMREAD_COLOR)
|
||||
|
||||
if frame is not None:
|
||||
_, buffer = cv2.imencode('.jpg', frame)
|
||||
yield (b'--frame\r\n'
|
||||
b'Content-Type: image/jpeg\r\n\r\n' + buffer.tobytes() + b'\r\n')
|
||||
|
||||
@app.route('/liveview')
|
||||
def liveview():
|
||||
return Response(generate(),
|
||||
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
Reference in New Issue
Block a user