2026-11-05 12:58:39 +01:00
|
|
|
"""Montrer la cause qui se voit dans l'image (véhicule, obstacle, phares) : recadrages côte à côte,
|
|
|
|
|
éclaircis, autour d'une cible marquée d'un cercle rouge.
|
|
|
|
|
|
|
|
|
|
.venv/bin/python .claude/skills/presentation/image-de-la-cause.py data/<STATION> <x> <y> <sortie.png> \
|
|
|
|
|
<AAAAMMJJTHHMMZ>="<légende>" [<AAAAMMJJTHHMMZ>="<légende>" ...] [--demi 350]
|
|
|
|
|
|
|
|
|
|
x, y : pixel de la cible dans l'image entière (« centre du cadre » d'une vignette de vignettes.py).
|
|
|
|
|
Une image par instant, prise dans <dossier>/images/<instant>_*.jpg ; mettre d'abord un instant sans la cause.
|
|
|
|
|
"""
|
|
|
|
|
import glob, os, sys
|
|
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
|
import matplotlib; matplotlib.use("Agg")
|
|
|
|
|
import matplotlib.pyplot as plt, matplotlib.image as mi
|
|
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
2026-11-05 13:04:08 +01:00
|
|
|
nommees = None # --cibles A,B : seulement ces noms écrits (les autres encombrent l'image) ; sans : tous
|
|
|
|
|
if "--cibles" in args:
|
|
|
|
|
i = args.index("--cibles"); nommees = set(args[i + 1].split(",")); del args[i:i + 2]
|
2026-11-05 12:58:39 +01:00
|
|
|
demi = 350
|
|
|
|
|
if "--demi" in args:
|
|
|
|
|
i = args.index("--demi"); demi = int(args[i + 1]); del args[i:i + 2]
|
|
|
|
|
dossier, x, y, sortie, *instants = args
|
|
|
|
|
x, y = int(x), int(y)
|
|
|
|
|
station = dossier.rstrip("/").split("/")[-1]
|
|
|
|
|
|
|
|
|
|
# le nom de chaque cible à sa position dans l'image (x, y de l'export, à la mesure la plus proche du premier instant)
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "agent-tools"))
|
|
|
|
|
from donnees import charger # noqa: E402
|
|
|
|
|
t0 = datetime.strptime(instants[0].partition("=")[0], "%Y%m%dT%H%MZ").replace(tzinfo=timezone.utc)
|
|
|
|
|
positions = {}
|
|
|
|
|
for capteur, ms in charger(dossier).items():
|
2026-11-05 13:04:08 +01:00
|
|
|
if nommees is not None and capteur not in nommees:
|
|
|
|
|
continue
|
2026-11-05 12:58:39 +01:00
|
|
|
proches = [m for m in ms if m.get("x") is not None and m.get("y") is not None and abs(m["t"] - t0) <= timedelta(hours=2)]
|
|
|
|
|
if proches:
|
|
|
|
|
m = min(proches, key=lambda m: abs(m["t"] - t0))
|
|
|
|
|
positions[capteur] = (m["x"], m["y"])
|
|
|
|
|
|
|
|
|
|
fig, axs = plt.subplots(1, len(instants), figsize=(4 * len(instants), 4.3), squeeze=False)
|
|
|
|
|
for ax, inst in zip(axs[0], instants):
|
|
|
|
|
k, _, lab = inst.partition("=")
|
|
|
|
|
img = mi.imread(glob.glob(f"{dossier}/images/{k}_*.jpg")[0]).astype(float)
|
|
|
|
|
y0, x0 = max(y - demi, 0), max(x - demi, 0)
|
|
|
|
|
img = img[y0:y + demi, x0:x + demi]
|
|
|
|
|
img = (img / img.max()) ** 0.45 # éclaircir les ombres, les scènes de nuit sont sombres
|
|
|
|
|
ax.imshow(img, cmap="gray", vmin=0, vmax=1)
|
|
|
|
|
ax.add_patch(plt.Circle((x - x0, y - y0), 28, fill=False, color="red", lw=1.5))
|
|
|
|
|
for capteur, (cx, cy) in positions.items():
|
|
|
|
|
if x0 <= cx < x0 + img.shape[1] and y0 <= cy < y0 + img.shape[0]:
|
2026-11-05 13:04:08 +01:00
|
|
|
ax.text(cx - x0, cy - y0 - 22, capteur, color="yellow", fontsize=8, ha="center", va="bottom",
|
|
|
|
|
bbox={"facecolor": "black", "alpha": 0.5, "pad": 1, "edgecolor": "none"})
|
2026-11-05 12:58:39 +01:00
|
|
|
ax.set_title(lab, fontsize=11); ax.axis("off")
|
|
|
|
|
fig.suptitle("Image éclaircie ; en jaune, le nom des cibles", fontsize=12) # pas de nom de station : il va au client
|
|
|
|
|
fig.tight_layout(); fig.savefig(sortie, dpi=100); print(sortie)
|