Images

Display background images and 3D image textures in the scene.

Display background images and 3D image textures positioned in world space.

Features:

Note

This example requires external assets. To download them, run:

git clone -b v1.0.0 https://github.com/nerfstudio-project/viser.git
cd viser/examples
./assets/download_assets.sh
python 01_scene/04_images.py  # With viser installed.

Source: examples/01_scene/04_images.py

Images

Code

 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()