#!/usr/bin/env python """Draws the conceptual diagram for the README: independent camera + LiDAR decalibration relative to the vehicle/IMU rig frame (top-down schematic). Usage: python scripts/make_concept_diagram.py --output docs/assets/concept_diagram.png """ from __future__ import annotations import argparse from pathlib import Path import matplotlib.patches as mpatches import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import FancyArrowPatch, FancyBboxPatch, Rectangle GT_COLOR = "#2E7D32" # green CAM_MISCAL_COLOR = "#E65100" # orange LIDAR_MISCAL_COLOR = "#C62828" # red RIG_COLOR = "#212121" BG_COLOR = "#FAFAFA" def _heading_arrow(ax, center, heading_deg, color, length=0.7, alpha=1.0, lw=2.2): """Draws a thin arrow from `center` pointing in `heading_deg`, representing a sensor's facing direction.""" heading = np.deg2rad(heading_deg) tip = center + length * np.array([np.cos(heading), np.sin(heading)]) ax.annotate( "", xy=tuple(tip), xytext=tuple(center), arrowprops=dict(arrowstyle="-|>", color=color, lw=lw, alpha=alpha, mutation_scale=14), zorder=7, ) def draw_diagram(output_path: Path) -> None: fig, ax = plt.subplots(figsize=(7.2, 7.6), facecolor=BG_COLOR) ax.set_facecolor(BG_COLOR) # --- vehicle body (top-down), rear at y=-1.6, front bumper at y=2.4 --- car_w, car_l = 3.2, 4.0 car_y0 = -1.6 car = FancyBboxPatch( (-car_w / 2, car_y0), car_w, car_l, boxstyle="round,pad=0,rounding_size=0.85", facecolor="#D6D6D6", edgecolor="#9E9E9E", linewidth=1.5, zorder=1, ) ax.add_patch(car) ax.add_patch(Rectangle((-car_w / 2 + 0.3, 0.3), car_w - 0.6, 1.3, facecolor="#BFD9F2", edgecolor="none", alpha=0.6, zorder=2)) ax.annotate("", xy=(0, car_y0 + car_l + 0.7), xytext=(0, car_y0 + car_l - 0.1), arrowprops=dict(arrowstyle="-|>", color="#616161", lw=2), zorder=2) ax.text(0, car_y0 + car_l + 0.85, "front of vehicle", ha="center", va="bottom", fontsize=10, color="#616161") # --- rig / IMU origin (rear axle) --- rig_origin = np.array([0.0, -1.0]) ax.scatter(*rig_origin, s=90, color=RIG_COLOR, zorder=5) ax.annotate("", xy=(rig_origin[0] + 0.7, rig_origin[1]), xytext=tuple(rig_origin), arrowprops=dict(arrowstyle="-|>", color=RIG_COLOR, lw=1.6), zorder=5) ax.annotate("", xy=(rig_origin[0], rig_origin[1] + 0.7), xytext=tuple(rig_origin), arrowprops=dict(arrowstyle="-|>", color=RIG_COLOR, lw=1.6), zorder=5) ax.text(rig_origin[0] + 0.85, rig_origin[1] - 0.08, "x", fontsize=11, color=RIG_COLOR, va="center") ax.text(rig_origin[0] - 0.22, rig_origin[1] + 0.8, "y", fontsize=11, color=RIG_COLOR, ha="center") ax.text(rig_origin[0] + 0.2, rig_origin[1] - 0.42, "vehicle / IMU rig frame", fontsize=10, color=RIG_COLOR, ha="left", fontweight="bold") # --- LiDAR: ground truth (roof, center) vs miscalibrated --- lidar_gt = np.array([0.0, 0.4]) lidar_miscal = np.array([-0.95, 0.95]) ax.scatter(*lidar_gt, s=240, marker="o", facecolor="white", edgecolor=GT_COLOR, linewidth=2.5, zorder=6) _heading_arrow(ax, lidar_gt, heading_deg=90, color=GT_COLOR, length=0.55) ax.scatter(*lidar_miscal, s=240, marker="o", facecolor="white", edgecolor=LIDAR_MISCAL_COLOR, linewidth=2.5, linestyle="--", zorder=6) _heading_arrow(ax, lidar_miscal, heading_deg=145, color=LIDAR_MISCAL_COLOR, length=0.55, alpha=0.9) arrow = FancyArrowPatch(tuple(lidar_gt), tuple(lidar_miscal), arrowstyle="-|>", mutation_scale=16, color=LIDAR_MISCAL_COLOR, lw=1.8, linestyle=":", connectionstyle="arc3,rad=0.3", zorder=5) ax.add_patch(arrow) ax.text(-1.75, 1.15, r"$\Delta T_{\mathrm{lidar}}$", fontsize=13, color=LIDAR_MISCAL_COLOR, ha="center", fontweight="bold") ax.text(0.32, 0.4, "LiDAR (true)", fontsize=9.5, color=GT_COLOR, ha="left", va="center") # --- Camera: ground truth (front bumper) vs miscalibrated --- cam_gt = np.array([0.0, 2.1]) cam_miscal = np.array([1.05, 1.55]) ax.scatter(*cam_gt, s=200, marker="s", facecolor="white", edgecolor=GT_COLOR, linewidth=2.5, zorder=6) _heading_arrow(ax, cam_gt, heading_deg=90, color=GT_COLOR, length=0.55) ax.scatter(*cam_miscal, s=200, marker="s", facecolor="white", edgecolor=CAM_MISCAL_COLOR, linewidth=2.5, linestyle="--", zorder=6) _heading_arrow(ax, cam_miscal, heading_deg=45, color=CAM_MISCAL_COLOR, length=0.55, alpha=0.9) arrow = FancyArrowPatch(tuple(cam_gt), tuple(cam_miscal), arrowstyle="-|>", mutation_scale=16, color=CAM_MISCAL_COLOR, lw=1.8, linestyle=":", connectionstyle="arc3,rad=-0.3", zorder=5) ax.add_patch(arrow) ax.text(1.85, 1.75, r"$\Delta T_{\mathrm{cam}}$", fontsize=13, color=CAM_MISCAL_COLOR, ha="center", fontweight="bold") ax.text(0.32, 2.1, "Camera (true)", fontsize=9.5, color=GT_COLOR, ha="left", va="center") # --- legend --- legend_handles = [ mpatches.Patch(facecolor="none", edgecolor=GT_COLOR, linewidth=2.5, label="Ground-truth mounting pose"), mpatches.Patch(facecolor="none", edgecolor=CAM_MISCAL_COLOR, linewidth=2.5, linestyle="--", label=r"Camera perturbed by $\Delta T_{\mathrm{cam}}$"), mpatches.Patch(facecolor="none", edgecolor=LIDAR_MISCAL_COLOR, linewidth=2.5, linestyle="--", label=r"LiDAR perturbed by $\Delta T_{\mathrm{lidar}}$"), ] ax.legend(handles=legend_handles, loc="upper center", bbox_to_anchor=(0.5, 0.08), ncol=1, frameon=False, fontsize=10) ax.set_title( "KITTI-C2L decalibration: camera and LiDAR are perturbed\nindependently relative to the vehicle rig frame", fontsize=13, fontweight="bold", pad=10, ) ax.set_xlim(-2.6, 2.6) ax.set_ylim(-2.6, 3.6) ax.set_aspect("equal") ax.axis("off") fig.tight_layout() output_path.parent.mkdir(parents=True, exist_ok=True) fig.savefig(output_path, dpi=200, facecolor=BG_COLOR) plt.close(fig) print(f"wrote {output_path}") def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--output", default="docs/assets/concept_diagram.png") args = parser.parse_args() draw_diagram(Path(args.output)) return 0 if __name__ == "__main__": raise SystemExit(main())