Added size and position params to GPU preview route
This commit is contained in:
parent
51cd776700
commit
366b771b72
2 changed files with 21 additions and 5 deletions
|
|
@ -1,13 +1,16 @@
|
||||||
|
from openflexure_microscope.api.utilities import JsonPayload
|
||||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||||
|
|
||||||
from flask import jsonify
|
from flask import jsonify, request
|
||||||
|
|
||||||
|
|
||||||
class GPUPreviewAPI(MicroscopeView):
|
class GPUPreviewAPI(MicroscopeView):
|
||||||
|
|
||||||
def post(self, operation):
|
def post(self, operation):
|
||||||
"""
|
"""
|
||||||
Create a new image capture.
|
Start or stop the onboard GPU preview.
|
||||||
|
Optional "window" parameter can be passed to control the position and size of the preview window,
|
||||||
|
in the format ``[x, y, width, height]``.
|
||||||
|
|
||||||
.. :quickref: GPU Preview; Start/stop preview
|
.. :quickref: GPU Preview; Start/stop preview
|
||||||
|
|
||||||
|
|
@ -18,6 +21,10 @@ class GPUPreviewAPI(MicroscopeView):
|
||||||
POST /camera/preview/start HTTP/1.1
|
POST /camera/preview/start HTTP/1.1
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"window": [0, 0, 480, 320],
|
||||||
|
}
|
||||||
|
|
||||||
.. sourcecode:: http
|
.. sourcecode:: http
|
||||||
|
|
||||||
POST /camera/preview/stop HTTP/1.1
|
POST /camera/preview/stop HTTP/1.1
|
||||||
|
|
@ -29,7 +36,16 @@ class GPUPreviewAPI(MicroscopeView):
|
||||||
:status 200: preview started/stopped
|
:status 200: preview started/stopped
|
||||||
"""
|
"""
|
||||||
if operation == "start":
|
if operation == "start":
|
||||||
self.microscope.camera.start_preview()
|
payload = JsonPayload(request)
|
||||||
|
|
||||||
|
window = payload.param('window', default=[])
|
||||||
|
fullscreen = False
|
||||||
|
|
||||||
|
if len(window) != 4 or not all(isinstance(n, int) for n in window):
|
||||||
|
fullscreen = True
|
||||||
|
window = None
|
||||||
|
|
||||||
|
self.microscope.camera.start_preview(fullscreen=fullscreen, window=window)
|
||||||
elif operation == "stop":
|
elif operation == "stop":
|
||||||
self.microscope.camera.stop_preview()
|
self.microscope.camera.stop_preview()
|
||||||
return jsonify(self.microscope.state)
|
return jsonify(self.microscope.state)
|
||||||
|
|
|
||||||
|
|
@ -225,9 +225,9 @@ class StreamingCamera(BaseCamera):
|
||||||
|
|
||||||
# LAUNCH ACTIONS
|
# LAUNCH ACTIONS
|
||||||
|
|
||||||
def start_preview(self) -> bool:
|
def start_preview(self, fullscreen=True, window=None) -> bool:
|
||||||
"""Start the on board GPU camera preview."""
|
"""Start the on board GPU camera preview."""
|
||||||
self.camera.start_preview()
|
self.camera.start_preview(fullscreen=fullscreen, window=window)
|
||||||
self.state['preview_active'] = True
|
self.state['preview_active'] = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue