diff --git a/picamera2/picamera2.py b/picamera2/picamera2.py index a3709aef..42373447 100644 --- a/picamera2/picamera2.py +++ b/picamera2/picamera2.py @@ -270,12 +270,12 @@ def __init__(self, camera_num=0, verbose_console=None, tuning=None, allocator=No _log.debug(f"{self.camera_manager}") # We deliberately make raw streams with no size so that it will be filled in # later once the main stream size has been set. - self.preview_configuration = self.create_preview_configuration() - self.preview_configuration.enable_raw() # causes the size to be reset to None - self.still_configuration = self.create_still_configuration() - self.still_configuration.enable_raw() # ditto - self.video_configuration = self.create_video_configuration() - self.video_configuration.enable_raw() # ditto + self.preview_configuration_ = CameraConfiguration(self.create_preview_configuration(), self) + self.preview_configuration_.enable_raw() # causes the size to be reset to None + self.still_configuration_ = CameraConfiguration(self.create_still_configuration(), self) + self.still_configuration_.enable_raw() # ditto + self.video_configuration_ = CameraConfiguration(self.create_video_configuration(), self) + self.video_configuration_.enable_raw() # ditto except Exception: _log.error("Camera __init__ sequence did not complete.") raise RuntimeError("Camera __init__ sequence did not complete.") @@ -425,12 +425,10 @@ def _grab_camera(self, idx): elif isinstance(idx, int): return self.camera_manager.cameras[idx] - def _initialize_camera(self) -> bool: + def _initialize_camera(self) -> None: """Initialize camera :raises RuntimeError: Failure to initialise camera - :return: True if success - :rtype: bool """ if not self.camera_manager.cameras: _log.error("Camera(s) not found (Do not forget to disable legacy camera with raspi-config).") @@ -458,7 +456,6 @@ def _initialize_camera(self) -> bool: self.sensor_format = self._native_mode['format'] _log.info('Initialization successful.') - return True def __identify_camera(self): for idx, address in enumerate(self.camera_manager.cameras): @@ -471,7 +468,9 @@ def _open_camera(self) -> None: :raises RuntimeError: Failed to setup camera """ - if not self._initialize_camera(): + try: + self._initialize_camera() + except RuntimeError: raise RuntimeError("Failed to initialize camera") # This now throws an error if it can't open the camera. @@ -628,12 +627,12 @@ def close(self) -> None: self.streams = None self.stream_map = None self.camera = None - self.camera_ctrl_info = None + self.camera_ctrl_info = {} self.camera_config = None self.libcamera_config = None - self.preview_configuration_ = None - self.still_configuration_ = None - self.video_configuration_ = None + self.preview_configuration = {} + self.still_configuration = {} + self.video_configuration = {} self.notifymeread.close() os.close(self.notifyme_w) # Clean up the allocator