Capture#
omni.kit.widget.viewport.capture
is the interface to a capture a Viewport’s state and AOVs.
It provides a few convenient implementations that will write AOV(s) to disk or pass CPU buffers for pixel access.
FileCapture#
A simple delegate to capture a single AOV to a single file. It can be used as is, or subclassed to access additional information/meta-data to be written. By default it will capture a color AOV, but accepts an explicit AOV-name to capture instead.
from omni.kit.widget.viewport.capture import FileCapture
capture = viewport_api.schedule_capture(FileCapture(image_path))
captured_aovs = await capture.wait_for_result()
if captured_aovs:
print(f'AOV "{captured_aovs[0]}" was written to "{image_path}"')
else:
print(f'No image was written to "{image_path}"')
A sample subclass implementation to write additional data.
from omni.kit.widget.viewport.capture import FileCapture
SideCarWriter(FileCapture):
def __init__(self, image_path, aov_name=''):
super().__init__(image_path, aov_name)
def capture_aov(self, file_path, aov):
# Call the default file-saver
self.save_aov_to_file(file_path, aov)
# Possibly append data to a custom image
print(f'Wrote AOV "{aov['name']}" to "{file_path}")
print(f' with view: {self.view}")
print(f' with projection: {self.projection}")
capture = viewport_api.schedule_capture(SideCarWriter(image_path))
captured_aovs = await capture.wait_for_result()
if captured_aovs:
print(f'AOV "{captured_aovs[0]}" was written to "{image_path}"')
else:
print(f'No image was written to "{image_path}"')
ByteCapture#
A simple delegate to capture a single AOV and deliver it as CPU pixel data. It can be used as is with a free-standing function, or subclassed to access additional information/meta-data. By default it will capture a color AOV, but accepts an explicit AOV-name to capture instead.
from omni.kit.widget.viewport.capture import ByteCapture
def on_capture_completed(buffer, buffer_size, width, height, format):
print(f'PixelData resolution: {width} x {height}')
print(f'PixelData format: {format}')
capture = viewport_api.schedule_capture(ByteCapture(on_capture_completed))
captured_aovs = await capture.wait_for_result()
if captured_aovs:
print(f'AOV "{captured_aovs[0]}" was written to "{image_path}"')
print(f'It had a camera view of {capture.view}')
else:
print(f'No image was written to "{image_path}"')
A sample subclass implementation to write additional data.
from omni.kit.widget.viewport.capture import ByteCapture
SideCarData(ByteCapture):
def __init__(self, image_path, aov_name=''):
super().__init__(image_path, aov_name)
def on_capture_completed(self, buffer, buffer_size, width, height, format):
print(f'PixelData resolution: {width} x {height}')
print(f'PixelData format: {format}')
print(f'PixelData has a camera view of {self.view}')
capture = viewport_api.schedule_capture(SideCarData(image_path))
captured_aovs = await capture.wait_for_result()
if captured_aovs:
print(f'AOV "{captured_aovs[0]}" was written to "{image_path}"')
else:
print(f'No image was written to "{image_path}"')