(meshes,
key,
action,
renderer,
savepath,
backgrounds,
cam_pose,
cams=(0.75, 0.75, 0, 0.10),
color=[0.11, 0.53, 0.8])
| 16 | |
| 17 | |
| 18 | def render_video(meshes, |
| 19 | key, |
| 20 | action, |
| 21 | renderer, |
| 22 | savepath, |
| 23 | backgrounds, |
| 24 | cam_pose, |
| 25 | cams=(0.75, 0.75, 0, 0.10), |
| 26 | color=[0.11, 0.53, 0.8]): |
| 27 | # cams=(0.75, 0.75, 0, 0.10), color=[165.0/255,112/255,140/255]): |
| 28 | # center the first frame |
| 29 | if key not in ["real", "ntf", "side"]: |
| 30 | w = int(key) / 6.0 |
| 31 | # purpole to green |
| 32 | # color = w*np.array([0.9,102/255,120/255]) + (1-w)*np.array([0.11, 0.9, 0.11]) |
| 33 | # color = (1-w)*np.array([165.0/255,112/255,140/255]) + w*np.array([0.11, 0.8, 0.11]) |
| 34 | color = (1 - w) * np.array([0.75, 0.13, 0.7]) + w * np.array( |
| 35 | [0.12, 0.7, 0.14]) |
| 36 | |
| 37 | meshes = meshes - meshes[0].mean(axis=0) |
| 38 | imgs = [] |
| 39 | idx = 0 |
| 40 | # for mesh in meshes: |
| 41 | for mesh in tqdm(meshes, desc=f"Visualize {key}, action {action}"): |
| 42 | # file_name = '3dpw_rot-90_glob_trimesh.ply' mesh_filename=file_name, |
| 43 | # prepare background |
| 44 | if len(backgrounds.shape) == 3: |
| 45 | background = backgrounds |
| 46 | cam = cams |
| 47 | elif len(backgrounds.shape) == 4: |
| 48 | background = backgrounds[idx] |
| 49 | cam = cams[idx] |
| 50 | idx += 1 |
| 51 | # prepare cams |
| 52 | img = renderer.render(background, |
| 53 | mesh, |
| 54 | cam, |
| 55 | color=color, |
| 56 | cam_pose=cam_pose) |
| 57 | imgs.append(img) |
| 58 | # show(img) |
| 59 | |
| 60 | imgs = np.array(imgs) |
| 61 | # masks = ~(imgs/255. > 0.96).all(-1) |
| 62 | # coords = np.argwhere(masks.sum(axis=0)) |
| 63 | # y1, x1 = coords.min(axis=0) |
| 64 | # y2, x2 = coords.max(axis=0) |
| 65 | # writer = imageio.get_writer(savepath, fps=30) |
| 66 | # for cimg in imgs[:, y1:y2, x1:x2]: |
| 67 | # writer.append_data(cimg) |
| 68 | # writer.close() |
| 69 | |
| 70 | # from mld.utils.uicap_utils import write_rgba_seqs |
| 71 | # write_rgba_seqs(imgs, savepath) |
| 72 | |
| 73 | writer = imageio.get_writer(savepath, fps=30) |
| 74 | for cimg in imgs: |
| 75 | writer.append_data(cimg) |
no test coverage detected