Spaces:
Running
on
Zero
Running
on
Zero
File size: 712 Bytes
c614b0f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import os
import torch
from pose_utils.camera import get_focalLength_from_fieldOfView
def get_camera_parameters(img_size, fov=60, p_x=None, p_y=None, device=torch.device("cuda")):
"""Given image size, fov and principal point coordinates, return K the camera parameter matrix"""
K = torch.eye(3)
# Get focal length.
focal = get_focalLength_from_fieldOfView(fov=fov, img_size=img_size)
K[0, 0], K[1, 1] = focal, focal
# Set principal point
if p_x is not None and p_y is not None:
K[0, -1], K[1, -1] = p_x * img_size, p_y * img_size
else:
K[0, -1], K[1, -1] = img_size // 2, img_size // 2
# Add batch dimension
K = K.unsqueeze(0).to(device)
return K
|