Skip to content

Commit

Permalink
fix cam pose matrix, add intrinsic matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
cremebrule committed Sep 11, 2023
1 parent 5d2086c commit 54eadc7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions omnigibson/sensors/vision_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,29 @@ def focal_length(self, length):
"""
self.set_attribute("focalLength", length)

@property
def intrinsic_matrix(self):
"""
Returns:
n-array: (3, 3) camera intrinsic matrix. Transforming point p (x,y,z) in the camera frame via K * p will
produce p' (x', y', w) - the point in the image plane. To get pixel coordiantes, divide x' and y' by w
"""
params = get_camera_params(viewport=self._viewport.viewport_api)
h, w = self.image_height, self.image_width
horizontal_fov = params["fov"]
vertical_fov = horizontal_fov * h / w

f_x = (w / 2.0) / np.tan(horizontal_fov / 2.0)
f_y = (h / 2.0) / np.tan(vertical_fov / 2.0)

K = np.array([
[f_x, 0.0, w / 2.0],
[0.0, f_y, h / 2.0],
[0.0, 0.0, 1.0]
])

return K

@property
def _obs_space_mapping(self):
# Generate the complex space types for special modalities:
Expand Down
2 changes: 1 addition & 1 deletion omnigibson/utils/usd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_camera_params(viewport):
view_proj_mat = helpers.get_view_proj_mat(view_params)

return {
"pose": np.array(prim_tf),
"pose": np.array(prim_tf).T,
"fov": fov,
"focal_length": view_params["focal_length"],
"horizontal_aperture": view_params["horizontal_aperture"],
Expand Down

0 comments on commit 54eadc7

Please sign in to comment.