Wait for updates / rendering before caputure

Hello,

I`m capturing images inside of omniverse.

Before I capture, I would like to change to position and direction of the camera. This is how I do that:
viewportWindow.set_camera_position(cameraPath, 0, 0, 5, True)
viewportWindow.set_camera_target(cameraPath, 0, 0, 0, True)

That works fine, but when I capture the next frame, I still get an image from the old position, because I have to wait for the viewport update.

I tried the following:

asyncio.ensure_future(omni.kit.app.get_app().next_update_async())

and

await omni.kit.app.get_app().next_update_async()

But that does not work. How can I wait for the viewport update after changing camera parameter?

And what about the raytracing state? Is there a way to wait for finishing the current image (later I would like to switch to iray for capturing images, so I have to wait for the ray tracing).

Thank you for your help

Small update…

instead of calling next_update_async I added a sleep(5) to wait for 5 seconds… but event that, does not change anything… only the second render request is created with the updates camera parameters - reagardless of the waiting duration.

Here is the full code:
@router.post(“/render”, description=“Renders a session”, summary=“Renders the current session from a specified camera”)
async def post_render(data: dict = fastapi.Body(None)):
renderer = omni.renderer_capture.acquire_renderer_capture_interface()

viewportWindow = omni.kit.viewport_legacy.get_default_viewport_window()

currentCameraPath = viewportWindow.get_active_camera()
requestId = data.get("requestId", "00000000-0000-0000-0000-000000000000")
acceptRenderedImageUri = data.get("acceptRenderedImageUri", "https://localhost:6001/api/session/00000000-0000-0000-0000-000000000000/AcceptRenderedImage")
cameraPath = data.get("cameraPath", "/Stage/Cameras/Interactive")

def renderImageIntoMemeryCallback(capsule, length, width, height, textureFormat):
    try:
        ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
        ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]

        pointer = ctypes.pythonapi.PyCapsule_GetPointer(capsule, None)
    
        ap = ctypes.cast(pointer, ctypes.POINTER(ctypes.c_byte * length))
    
        imageData = base64.b64encode(ap.contents)

        viewportWindow.set_active_camera(currentCameraPath)

        req = urllib.request.Request(acceptRenderedImageUri, method="POST")
        req.add_header('RequestId', requestId)
        req.add_header('ImageWidth', width)
        req.add_header('ImageHeight', height)
        req.add_header('ImageFormat', str(textureFormat))
        req.add_header('CameraPath', cameraPath)
        
        gcontext = ssl.SSLContext()

        urllib.request.urlopen(req, imageData, context=gcontext)
    except:
        print(sys.exc_info()[0])

if currentCameraPath != cameraPath:
    viewportWindow.set_active_camera(cameraPath)

viewportWindow.set_camera_position(cameraPath, 0, 0, 5, True)
viewportWindow.set_camera_target(cameraPath, 0, 0, 0, True)

await omni.kit.app.get_app().next_update_async()

viewport_ldr_rp = viewportWindow.get_drawable_ldr_resource()
renderer.capture_next_frame_rp_resource_callback(renderImageIntoMemeryCallback, viewport_ldr_rp)

return {"status": "success"}

small update:

when calling next_update_async several times (12 times in my case) it works… but that could not be the correct solution :-)

Hi @WendyGram,

could you help with this? This topic is realy important for us…

Thank you very much

Carl

Hey @c.bickmeier. Looking into this for you.

@c.bickmeier Have you taken a look at:

  • omni.kit.thumbnails.usd
  • omni.kit.capture

These are some good examples for capturing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.