Skip to content

Instantly share code, notes, and snippets.

@agtbaskara
Created June 3, 2022 19:58
Show Gist options
  • Save agtbaskara/0eb46ef31b325240abac94821026fd9e to your computer and use it in GitHub Desktop.
Save agtbaskara/0eb46ef31b325240abac94821026fd9e to your computer and use it in GitHub Desktop.
create synchronized video from dataset
import os
import cv2
import skvideo.io
import numpy as np
import pandas as pd
from tqdm import tqdm
if __name__ == '__main__':
reference_file_path = os.path.join('town07.csv')
df = pd.read_csv(reference_file_path, header=None)
writer = skvideo.io.FFmpegWriter('town07.mp4')
for index, row in tqdm(df.iterrows(), total=df.shape[0]):
frame1 = cv2.imread(os.path.join('clearnight', 'image_rgb', row[0]))
frame2 = cv2.imread(os.path.join('clearnoon', 'image_rgb', row[0]))
frame3 = cv2.imread(os.path.join('cloudysunset', 'image_rgb', row[0]))
frame4 = cv2.imread(os.path.join('hardrainnoon', 'image_rgb', row[0]))
frame_a = np.concatenate((frame1, frame2), axis=1)
frame_b = np.concatenate((frame3, frame4), axis=1)
frame = np.concatenate((frame_a, frame_b), axis=0)
writer.writeFrame(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
writer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment