Skip to content

Commit

Permalink
Fix configuration issues with USB cams
Browse files Browse the repository at this point in the history
The new sensor configuration code doesn't work with USB cams. Make
minimal changes just to stop things from falling over.

Signed-off-by: David Plowman <[email protected]>
  • Loading branch information
davidplowman authored and will-v-pi committed Oct 4, 2023
1 parent 02426bc commit 14f54a9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ def create_preview_configuration(self, main={}, lores=None, raw={}, transform=li
# USB cams can't deliver a raw stream.
if not self._is_rpi_camera():
raw = None
sensor = None
main = self._make_initial_stream_config({"format": "XBGR8888", "size": (640, 480)}, main)
self.align_stream(main, optimal=False)
lores = self._make_initial_stream_config({"format": "YUV420", "size": main["size"]}, lores)
Expand Down Expand Up @@ -701,6 +702,7 @@ def create_still_configuration(self, main={}, lores=None, raw={}, transform=libc
# USB cams can't deliver a raw stream.
if not self._is_rpi_camera():
raw = None
sensor = None
main = self._make_initial_stream_config({"format": "BGR888", "size": self.sensor_resolution}, main)
self.align_stream(main, optimal=False)
lores = self._make_initial_stream_config({"format": "YUV420", "size": main["size"]}, lores)
Expand Down Expand Up @@ -734,6 +736,7 @@ def create_video_configuration(self, main={}, lores=None, raw={}, transform=libc
# USB cams can't deliver a raw stream.
if not self._is_rpi_camera():
raw = None
sensor = None
main = self._make_initial_stream_config({"format": "XBGR8888", "size": (1280, 720)}, main)
self.align_stream(main, optimal=False)
lores = self._make_initial_stream_config({"format": "YUV420", "size": main["size"]}, lores)
Expand Down Expand Up @@ -864,6 +867,9 @@ def _make_libcamera_config(self, camera_config):
self._update_libcamera_stream_config(libcamera_config.at(self.raw_index), camera_config["raw"], buffer_count)
libcamera_config.at(self.raw_index).color_space = libcamera.ColorSpace.Raw()

if not self._is_rpi_camera():
return libcamera_config

# We're always going to set up the sensor config fully.
bit_depth = 0
if 'bit_depth' in camera_config['sensor']:
Expand Down Expand Up @@ -973,10 +979,11 @@ def _update_camera_config(self, camera_config, libcamera_config) -> None:
if self.raw_index >= 0:
self._update_stream_config(camera_config["raw"], libcamera_config.at(self.raw_index))

sensor_config = {}
sensor_config['bit_depth'] = libcamera_config.sensor_config.bit_depth
sensor_config['output_size'] = utils.convert_from_libcamera_type(libcamera_config.sensor_config.output_size)
camera_config['sensor'] = sensor_config
if libcamera_config.sensor_config is not None:
sensor_config = {}
sensor_config['bit_depth'] = libcamera_config.sensor_config.bit_depth
sensor_config['output_size'] = utils.convert_from_libcamera_type(libcamera_config.sensor_config.output_size)
camera_config['sensor'] = sensor_config

def configure_(self, camera_config="preview") -> None:
"""Configure the camera system with the given configuration.
Expand Down

0 comments on commit 14f54a9

Please sign in to comment.