Extend pick_barrier coarse window to 10 min by default

Some videos have late barrier opening (e.g. 5:46) that fell outside
the original 5-min search window. Default coarse-grid span is now
600 s (10 s spacing in the 60-thumb grid). Add --coarse-span CLI flag
to widen further if needed; auto-suggest scans the same 10-min window.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Giorgio Gilestro 2026-05-01 12:08:23 +01:00
parent e8c7f23d4d
commit 125f187187

View file

@ -44,7 +44,7 @@ import pandas as pd
from config import DATA_METADATA, INVENTORY_CSV, VIDEO_INFO_TSV
from detect_barrier_opening import (
SEARCH_END_S, STEP_S, WINDOW_S,
STEP_S, WINDOW_S,
per_frame_distance, sliding_mean,
)
@ -58,8 +58,9 @@ DB_NAME_RE = re.compile(
GRID_ROWS, GRID_COLS = 6, 10
N_THUMBS = GRID_ROWS * GRID_COLS # 60
COARSE_SPAN_S = SEARCH_END_S # 0..300s, ~5s spacing
DEFAULT_COARSE_SPAN_S = 600.0 # 0..10 min, ~10 s spacing — covers late-opening videos
FINE_SPAN_S = 12.0 # ±6 s around coarse pick → ~0.2 s spacing
AUTO_SEARCH_END_S = 600.0 # how far the auto-detector scans for its suggestion
def auto_suggest(db_path: Path) -> float | None:
@ -75,7 +76,7 @@ def auto_suggest(db_path: Path) -> float | None:
except Exception:
continue
dist = per_frame_distance(df)
smean = sliding_mean(dist, WINDOW_S, STEP_S, SEARCH_END_S)
smean = sliding_mean(dist, WINDOW_S, STEP_S, AUTO_SEARCH_END_S)
pad = max(1, int(WINDOW_S / STEP_S))
if len(smean) < 2 * pad + 1:
continue
@ -218,17 +219,19 @@ def pick_for_video(
machine_name: str,
session_date: str,
session_time: str,
coarse_span_s: float = DEFAULT_COARSE_SPAN_S,
) -> dict | str | None:
"""Run the two-stage thumbnail picker. Return dict, 'skip', or 'quit'."""
auto_t = auto_suggest(db_path) if db_path else None
print(f" auto-suggest: {f'{auto_t:.1f}s' if auto_t else '(none)'}")
# Stage 1: coarse grid centred on auto-suggest (or 150 s default).
coarse_center = auto_t if auto_t is not None else COARSE_SPAN_S / 2
title_coarse = f"COARSE {machine_name} {session_date} {session_time} · spanning 5 min"
# Stage 1: coarse grid centred on auto-suggest, or middle of span.
coarse_center = auto_t if auto_t is not None else coarse_span_s / 2
title_coarse = (f"COARSE {machine_name} {session_date} {session_time} "
f"· spanning {coarse_span_s/60:.0f} min")
while True:
coarse_t, action = show_thumbnail_grid(
video_path, coarse_center, COARSE_SPAN_S, title_coarse
video_path, coarse_center, coarse_span_s, title_coarse
)
if action == "skip":
return "skip"
@ -294,6 +297,8 @@ def main() -> None:
help="only process the first N videos")
parser.add_argument("--db", type=Path, default=None,
help="annotate this specific tracking DB only")
parser.add_argument("--coarse-span", type=float, default=DEFAULT_COARSE_SPAN_S,
help=f"coarse-grid time span in seconds (default {DEFAULT_COARSE_SPAN_S:.0f})")
args = parser.parse_args()
OUT_CSV.parent.mkdir(parents=True, exist_ok=True)
@ -357,7 +362,8 @@ def main() -> None:
prefix = f"[{i}/{len(queue)}] {machine_name} {session_date} {session_time}"
print(f"\n{prefix}")
result = pick_for_video(video, db, machine_name, session_date, session_time)
result = pick_for_video(video, db, machine_name, session_date, session_time,
coarse_span_s=args.coarse_span)
if result is None or result == "skip":
skipped += 1