diff --git a/src/aare/gui/threads/camera_thread.py b/src/aare/gui/threads/camera_thread.py index 456d0642..33320f58 100644 --- a/src/aare/gui/threads/camera_thread.py +++ b/src/aare/gui/threads/camera_thread.py @@ -76,17 +76,29 @@ class SampleCameraThread(QThread): for part in r[:-1]: try: decoded = json.loads(part.decode("utf-8")) - if isinstance(decoded, dict) and "shape" in decoded: + if isinstance(decoded, dict): header = decoded break - except: + except Exception: continue if header: - h, w = header["shape"][:2] - raw = np.frombuffer(data, np.uint8).reshape((h, w)) + encoding = str(header.get("encoding", "")).lower() - rgb = cv2.cvtColor(raw, cv2.COLOR_BAYER_GB2RGB) # choose correct Bayer order + if encoding == "jpeg": + encoded = np.frombuffer(data, dtype=np.uint8) + bgr = cv2.imdecode(encoded, cv2.IMREAD_COLOR) + if bgr is None: + print("Failed to decode JPEG image from zmq stream") + continue + rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB) + elif "shape" in header: + h, w = header["shape"][:2] + raw = np.frombuffer(data, np.uint8).reshape((h, w)) + rgb = cv2.cvtColor(raw, cv2.COLOR_BAYER_GB2RGB) + else: + print(f"Unsupported header in zmq stream: {header}") + continue if self.__measure_focus: gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)