InstantSplat / utils /gradio_utils.py
kairunwen's picture
add code
35e2073
raw
history blame
1.72 kB
import os
import numpy as np
import imageio
from utils.camera_utils import generate_interpolated_path
def save_interpolate_pose(model_path, iter, n_views):
org_pose = np.load(model_path + f"pose/pose_{iter}.npy")
# visualizer(org_pose, ["green" for _ in org_pose], model_path + "pose/poses_optimized.png")
n_interp = int(10 * 30 / n_views) # 10second, fps=30
all_inter_pose = []
for i in range(n_views-1):
tmp_inter_pose = generate_interpolated_path(poses=org_pose[i:i+2], n_interp=n_interp)
all_inter_pose.append(tmp_inter_pose)
all_inter_pose = np.array(all_inter_pose).reshape(-1, 3, 4)
inter_pose_list = []
for p in all_inter_pose:
tmp_view = np.eye(4)
tmp_view[:3, :3] = p[:3, :3]
tmp_view[:3, 3] = p[:3, 3]
inter_pose_list.append(tmp_view)
inter_pose = np.stack(inter_pose_list, 0)
# visualizer(inter_pose, ["blue" for _ in inter_pose], model_path + "pose/poses_interpolated.png")
np.save(model_path + "pose/pose_interpolated.npy", inter_pose)
def images_to_video(image_folder, output_video_path, fps=30):
"""
Convert images in a folder to a video.
Args:
- image_folder (str): The path to the folder containing the images.
- output_video_path (str): The path where the output video will be saved.
- fps (int): Frames per second for the output video.
"""
images = []
for filename in sorted(os.listdir(image_folder)):
if filename.endswith(('.png', '.jpg', '.jpeg')):
image_path = os.path.join(image_folder, filename)
image = imageio.imread(image_path)
images.append(image)
imageio.mimwrite(output_video_path, images, fps=fps)