"""Plot source frames and design counts for StereoGenBench Temporal.""" from collections import Counter import json from pathlib import Path import matplotlib matplotlib.use("Agg") from matplotlib import pyplot as plt import numpy as np HERE = Path(__file__).resolve().parent ROOT = HERE.parent INK = "#292929" plt.rcParams.update({"font.family": "DejaVu Sans", "pdf.fonttype": 42, "text.color": INK}) REAL = [ ("2011_09_26_drive_0019", 38), ("2011_10_03_drive_0042", 82), ("eth3d_sfm_garden", 60), ("eth3d_einstein_2", 56), ("motion_4", 95), ("eth3d_drone", 60), ] SGB = [ ("sgb_dev_downtown_west_000018", 65), ("sgb_dev_japanesestyleroom_000025", 40), ("sgb_train_gangnyeongieoncomplex_000542", 65), ("sgb_train_assetsvilletown_000219", 40), ("sgb_test_deepwaterstation_demomapscalabilityepic_000033", 12), ("sgb_test_stf_testmap_000028", 40), ] UNREAL = [ ("ue2_dev_cuts", 52), ("ue2_dev_continuous", 401), ("ue2_test_continuous", 4), ("ue2_test_cuts", 179), ("ue2_test_foliage_continuous", 99), ("ue2_test_foliage_cuts", 437), ] # Left, top, right and bottom pixel coordinates in the 320 × 192 left render. DETAIL_CROPS = { ("ue2_dev_continuous", 401): (26, 0, 194, 109), ("ue2_test_cuts", 179): (153, 47, 320, 155), ("ue2_test_foliage_cuts", 437): (43, 0, 222, 118), } def registry(name): return json.loads((ROOT / "metadata" / (name + ".json")).read_text(encoding="utf8")) def framestrip(fig, y, heading, examples, records, grouped=False): fig.text(.018, y + .174, heading, fontsize=12, fontweight="medium", va="bottom") gap, group_gap = .0026, .009 if grouped else .0026 width = (.964 - 3 * gap - 2 * group_gap) / 6 x = .018 for column, (source_id, frame_index) in enumerate(examples): src = records[source_id] with np.load(ROOT / (src.get("rgb") or src["media"]), allow_pickle=False) as data: frame = data["left"][frame_index] crop = DETAIL_CROPS.get((source_id, frame_index)) if crop is not None: x0, y0, x1, y1 = crop frame = frame[y0:y1, x0:x1] ax = fig.add_axes([x, y, width, .168]) h, w = frame.shape[:2] ratio = width * fig.get_figwidth() / (.168 * fig.get_figheight()) crop_w, crop_h = min(w, round(h * ratio)), min(h, round(w / ratio)) left, top = (w - crop_w) // 2, (h - crop_h) // 2 ax.imshow(frame[top:top + crop_h, left:left + crop_w], aspect="auto", interpolation="bilinear" if crop else "nearest") ax.axis("off") x += width + (group_gap if column in (1, 3) else gap) def bars(fig, bounds, title, labels, counts): ax = fig.add_axes(bounds) ax.set_title(title, loc="left", fontsize=11, pad=6) x = np.arange(len(labels)) ax.bar(x, counts, width=.51, color="#505558") maximum = max(counts) for i, n in enumerate(counts): ax.text(i, n + maximum * .025, str(n), ha="center", va="bottom", fontsize=9, color=INK) ax.set_ylim(0, maximum * 1.24) ax.set_xticks(x, labels, fontsize=9) ax.tick_params(axis="x", length=0, pad=4, colors=INK) ax.set_yticks([]) for spine in ("left", "top", "right"): ax.spines[spine].set_visible(False) ax.spines["bottom"].set_color("#b3b3b3") ax.spines["bottom"].set_linewidth(.65) def main(): real, synthetic, edits = registry("recordings"), registry("synthetic_sources"), registry("edits") fig = plt.figure(figsize=(14, 8.6), facecolor="white") framestrip(fig,.799,"Real stereo", REAL, real) framestrip(fig,.573,"StereoGenBench trajectories", SGB, synthetic) framestrip(fig,.347,"Unreal long takes", UNREAL, synthetic, grouped=True) for x, name in zip((.177, .500, .823), ("Historic Saloon", "DeepWater Station", "STF foliage")): fig.text(x,.332,name,fontsize=8.7,ha="center",va="center") source_counts = Counter(r["dataset"] for r in real.values()) family_counts = Counter(r["family"] for r in synthetic.values()) counts = [source_counts["KITTI Raw"], source_counts["ETH3D SLAM"], source_counts["Freiburg Stereo Ego-Motion"], family_counts["SGB"], family_counts["Unreal"]] bars(fig,[.03,.064,.325,.178],"Source sequences",["KITTI","ETH3D","Freiburg","SGB","Unreal"],counts) cuts, continuations = [], [] for style in ("sparse","uniform","variable"): group = [e for e in edits.values() if e["layout"] == style] cut_counts = {len(e["cuts"]) for e in group} window_counts = {sum(len(range(23, s["frames"], 20)) for s in e["shots"]) for e in group} assert len(group)==40 and len(cut_counts)==len(window_counts)==1 cuts.append(cut_counts.pop()) continuations.append(window_counts.pop()) labels = ["Sparse","Uniform","Variable"] bars(fig,[.414,.064,.243,.178],"Cuts per real edit",labels,cuts) bars(fig,[.726,.064,.243,.178],"Within-shot continuations",labels,continuations) fig.savefig(HERE / "scene-distribution-and-design.png", dpi=200, metadata={"Software":"Matplotlib"}) fig.savefig(HERE / "scene-distribution-and-design.pdf", metadata={"Title":"StereoGenBench Temporal — source frames and edit design","Author":"StereoGenBench"}) plt.close(fig) if __name__ == "__main__": main()