|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from scene.cameras import Camera |
|
import numpy as np |
|
from utils.general_utils import PILtoTorch |
|
from utils.graphics_utils import fov2focal |
|
|
|
WARNED = False |
|
|
|
def loadCam(args, id, cam_info, resolution_scale): |
|
|
|
image_rgb = PILtoTorch(cam_info.image).type("torch.ByteTensor") |
|
background = PILtoTorch(cam_info.background)[:3, ...].type("torch.ByteTensor") |
|
|
|
gt_image = image_rgb[:3, ...] |
|
loaded_mask = None |
|
|
|
return Camera(colmap_id=cam_info.uid, R=cam_info.R, T=cam_info.T, |
|
FoVx=cam_info.FovX, FoVy=cam_info.FovY, |
|
image=gt_image, gt_alpha_mask=loaded_mask, background=background, talking_dict=cam_info.talking_dict, |
|
image_name=cam_info.image_name, uid=id, data_device=args.data_device) |
|
|
|
def cameraList_from_camInfos(cam_infos, resolution_scale, args): |
|
camera_list = [] |
|
|
|
for id, c in enumerate(cam_infos): |
|
camera_list.append(loadCam(args, id, c, resolution_scale)) |
|
|
|
return camera_list |
|
|
|
def camera_to_JSON(id, camera : Camera): |
|
Rt = np.zeros((4, 4)) |
|
Rt[:3, :3] = camera.R.transpose() |
|
Rt[:3, 3] = camera.T |
|
Rt[3, 3] = 1.0 |
|
|
|
W2C = np.linalg.inv(Rt) |
|
pos = W2C[:3, 3] |
|
rot = W2C[:3, :3] |
|
serializable_array_2d = [x.tolist() for x in rot] |
|
camera_entry = { |
|
'id' : id, |
|
'img_name' : camera.image_name, |
|
'width' : camera.width, |
|
'height' : camera.height, |
|
'position': pos.tolist(), |
|
'rotation': serializable_array_2d, |
|
'fy' : fov2focal(camera.FovY, camera.height), |
|
'fx' : fov2focal(camera.FovX, camera.width) |
|
} |
|
return camera_entry |
|
|