MCPcopy
hub / github.com/SizheAn/PanoHead / create_cam2world_matrix

Function create_cam2world_matrix

camera_utils.py:118–137  ·  view source on GitHub ↗

Takes in the direction the camera is pointing and the camera origin and returns a cam2world matrix. Works on batches of forward_vectors, origins. Assumes y-axis is up and that there is no camera roll.

(forward_vector, origin)

Source from the content-addressed store, hash-verified

116 return create_cam2world_matrix(forward_vectors, camera_origins)
117
118def create_cam2world_matrix(forward_vector, origin):
119 """
120 Takes in the direction the camera is pointing and the camera origin and returns a cam2world matrix.
121 Works on batches of forward_vectors, origins. Assumes y-axis is up and that there is no camera roll.
122 """
123
124 forward_vector = math_utils.normalize_vecs(forward_vector)
125 up_vector = torch.tensor([0, 1, 0], dtype=torch.float, device=origin.device).expand_as(forward_vector)
126
127 right_vector = -math_utils.normalize_vecs(torch.cross(up_vector, forward_vector, dim=-1))
128 up_vector = math_utils.normalize_vecs(torch.cross(forward_vector, right_vector, dim=-1))
129
130 rotation_matrix = torch.eye(4, device=origin.device).unsqueeze(0).repeat(forward_vector.shape[0], 1, 1)
131 rotation_matrix[:, :3, :3] = torch.stack((right_vector, up_vector, forward_vector), axis=-1)
132
133 translation_matrix = torch.eye(4, device=origin.device).unsqueeze(0).repeat(forward_vector.shape[0], 1, 1)
134 translation_matrix[:, :3, 3] = origin
135 cam2world = (translation_matrix @ rotation_matrix)[:, :, :]
136 assert(cam2world.shape[1:] == (4, 4))
137 return cam2world
138
139
140def FOV_to_intrinsics(fov_degrees, device='cpu'):

Callers 3

sampleMethod · 0.85
sampleMethod · 0.85
sampleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected