Fixed camera settings
Since splitting the camera config into a separate YAML file, we've broken the ability to change the camera's configuration via the API (or at any time except when the camera is set up, I think). This (mostly) fixes that, though I get type errors that I've had to work around (e.g. when setting shutter_speed), see `pi.py`
This commit is contained in:
parent
e90eb7c2d4
commit
e6ec800c21
4 changed files with 20 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ from openflexure_microscope.api.utilities import gen, JsonPayload
|
||||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||||
|
|
||||||
from flask import Response, Blueprint, jsonify, request
|
from flask import Response, Blueprint, jsonify, request
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class StreamAPI(MicroscopeView):
|
class StreamAPI(MicroscopeView):
|
||||||
|
|
@ -99,8 +100,6 @@ class ConfigAPI(MicroscopeView):
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
{
|
{
|
||||||
"analog_gain": 1.0,
|
|
||||||
"digital_gain": 1.0,
|
|
||||||
"image_resolution": [
|
"image_resolution": [
|
||||||
2592,
|
2592,
|
||||||
1944
|
1944
|
||||||
|
|
@ -111,7 +110,9 @@ class ConfigAPI(MicroscopeView):
|
||||||
1312,
|
1312,
|
||||||
976
|
976
|
||||||
],
|
],
|
||||||
"picamera_params": {
|
"picamera_settings": {
|
||||||
|
"analog_gain": 1.0,
|
||||||
|
"digital_gain": 1.0,
|
||||||
"awb_gains": [
|
"awb_gains": [
|
||||||
0.92578125,
|
0.92578125,
|
||||||
2.94921875
|
2.94921875
|
||||||
|
|
@ -125,7 +126,6 @@ class ConfigAPI(MicroscopeView):
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"openflexure_microscope.plugins.default:Plugin"
|
"openflexure_microscope.plugins.default:Plugin"
|
||||||
],
|
],
|
||||||
"shading_table_path": "/home/pi/.openflexure/microscopelst.npy",
|
|
||||||
"video_resolution": [
|
"video_resolution": [
|
||||||
832,
|
832,
|
||||||
624
|
624
|
||||||
|
|
@ -170,7 +170,7 @@ class ConfigAPI(MicroscopeView):
|
||||||
"""
|
"""
|
||||||
payload = JsonPayload(request)
|
payload = JsonPayload(request)
|
||||||
|
|
||||||
print(payload.json)
|
logging.debug("Updating settings from POST request.")
|
||||||
|
|
||||||
self.microscope.write_config(payload.json)
|
self.microscope.write_config(payload.json)
|
||||||
self.microscope.save_config()
|
self.microscope.save_config()
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,14 @@ class BaseCamera(object):
|
||||||
self.images = self.load_capture_db(self.images_db)
|
self.images = self.load_capture_db(self.images_db)
|
||||||
self.videos = self.load_capture_db(self.videos_db)
|
self.videos = self.load_capture_db(self.videos_db)
|
||||||
|
|
||||||
|
def apply_config(self, config):
|
||||||
|
"""Update settings from a config dictionary"""
|
||||||
|
self.config.update(config)
|
||||||
|
|
||||||
|
def read_config(self, config):
|
||||||
|
"""Return the current settings as a dictionary"""
|
||||||
|
return self.config
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
"""Create camera on context enter."""
|
"""Create camera on context enter."""
|
||||||
return self
|
return self
|
||||||
|
|
|
||||||
|
|
@ -184,12 +184,17 @@ class StreamingCamera(BaseCamera):
|
||||||
set_digital_gain(self.camera, value)
|
set_digital_gain(self.camera, value)
|
||||||
elif key == 'analog_gain':
|
elif key == 'analog_gain':
|
||||||
set_analog_gain(self.camera, value)
|
set_analog_gain(self.camera, value)
|
||||||
|
elif key == "shutter_speed":
|
||||||
|
self.camera.shutter_speed = int(value)
|
||||||
else:
|
else:
|
||||||
setattr(self.camera, key, value) # Write setting to camera
|
setattr(self.camera, key, value) # Write setting to camera
|
||||||
|
|
||||||
# StreamingCamera parameters (applied via StreamingCamera config)
|
# StreamingCamera parameters (applied via StreamingCamera config)
|
||||||
for key, value in config.items(): # For each provided setting
|
for key, value in config.items(): # For each provided setting
|
||||||
if key != 'picamera_settings': # We already handled this
|
if key in self.config.keys():
|
||||||
|
if key != 'picamera_settings': # We already handled this
|
||||||
|
logging.warn("{} is not in the streaming camera settings dictionary - adding it.")
|
||||||
|
#continue #TODO: filter settings somehow?
|
||||||
logging.debug("Setting parameter {}: {}".format(key, value))
|
logging.debug("Setting parameter {}: {}".format(key, value))
|
||||||
self.config[key] = value
|
self.config[key] = value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ class Microscope(object):
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
if self.camera:
|
if self.camera:
|
||||||
# Update camera config
|
# Update camera config
|
||||||
self.camera.config.update(config)
|
self.camera.apply_config(config)
|
||||||
|
|
||||||
# If attached to a stage
|
# If attached to a stage
|
||||||
# TODO: Convert stage settings into a config expansion
|
# TODO: Convert stage settings into a config expansion
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue