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