forked from miguelgrinberg/flask-video-streaming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
43 lines (34 loc) · 1.16 KB
/
views.py
File metadata and controls
43 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from utilities import gen
from labthings.server.find import find_component
from labthings.server.view import PropertyView
from labthings.server.decorators import doc_response
import io
from flask import Response, send_file
class MjpegStream(PropertyView):
"""
Real-time MJPEG stream from the microscope camera
"""
@doc_response(200, mimetype="multipart/x-mixed-replace")
def get(self):
"""
MJPEG stream from the Pi camera.
"""
camera = find_component("org.raspberrypi.camera")
# Ensure camera worker is running
camera.start_worker()
return Response(
gen(camera), mimetype="multipart/x-mixed-replace; boundary=frame"
)
class SnapshotStream(PropertyView):
"""
Single JPEG snapshot from the camera stream
"""
@doc_response(200, description="Snapshot taken", mimetype="image/jpeg")
def get(self):
"""
Single snapshot from the camera stream
"""
camera = find_component("org.raspberrypi.camera")
# Ensure camera worker is running
camera.start_worker()
return Response(camera.get_frame(), mimetype="image/jpeg")