From e89ad935357a3c6629b520fa7c09d94d08ec80d5 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Thu, 18 Sep 2025 12:11:15 +0100 Subject: [PATCH] Specify the camera board not the sensor model during configuration. --- ofm_config_full.json | 2 +- .../things/camera/picamera.py | 30 +++++++++++-------- .../camera/picamera_recalibrate_utils.py | 5 ++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ofm_config_full.json b/ofm_config_full.json index 28adf496..60b85a66 100644 --- a/ofm_config_full.json +++ b/ofm_config_full.json @@ -3,7 +3,7 @@ "/camera/": { "class": "openflexure_microscope_server.things.camera.picamera:StreamingPiCamera2", "kwargs": { - "sensor_model": "imx219" + "camera_board": "picamera_v2" } }, "/stage/": "openflexure_microscope_server.things.stage.sangaboard:SangaboardThing", diff --git a/src/openflexure_microscope_server/things/camera/picamera.py b/src/openflexure_microscope_server/things/camera/picamera.py index 8d00b007..be01b337 100644 --- a/src/openflexure_microscope_server/things/camera/picamera.py +++ b/src/openflexure_microscope_server/things/camera/picamera.py @@ -47,9 +47,9 @@ from . import picamera_tuning_file_utils as tf_utils from . import BaseCamera, ArrayModel -SUPPORTED_SENSOR_INFO = { - "imx219": recalibrate_utils.IMX219_SENSOR_INFO, - "imx477": recalibrate_utils.IMX477_SENSOR_INFO, +SUPPORTED_CAMS_SENSOR_INFO = { + "picamera_v2": recalibrate_utils.IMX219_SENSOR_INFO, + "picamera_hq": recalibrate_utils.IMX477_SENSOR_INFO, } @@ -139,29 +139,33 @@ class StreamingPiCamera2(BaseCamera): generalisation. """ - def __init__(self, camera_num: int = 0, sensor_model: str = "imx219") -> None: + def __init__(self, camera_num: int = 0, camera_board: str = "picamera_v2") -> None: """Initialise the camera with the given camera number. This makes no connection to the camera (except to get the default tuning file). :param camera_num: The number of the camera. This should generally be left as 0 as most Raspberry Pi boards only support 1 camera. - :param sensor_model: The sensor model of the image sensor on this picamera. + :param camera_board: The camera board used. Supported options are "picamera_v2" + and "picamera_hq". """ super().__init__() self._setting_save_in_progress = False self._camera_num = camera_num - self._sensor_model = sensor_model - if sensor_model not in SUPPORTED_SENSOR_INFO: + self._camera_board = camera_board + if camera_board not in SUPPORTED_CAMS_SENSOR_INFO: raise PicameraModelError( - f"The sensor model {sensor_model} is not supported." + f"The camera_board {camera_board} is not supported. Supported boards " + f"are {SUPPORTED_CAMS_SENSOR_INFO.keys()}." ) - self._sensor_info = SUPPORTED_SENSOR_INFO[sensor_model] + self._sensor_info = SUPPORTED_CAMS_SENSOR_INFO[camera_board] self._picamera_lock = None self._picamera = None # Load the tuning file for the specified sensor mode. - self.default_tuning = tf_utils.load_default_tuning(sensor_model) + self.default_tuning = tf_utils.load_default_tuning( + self._sensor_info.sensor_model + ) # Set tuning to default tuning. This will be overwritten when the Thing is # connects to the server if tuning is saved to disk. @@ -410,10 +414,10 @@ class StreamingPiCamera2(BaseCamera): ) if check_sensor_model: hw_sensor_model = self._picamera.camera_properties["Model"] - if hw_sensor_model != self._sensor_model: + if hw_sensor_model != self._sensor_info.sensor_model: raise PicameraModelError( - f"Wrong Picamera model. Expecting {self._sensor_model}, but " - f"found {hw_sensor_model}." + f"Wrong Picamera model. Expecting {self._sensor_info.sensor_model}, " + f"but found {hw_sensor_model}." ) self._picamera_lock = RLock() diff --git a/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py b/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py index 50d6c3ed..5f38ee6e 100644 --- a/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py +++ b/src/openflexure_microscope_server/things/camera/picamera_recalibrate_utils.py @@ -56,6 +56,9 @@ import picamera2 class SensorInfo(BaseModel): """Information about the sensor used for calibration and property setting.""" + sensor_model: str + """The model of the sensor, as specified by the Picamera2 library.""" + unpacked_pixel_format: str """The format of the unpacked pixels.""" @@ -76,6 +79,7 @@ class SensorInfo(BaseModel): IMX219_SENSOR_INFO = SensorInfo( + sensor_model="imx219", unpacked_pixel_format="SBGGR10", bit_depth=10, blacklevel=64, @@ -85,6 +89,7 @@ IMX219_SENSOR_INFO = SensorInfo( ) IMX477_SENSOR_INFO = SensorInfo( + sensor_model="imx477", unpacked_pixel_format="SBGGR12", bit_depth=12, blacklevel=256,