diff --git a/src/viser/_scene_api.py b/src/viser/_scene_api.py index e9304c556..a8a09ad11 100644 --- a/src/viser/_scene_api.py +++ b/src/viser/_scene_api.py @@ -100,6 +100,12 @@ def _encode_image_binary( return media_type, binary +def _decode_image_binary(binary: bytes) -> np.ndarray: + with io.BytesIO(binary) as buf: + image = iio.imread(buf) + return image + + TVector = TypeVar("TVector", bound=tuple) diff --git a/src/viser/_scene_handles.py b/src/viser/_scene_handles.py index 26566d15f..6c057cc7e 100644 --- a/src/viser/_scene_handles.py +++ b/src/viser/_scene_handles.py @@ -361,6 +361,11 @@ class CameraFrustumHandle( @property def image(self) -> np.ndarray | None: """Current content of the image. Synchronized automatically when assigned.""" + if self._image is None and self._image_data is not None: + from ._scene_api import _decode_image_binary + + self._image = _decode_image_binary(self._image_data) + return self._image @image.setter