Added API route to edit camera config
This commit is contained in:
parent
a8c9a7e7dd
commit
6a374d093a
3 changed files with 86 additions and 1 deletions
|
|
@ -9,9 +9,16 @@ class JsonPayload:
|
|||
"""
|
||||
# Try to load as json
|
||||
self.json = request.get_json() #: dict: Dictionary representation of request JSON
|
||||
|
||||
if self.json is None:
|
||||
self.json = {}
|
||||
|
||||
# Store raw response data
|
||||
self.data = request.get_data() #: str: String representation of request data
|
||||
|
||||
if self.data is None:
|
||||
self.data = ""
|
||||
|
||||
def param(self, key, default=None, convert=None):
|
||||
"""
|
||||
Check if a key exists in a JSON/dictionary payload, and returns it.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from openflexure_microscope.api.v1.views import MicroscopeView
|
|||
|
||||
from flask import Blueprint
|
||||
|
||||
from . import capture, record, preview
|
||||
from . import capture, record, preview, config
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
|
@ -31,4 +31,9 @@ def construct_blueprint(microscope_obj):
|
|||
'/preview/<string:operation>',
|
||||
view_func=preview.GPUPreviewAPI.as_view('gpu_preview', microscope=microscope_obj))
|
||||
|
||||
# Config routes
|
||||
blueprint.add_url_rule(
|
||||
'/config',
|
||||
view_func=config.ConfigAPI.as_view('camera_config', microscope=microscope_obj))
|
||||
|
||||
return(blueprint)
|
||||
73
openflexure_microscope/api/v1/blueprints/camera/config.py
Normal file
73
openflexure_microscope/api/v1/blueprints/camera/config.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
from openflexure_microscope.api.utilities import JsonPayload
|
||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
class ConfigAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Get camera configuration
|
||||
|
||||
.. :quickref: Camera config; Get camera configuration
|
||||
"""
|
||||
|
||||
return jsonify(self.microscope.camera.config)
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
Modify camera configuration
|
||||
|
||||
.. :quickref: Camera config; Set camera configuration
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /camera/capture HTTP/1.1
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"analog_gain": 1.0,
|
||||
"digital_gain": 1.0,
|
||||
"jpeg_quality": 75,
|
||||
"picamera_params": {
|
||||
"framerate": 24.0,
|
||||
"saturation": 0,
|
||||
"shutter_speed": 5000
|
||||
}
|
||||
}
|
||||
|
||||
:>header Accept: application/json
|
||||
|
||||
:<json float analog_gain: Analog gain
|
||||
:<json float digital_gain: Digital gain
|
||||
|
||||
:<json list image_resolution: Image resolution in format [x, y]
|
||||
:<json list video_resolution: Video resolution in format [x, y]
|
||||
:<json list numpy_resolution: Raw numpy array resolution in format [x, y]
|
||||
|
||||
:<json int jpeg_quality: JPEG quality (1-100)
|
||||
:<json string shading_table_path: Full path on the Pi to the lens shading table npy file
|
||||
|
||||
:<json json picamera_param: - **awb_gains** *(list)*: Auto-white-balance gains in format [r, g, b]
|
||||
**awb_mode** *(string)*: PiCamera AWB mode
|
||||
**exposure_mode** *(string)*: PiCamera exposure mode
|
||||
**framerate** *(float)*: PiCamera framerate
|
||||
**saturation** *(int)*: PiCamera saturation
|
||||
**shutter_speed** *(string)*: PiCamera shutter speed
|
||||
|
||||
:<header Content-Type: application/json
|
||||
:status 200: capture created
|
||||
|
||||
"""
|
||||
payload = JsonPayload(request)
|
||||
|
||||
print(payload.json)
|
||||
|
||||
self.microscope.camera.config = payload.json
|
||||
|
||||
return jsonify(self.microscope.camera.config)
|
||||
Loading…
Add table
Add a link
Reference in a new issue