How to capture stage from kit app in headless mode?

Hi,

I’m currently working with the Omniverse Kit app in headless mode (kit_service), and it needs to be containerized for my use case. The goal is to capture and export the images of model from different cameras at various angles on the stage. However, since the app is running in headless mode my current approach to capture the model in is failing.

Here’s the code I’ve been using to attempt the capture:

from omni.kit.capture.viewport import CaptureExtension, CaptureOptions

class image_capture():

    def __init__(self):
          self._capture = CaptureExtension.get_instance()

    async def on_capture_images():      

        for i, camera_path in enumerate(self.cameras):
            print(f"Capturing from camera {i+1}/{len(self.cameras)}")
    
            self._capture.options = CaptureOptions(
                camera=camera_path,
                fps=24.0,
                start_frame=1,
                end_frame=1,
                res_width=1000,
                res_height=500,
                output_folder=self._output_dir,
                file_name=f"image_{i:03d}",
                save_alpha=True,
                overwrite_existing_frames=True,
                )
            self._capture.start()

But I am encountering the following error:


Capturing images from 5 cameras...
Capturing from camera 1/5
2025-03-21 11:26:31 [15,827ms] [Warning] [omni.kit.capture.viewport.extension] Capture couldn't be started due to failed to prepare viewport for capture.

Has anyone encountered a similar issue with capturing/exporting in headless mode, especially when the app is containerized? Any guidance for handling this scenario would be greatly appreciated.

Thank you!
Pranav

I will try to find the correct code to capture without the error.

Can you first just try running the code for just one camera, rather than trying to loop it. Maybe that is the problem.

Hey @Pranav.Buradkar

You need to create a viewport, even when working headlessly

Try adding this

import omni.kit.viewport.utility as vp_utils

# Create a new viewport window 
viewport_api = vp_utils.get_viewport_interface()
viewport = viewport_api.create_instance()
viewport_api.set_active_camera(viewport, camera_path)
viewport_api.set_texture_resolution(viewport, 1000, 500)
1 Like

Thanks @AshleyG_NVIDIA.
It worked

1 Like