Change intrinsic camera parameters

Hey, basic question but yet I havent found a solution for that in the examples or in this forum. How can I change the intrinsic parameters (fox, cx cy, fx, fy) of my camera in a python script? I would like to simulate different kinds of sensors…

vpi = omni.kit.viewport.get_viewport_interface()
vpi.get_viewport_window().set_active_camera(str(self.camera.GetPath()))

I use these two lines to set the active camera, but I have no clue how I can change the intrinsic camera parameters… I know that I can read them with the synthetic data extension, but this is not what I want here…

Thanks a lot!

Hi @fastblizzard

You can read and change the parameter of a camera prim by inspecting its attributes as shown in the next code (just change the prim_path to your camera path):

import omni

stage = omni.usd.get_context().get_stage()
prim_path = "/Camera"

prim= stage.GetPrimAtPath(prim_path)
focal_length = prim.GetAttribute("focalLength")

# get value
print("focal length:", focal_length.Get())

# set value
focal_length.Set(10.0)
1 Like

thanks a lot, I will try it out.

@toni.sm
Thanks , it works. I am trying to compute the intrinsic camera matrix [3x3] for later processing. But it seems that the view_projection_matrix returned from the synthecif_helper is not what I am looking for. I am actually wondering what it is… The documentation is updated (thank you all! ), but this is still a bit mysterious.
Thanks !

Have you found the intrinsic camera matrix [3x4] including fx fy cx cy?

@xuzy70 A few snippets which might be useful to compute camera intrinsics

import omni
import math
stage = omni.usd.get_context().get_stage()
viewport = omni.kit.viewport.get_viewport_interface()
# acquire the viewport window
viewport_handle = viewport.get_instance("Viewport")
viewport_window = viewport.get_viewport_window(viewport_handle)
width = 1280
height = 720
aspect_ratio = width / height
# get camera prim attached to viewport
camera = stage.GetPrimAtPath(viewport_window.get_active_camera())
focal_length = camera.GetAttribute("focalLength").Get()
horiz_aperture = camera.GetAttribute("horizontalAperture").Get()
# Pixels are square so we can do:
vert_aperture = height/width * horiz_aperture
near, far = camera.GetAttribute("clippingRange").Get()
fov = 2 * math.atan(horiz_aperture / (2 * focal_length))

# compute focal point and center
focal_x = height * focal_length / vert_aperture
focal_y = width * focal_length / horiz_aperture
center_x = height * 0.5
center_y = width * 0.5

Note that focal/center _x/_y should be flipped depending on your image conventions

2 Likes