I am working on creating a synthetic dataset offline and have a question regarding the pose of a camera in the world frame (extrinsic matrix). I created a camera with the replicator (rep.create.camera()) and modify its pose randomly in each frame with a trigger for each frame. How can I access this varying pose per frame?
Thank you very much!
Hi @spiegeln - You can access the pose of a camera in the world frame by using the
omni.usd.get_world_transform_matrix() function from the Omniverse Kit API. This function returns the world transform matrix for a given USD prim, which in your case would be the camera.
Here is a code snippet that demonstrates how to get the world transform matrix of a camera:
# Assuming `camera` is your camera prim
camera_transform_matrix = omni.usd.get_world_transform_matrix(camera)
camera_transform_matrix is a 4x4 matrix that represents the pose of the camera in the world frame. This matrix includes both the rotation and translation of the camera.
If you want to get the translation (position) and rotation separately, you can extract them from the transform matrix like this:
# Get the translation (position) of the camera
camera_position = camera_transform_matrix.ExtractTranslation()
# Get the rotation of the camera
camera_rotation = camera_transform_matrix.ExtractRotation().GetQuaternion()
Remember that the pose of the camera is updated in each frame, so you would need to get the world transform matrix inside your frame trigger to get the updated pose for each frame.