From f942d7bebc134ffa76abd4c085b443b27f165d8a Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 23 Oct 2025 11:11:22 +0200 Subject: [PATCH] fix(camera): BGR to RGB logic moved to Camera --- .../ids_cameras/base_integration/camera.py | 28 +++++++++++-------- csaxs_bec/devices/ids_cameras/ids_camera.py | 2 -- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/csaxs_bec/devices/ids_cameras/base_integration/camera.py b/csaxs_bec/devices/ids_cameras/base_integration/camera.py index bdd27c2..d0cb22b 100644 --- a/csaxs_bec/devices/ids_cameras/base_integration/camera.py +++ b/csaxs_bec/devices/ids_cameras/base_integration/camera.py @@ -66,8 +66,8 @@ class IDSCameraObject: check_error(ueye.is_SetDisplayMode(self.h_cam, ueye.IS_SET_DM_DIB), "IDSCameraObject") if ( - int.from_bytes(self.s_info.nColorMode.value, byteorder="big") - == self.ueye.IS_COLORMODE_BAYER + int.from_bytes(self.s_info.nColorMode.value, byteorder="big") + == self.ueye.IS_COLORMODE_BAYER ): logger.info("Bayer color mode detected.") # setup the color depth to the current windows setting @@ -76,16 +76,16 @@ class IDSCameraObject: ) # TODO This raises an error - maybe check the m_n_colormode value self.bytes_per_pixel = int(self.n_bits_per_pixel / 8) elif ( - int.from_bytes(self.s_info.nColorMode.value, byteorder="big") - == self.ueye.IS_COLORMODE_CBYCRY + int.from_bytes(self.s_info.nColorMode.value, byteorder="big") + == self.ueye.IS_COLORMODE_CBYCRY ): # for color camera models use RGB32 mode self.m_n_colormode = self.ueye.IS_CM_BGRA8_PACKED self.n_bits_per_pixel = self.ueye.INT(32) self.bytes_per_pixel = int(self.n_bits_per_pixel / 8) elif ( - int.from_bytes(self.s_info.nColorMode.value, byteorder="big") - == self.ueye.IS_COLORMODE_MONOCHROME + int.from_bytes(self.s_info.nColorMode.value, byteorder="big") + == self.ueye.IS_COLORMODE_MONOCHROME ): # for color camera models use RGB32 mode self.m_n_colormode = self.ueye.IS_CM_MONO8 @@ -159,11 +159,11 @@ class Camera: """ def __init__( - self, - camera_id: int, - m_n_colormode: Literal[0, 1, 2, 3] = 1, - bits_per_pixel: int = 24, - connect: bool = True, + self, + camera_id: int, + m_n_colormode: Literal[0, 1, 2, 3] = 1, + bits_per_pixel: int = 24, + connect: bool = True, ): self.ueye = ueye self.camera_id = camera_id @@ -263,9 +263,13 @@ class Camera: if array is None: logger.error("Failed to get image data from the camera.") return None - return np.reshape( + img = np.reshape( array, (self.cam.height.value, self.cam.width.value, self.cam.bytes_per_pixel) ) + # If RGB image (H, W, 3), reshuffle channels from BGR → RGB + if img.ndim == 3 and img.shape[2] == 3: + img = img[:, :, ::-1] + return img if __name__ == "__main__": diff --git a/csaxs_bec/devices/ids_cameras/ids_camera.py b/csaxs_bec/devices/ids_cameras/ids_camera.py index 52c857b..3111d61 100644 --- a/csaxs_bec/devices/ids_cameras/ids_camera.py +++ b/csaxs_bec/devices/ids_cameras/ids_camera.py @@ -168,8 +168,6 @@ class IDSCamera(PSIDeviceBase): """Process the image data before sending it to the preview signal.""" if image is None: return - if len(image.shape)==3 and image.shape[2] == 3: - image = image[:,:,::-1] self.image.put(image) def get_last_image(self) -> np.ndarray: