MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / Camera

Class Camera

scene/cameras.py:19–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17from copy import deepcopy
18
19class Camera:
20 def __init__(self, colmap_id, R, T, FoVx, FoVy, image, gt_alpha_mask,
21 image_name, uid,
22 trans=np.array([0.0, 0.0, 0.0]), scale=1.0, data_device = "cuda", timestamp = 0.0,
23 cx=-1, cy=-1, fl_x=-1, fl_y=-1, depth=None, resolution=None, image_path=None, meta_only=False,
24 ):
25
26 self.uid = uid
27 self.colmap_id = colmap_id
28 self.R = R
29 self.T = T
30 self.FoVx = FoVx
31 self.FoVy = FoVy
32 self.image_name = image_name
33 self.cx = cx
34 self.cy = cy
35 self.fl_x = fl_x
36 self.fl_y = fl_y
37 self.resolution = resolution
38 self.image_path = image_path
39 self.image = image
40 self.gt_alpha_mask = gt_alpha_mask
41 self.meta_only = meta_only
42
43 try:
44 self.data_device = torch.device(data_device)
45 except Exception as e:
46 print(e)
47 print(f"[Warning] Custom device {data_device} failed, fallback to default cuda device")
48 self.data_device = torch.device("cuda")
49
50 self.image_width = resolution[0]
51 self.image_height = resolution[1]
52
53 if not self.meta_only:
54 if gt_alpha_mask is not None:
55 self.image *= gt_alpha_mask.to(self.image.device)
56 else:
57 self.image *= torch.ones((1, self.image_height, self.image_width), device=self.image.device)
58
59 self.zfar = 100.0
60 self.znear = 0.01
61
62 self.trans = trans
63 self.scale = scale
64
65 self.world_view_transform = torch.tensor(getWorld2View2(R, T, trans, scale)).transpose(0, 1)
66 if cx > 0:
67 self.projection_matrix = getProjectionMatrixCenterShift(self.znear, self.zfar, cx, cy, fl_x, fl_y, self.image_width, self.image_height).transpose(0,1)
68 else:
69 self.projection_matrix = getProjectionMatrix(znear=self.znear, zfar=self.zfar, fovX=self.FoVx, fovY=self.FoVy).transpose(0,1)
70 self.full_proj_transform = (self.world_view_transform.unsqueeze(0).bmm(self.projection_matrix.unsqueeze(0))).squeeze(0)
71 self.camera_center = self.world_view_transform.inverse()[3, :3]
72
73 self.timestamp = timestamp
74
75 def get_rays(self):
76 grid = create_meshgrid(self.image_height, self.image_width, normalized_coordinates=False)[0] + 0.5

Callers 3

loadCamFunction · 0.90
read_intrinsics_textFunction · 0.85
read_intrinsics_binaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected