Background Image#

This example shows how to set a background image. This is useful for relaying from a rendering model such as NeRFs, Gaussian Splatting, or GANs.

from asyncio import sleep

import imageio as iio
from tqdm import tqdm

from vuer import Vuer
from import ClientEvent
from vuer.schemas import Scene, SceneBackground

reader = iio.get_reader("../../../assets/movies/disney.webm")

app = Vuer()

# we add the handler here because the spawn(start=True) binding is blocking.
async def on_camera(event: ClientEvent, session):
    assert event == "CAMERA_MOVE", "the event type should be correct"
    print("camera event", event.etype, event.value)

async def show_heatmap(session):
    session.set @ Scene()

    for i, frame in tqdm(enumerate(reader), desc="playing video"):

        # use the upsert(..., to="bgChildren") syntax, so it is in global frame.
                # Can scale the images down.
                frame[::1, ::1, :],
                # One of ['b64png', 'png', 'b64jpg', 'jpg']
                # 'b64png' does not work for some reason, but works for the nerf demo.
                # 'jpg' encoding is significantly faster than 'png'.
        # 'jpg' encoding should give you about 30fps with a 16ms wait in-between.
        await sleep(0.016)