Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image decoding to CameraFrustumHandle when ._image is set via binary #368

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abcamiletto
Copy link

Related to #351

To speed up image visualization in Camera Frustum by loading directly from disk it is possible to do

from pathlib import Path

frustum_handle._image_data = Path("some_image.jpeg").read_bytes()
frustum_handle.image_media_type = "image/jpeg"

This creates a weird situation where frustum_handle.image is None because the internal ._image was never set.

This PR fixes that behaviour by decoding the ._image_data attribute if it exists and ._image is None

@brentyi
Copy link
Collaborator

brentyi commented Jan 19, 2025

Thanks for the PR @abcamiletto!

My main concern is that ._image will updated the first time that ._image_data is assigned, but not if ._image_data is reassigned. I'm also a little hesitant about making usability improvements for external use of internal attributes/APIs.

If we want to improve the user/developer experience here it would be nice to just add support for the raw bytes functionality to the public API. Open to ideas here, I'm also still okay with this proposal from the previous issue:

supporting already-encoded images by (1) changing the type of the .image property from np.ndarray | None to np.ndarray | bytes | None and (2) bypassing the encoding logic if bytes are passed in. I'd like to be consistent here though, so if we make this change we should also do it everywhere else an image can be passed as an argument in viser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants