GUI: added check to camera thread to handle encoded jpeg or not encoded streams

This commit is contained in:
appleb_m committed 2026-04-20 09:30:57 +02:00
1 parent 9ece3125f3
commit 8cfb9718e0
1 file changed
+17 -5
+17 -5
View File
@@ -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)