File size: 6,322 Bytes
db613b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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())