ImagesΒΆ

Example for sending images to the viewer.

We can send backgrond images to display behind the viewer (useful for visualizing NeRFs), or images to render as 3D textures.

 1import time
 2from pathlib import Path
 3
 4import imageio.v3 as iio
 5import numpy as np
 6
 7import viser
 8
 9
10def main() -> None:
11    server = viser.ViserServer()
12
13    # Add a background image.
14    server.scene.set_background_image(
15        iio.imread(Path(__file__).parent / "assets/Cal_logo.png"),
16        format="png",
17    )
18
19    # Add main image.
20    server.scene.add_image(
21        "/img",
22        iio.imread(Path(__file__).parent / "assets/Cal_logo.png"),
23        4.0,
24        4.0,
25        format="png",
26        wxyz=(1.0, 0.0, 0.0, 0.0),
27        position=(2.0, 2.0, 0.0),
28    )
29    while True:
30        server.scene.add_image(
31            "/noise",
32            np.random.randint(0, 256, size=(400, 400, 3), dtype=np.uint8),
33            4.0,
34            4.0,
35            format="jpeg",
36            wxyz=(1.0, 0.0, 0.0, 0.0),
37            position=(2.0, 2.0, -1e-2),
38        )
39        time.sleep(0.2)
40
41
42if __name__ == "__main__":
43    main()