Images¶
Display background images and 3D image textures in the scene.
Display background images and 3D image textures positioned in world space.
Features:
viser.SceneApi.set_background_image()
for background images behind the sceneviser.SceneApi.add_image()
for 3D-positioned image planes in world coordinatesStatic images from files and dynamic procedural content
Image positioning, scaling, and orientation in 3D space
Note
This example requires external assets. To download them, run:
cd /path/to/viser/examples/assets
./download_assets.sh
Source: examples/01_scene/04_images.py

Code¶
1import time
2from pathlib import Path
3
4import imageio.v3 as iio
5import numpy as np
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 np.random.randint(0, 256, size=(400, 400, 3), dtype=np.uint8),
32 4.0,
33 4.0,
34 format="jpeg",
35 wxyz=(1.0, 0.0, 0.0, 0.0),
36 position=(2.0, 2.0, -1e-2),
37 )
38 time.sleep(0.2)
39
40
41if __name__ == "__main__":
42 main()