MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / render_traj

Method render_traj

examples/simple_trainer_STG.py:1098–1210  ·  view source on GitHub ↗

Entry for trajectory rendering.

(self, step: int, stage: str = "val")

Source from the content-addressed store, hash-verified

1096
1097 @torch.no_grad()
1098 def render_traj(self, step: int, stage: str = "val"):
1099 """Entry for trajectory rendering."""
1100 print("Running trajectory rendering...")
1101
1102 cfg = self.cfg
1103 device = self.device
1104
1105 timestamps = torch.from_numpy(np.array([i/len(self.testset.scene_by_t) for i in range(len(self.testset.scene_by_t))])).float().to(device)
1106 Ks = self.testset[0]["K"].float().to(device)
1107 pixels = self.testset[0]["image"].float().to(device)
1108 num_views, height, width, _ = pixels.shape
1109
1110 camtoworld = self.testset[0]["camtoworld"].float().to(device)
1111
1112 # from c2w to rays
1113 # R = camtoworld[0, :3, :3].cpu().numpy()
1114 # T = torch.inverse(camtoworld)[0, :3, -1].cpu().numpy()
1115 # rays = self.get_rays(R, T, Ks[0,0,0], Ks[0,1,1], width, height).float().to(device)
1116
1117 # get v4, v5 for interp
1118 v4_fr0_global_id = 150
1119 v5_fr0_global_id = 200
1120 v4_c2w = torch.from_numpy(self.trainset.camtoworld[v4_fr0_global_id])
1121 v5_c2w = torch.from_numpy(self.trainset.camtoworld[v5_fr0_global_id])
1122 # v4_c2w = self.trainset[200]["camtoworld"].float().to(device)
1123 # v5_c2w = self.trainset[250]["camtoworld"].float().to(device)
1124
1125 v4_w2c = torch.inverse(v4_c2w)
1126 v5_w2c = torch.inverse(v5_c2w)
1127
1128 def get_c2w(time, v4_w2c, v5_w2c):
1129 R1 = v4_w2c[:3, :3].cpu().numpy()
1130 T1 = v4_w2c[:3, -1].cpu().numpy()
1131 R2 = v5_w2c[:3, :3].cpu().numpy()
1132 T2 = v5_w2c[:3, -1].cpu().numpy()
1133
1134 from helper.STG.posetrace_utils import interpolate_camera_poses2, qvec2rotmat
1135 q,t = interpolate_camera_poses2(R1, T1, R2, T2, time % 1)
1136
1137 R = qvec2rotmat(q) # w2c
1138 T = np.array(t) # w2c
1139
1140 # R_T = R.transpose()
1141
1142 w2c = np.zeros([4,4])
1143 w2c[:3, :3] = R
1144 w2c[:3, -1] = T
1145 w2c[3, 3] = 1
1146
1147 c2w = np.linalg.inv(w2c)
1148
1149 return c2w
1150
1151
1152
1153 video_dir = f"{self.result_dir}/videos"
1154 os.makedirs(video_dir, exist_ok=True)
1155 writer = imageio.get_writer(f"{video_dir}/{stage}_traj_{step}.mp4", fps=30)

Callers

nothing calls this directly

Calls 3

get_raysMethod · 0.95
rasterize_splatsMethod · 0.95
get_c2wFunction · 0.85

Tested by

no test coverage detected