"""Contact sheet: one row per take, n frames across it. py -I sheet.py rolls out.jpg [per_row] [take,take,...]""" import os, sys import cv2 import numpy as np root, out = sys.argv[1], sys.argv[2] n = int(sys.argv[3]) if len(sys.argv) > 3 else 3 only = sys.argv[4].split(",") if len(sys.argv) > 4 else None cell = (480, 270) if n <= 3 else (360, 202) rows = [] takes = sorted(t for t in os.listdir(root) if os.path.isdir(os.path.join(root, t))) if only: takes = [t for t in takes if any(t == o or t.startswith(o) for o in only)] for t in takes: files = sorted(f for f in os.listdir(os.path.join(root, t)) if f.endswith(".jpg")) if not files: continue pick = [files[int(i * (len(files) - 1) / max(1, n - 1))] for i in range(n)] row = [] for j, f in enumerate(pick): im = cv2.resize(cv2.imread(os.path.join(root, t, f)), cell, interpolation=cv2.INTER_AREA) if j == 0: cv2.putText(im, t, (8, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 0), 3, cv2.LINE_AA) cv2.putText(im, t, (8, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1, cv2.LINE_AA) row.append(im) rows.append(np.hstack(row)) cv2.imwrite(out, np.vstack(rows), [cv2.IMWRITE_JPEG_QUALITY, 88]) print(len(rows), "takes")