import cv2 import os # Parameters name = "cake" folder_path = f'vggsfm_code/examples/{name}/images' # Update with the path to your images video_path = f'{name}_video.mp4' fps = 1 # frames per second # Get all image files from the directory images = [img for img in os.listdir(folder_path)] images.sort() # Sort the images by name # Read the first image to get the size frame = cv2.imread(os.path.join(folder_path, images[0])) height, width, layers = frame.shape # Define the codec and create VideoWriter object fourcc = cv2.VideoWriter_fourcc(*'mp4v') # or 'x264' for codec video = cv2.VideoWriter(video_path, fourcc, fps, (width, height)) # Add images to video for image in images: video.write(cv2.imread(os.path.join(folder_path, image))) # Release the video writer video.release()