Skip to content

Commit

Permalink
Add a SensorConfiguration class to the CameraConfiguration object
Browse files Browse the repository at this point in the history
This will allow users of the configuration classes to set the sensor
configuration output_size and bit_depth in the natural way, e.g.

picam2.still_configuration.sensor.output_size = (4056, 3040)

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman committed Nov 10, 2023
1 parent fe755dc commit 05fb9b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion picamera2/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ class StreamConfiguration(Configuration):
_FORWARD_FIELDS = {}


class SensorConfiguration(Configuration):
_ALLOWED_FIELDS = ("output_size", "bit_depth")
_FIELD_CLASS_MAP = {}
_FORWARD_FIELDS = {}


class CameraConfiguration(Configuration):
_ALLOWED_FIELDS = ("use_case", "buffer_count", "transform", "display", "encode", "colour_space",
"controls", "main", "lores", "raw", "queue", "sensor")
_FIELD_CLASS_MAP = {"main": StreamConfiguration, "lores": StreamConfiguration, "raw": StreamConfiguration}
_FIELD_CLASS_MAP = {"main": StreamConfiguration, "lores": StreamConfiguration, "raw": StreamConfiguration,
"sensor": SensorConfiguration}
_FORWARD_FIELDS = {"size": "main", "format": "main"}

def __init__(self, d={}, picam2=None):
Expand All @@ -102,6 +109,8 @@ def __init__(self, d={}, picam2=None):
# can delete the raw stream if they wish.
if 'raw' not in d:
self.enable_raw()
if 'sensor' not in d:
self.sensor = SensorConfiguration()

def enable_lores(self, onoff=True):
if onoff:
Expand Down
6 changes: 4 additions & 2 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,17 @@ def _make_libcamera_config(self, camera_config):

# We're always going to set up the sensor config fully.
bit_depth = 0
if 'bit_depth' in camera_config['sensor']:
if camera_config['sensor'] is not None and 'bit_depth' in camera_config['sensor'] and \
camera_config['sensor']['bit_depth'] is not None:
bit_depth = camera_config['sensor']['bit_depth']
elif 'raw' in camera_config and camera_config['raw'] is not None and 'format' in camera_config['raw']:
bit_depth = SensorFormat(camera_config['raw']['format']).bit_depth
else:
bit_depth = SensorFormat(self.sensor_format).bit_depth

output_size = None
if 'output_size' in camera_config['sensor']:
if camera_config['sensor'] is not None and 'output_size' in camera_config['sensor'] and \
camera_config['sensor']['output_size'] is not None:
output_size = camera_config['sensor']['output_size']
elif 'raw' in camera_config and camera_config['raw'] is not None and 'size' in camera_config['raw']:
output_size = camera_config['raw']['size']
Expand Down

0 comments on commit 05fb9b2

Please sign in to comment.