Skip to main content
Capture camera observations directly into Float32Array tensors for in-browser policy inference (for example ONNX Runtime Web). This skips the toDataURLImage.decode round-trip the snapshot helpers use: the scene is rendered offscreen and read straight from the GPU into a normalized tensor. The hook keeps one reusable capture session per camera and re-aims each session to the live MuJoCo pose every step, so it is cheap to call inside a physics loop.
For the difference between snapshots, live streams, and tensors, see Cameras and Captures.

Signature

Each CameraFrameTensorResult has data (a Float32Array), shape, width, height, channels, layout, range, plus the camera and source used.

Usage

Mounted streams

Use usePolicyCameraTensorsFromMountedStreams to resolve dataset stream names to mounted MuJoCo cameras, sites, or bodies automatically, mirroring usePolicyCameraFramesFromMountedStreams:

Notes

  • capture() is synchronous and returns fresh Float32Arrays each call.
  • Render at the model’s input resolution (set width/height per stream) so no separate downscale step is needed.
  • For one-off conversions use captureCameraFrameTensor(); for lower-level control, createCameraFrameCaptureSession() exposes captureTensor() and capturePixels(), and pixelsToPolicyImageTensor() converts a raw RGBA buffer.
  • Use the snapshot APIs (usePolicyCameraFramesFromMountedStreams) instead when a policy endpoint expects PNG/JPEG data URLs rather than tensors.