import numpy as np def get_camera_dir(idx): img_scale = self.body['test'].get('img_scale', 1.0) view_setting = self.body['test'].get('view_setting', 'free') if view_setting == 'camera': # training view setting cam_id = self.body['test']['render_view_idx'] intr = self.dataset.intr_mats[cam_id].copy() intr[:2] *= img_scale extr = self.dataset.extr_mats[cam_id].copy() img_h, img_w = int(self.dataset.img_heights[cam_id] * img_scale), int(self.dataset.img_widths[cam_id] * img_scale) elif view_setting.startswith('free'): # free view setting # frame_num_per_circle = 360 # print(self.opt['test'].get('global_orient', False)) frame_num_per_circle = 360 rot_Y = (idx % frame_num_per_circle) / float(frame_num_per_circle) * 2 * np.pi extr = visualize_util.calc_free_mv(object_center, tar_pos = np.array([0, 0, 2.5]), rot_Y = rot_Y, rot_X = 0.3 if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) extr_list.append(extr) intr_list.append(intr) img_h_list.append(img_h) img_w_list.append(img_w) elif view_setting.startswith('degree120'): print('we render 120 degree') # +- 60 degree frame_per_cycle = 480 max_degree = 60 frame_half_cycle = frame_per_cycle // 2 if idx%frame_per_cycle < frame_per_cycle/2: rot_Y = -max_degree + (2 * max_degree / frame_half_cycle) * (idx%frame_half_cycle) # rot_Y = (idx % frame_per_60) / float(frame_per_60) * 2 * np.pi else: rot_Y = max_degree - (2 * max_degree / frame_half_cycle) * (idx%frame_half_cycle) # to radian rot_Y = rot_Y * np.pi / 180 if rot_Y<0: rot_Y = rot_Y + 2 * np.pi # print('rot_Y: ', rot_Y) extr = visualize_util.calc_free_mv(object_center, tar_pos = np.array([0, 0, 2.5]), rot_Y = rot_Y, rot_X = 0.3 if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) extr_list.append(extr) intr_list.append(intr) img_h_list.append(img_h) img_w_list.append(img_w) elif view_setting.startswith('degree90'): print('we render 90 degree') # +- 60 degree frame_per_cycle = 360 max_degree = 45 frame_half_cycle = frame_per_cycle // 2 if idx%frame_per_cycle < frame_per_cycle/2: rot_Y = -max_degree + (2 * max_degree / frame_half_cycle) * (idx%frame_half_cycle) # rot_Y = (idx % frame_per_60) / float(frame_per_60) * 2 * np.pi else: rot_Y = max_degree - (2 * max_degree / frame_half_cycle) * (idx%frame_half_cycle) # to radian rot_Y = rot_Y * np.pi / 180 if rot_Y<0: rot_Y = rot_Y + 2 * np.pi # print('rot_Y: ', rot_Y) extr = visualize_util.calc_free_mv(object_center, tar_pos = np.array([0, 0, 2.5]), rot_Y = rot_Y, rot_X = 0.3 if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) extr_list.append(extr) intr_list.append(intr) img_h_list.append(img_h) img_w_list.append(img_w) elif view_setting.startswith('front'): # front view setting extr = visualize_util.calc_free_mv(object_center, tar_pos = np.array([0, 0, 2.5]), rot_Y = 0., rot_X = 0.3 if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) extr_list.append(extr) intr_list.append(intr) img_h_list.append(img_h) img_w_list.append(img_w) # print('extr: ', extr) # print('intr: ', intr) # print('img_h: ', img_h) # print('img_w: ', img_w) # exit() elif view_setting.startswith('back'): # back view setting extr = visualize_util.calc_free_mv(object_center, tar_pos = np.array([0, 0, 2.5]), rot_Y = np.pi, rot_X = 0.5 * np.pi / 4. if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) elif view_setting.startswith('moving'): # moving camera setting extr = visualize_util.calc_free_mv(object_center, # tar_pos = np.array([0, 0, 3.0]), # rot_Y = -0.3, tar_pos = np.array([0, 0, 2.5]), rot_Y = 0., rot_X = 0.3 if view_setting.endswith('bird') else 0., global_orient = global_orient if self.body['test'].get('global_orient', False) else None) intr = np.array([[1100, 0, 512], [0, 1100, 512], [0, 0, 1]], np.float32) intr[:2] *= img_scale img_h = int(1024 * img_scale) img_w = int(1024 * img_scale) elif view_setting.startswith('cano'): cano_center = self.dataset.cano_bounds.mean(0) extr = np.identity(4, np.float32) extr[:3, 3] = -cano_center rot_x = np.identity(4, np.float32) rot_x[:3, :3] = cv.Rodrigues(np.array([np.pi, 0, 0], np.float32))[0] extr = rot_x @ extr f_len = 5000 extr[2, 3] += f_len / 512 intr = np.array([[f_len, 0, 512], [0, f_len, 512], [0, 0, 1]], np.float32) # item = self.dataset.getitem(idx, # training = False, # extr = extr, # intr = intr, # img_w = 1024, # img_h = 1024) img_w, img_h = 1024, 1024 # item['live_smpl_v'] = item['cano_smpl_v'] # item['cano2live_jnt_mats'] = torch.eye(4, dtype = torch.float32)[None].expand(item['cano2live_jnt_mats'].shape[0], -1, -1) # item['live_bounds'] = item['cano_bounds'] else: raise ValueError('Invalid view setting for animation!')