forked from andrew/feedmill-recounter
fix: degrade to dynamic on an unreadable zone calibration
This commit is contained in:
1 parent
d53e9426fb
commit
f8f3049531
4 files changed
+34
-3
No files matched your search
+2
-1
@@ -49,7 +49,8 @@ version tags are cut in this repo — `main` is the release line).
|
||||
explicit `zone_mode` (e.g. `POST /api/analyze`) — the count line no longer
|
||||
follows the truck; the web form already sent `zone_mode=fixed`.
|
||||
`"dynamic"` stays available as an explicit opt-in, and a deployment with no
|
||||
calibration file on disk falls back to `"dynamic"` automatically.
|
||||
usable calibration on disk (missing or corrupt `zones.json`) falls back to
|
||||
`"dynamic"` automatically.
|
||||
- **Analysis frame pinned to 1280x720, model input pinned to 640x640**
|
||||
(`fcdfed1`): every decoded frame is resized to 1280x720 before detection
|
||||
(FCP `predict.py:826`) and both models run with an explicit `imgsz=640`
|
||||
|
||||
@@ -140,7 +140,7 @@ Models without "truck" class: `best`, `karung-dimuat`, `yolo11n-bbox` (auto-load
|
||||
The web upload form offers three zone modes:
|
||||
|
||||
- **Auto-detect Truck**: truck detector finds the main truck each ~15 frames, ROI + counting line follow it (EMA-smoothed with 10px deadband, sticky truck pick)
|
||||
- **Fixed Zone** (default): static zone from `zones.json` presets, scaled from reference resolution to video resolution; never moves; presets editable via `tools/calibrate_zone.py`
|
||||
- **Fixed Zone** (default): static zone from `zones.json` presets, built in the fixed 1280×720 analysis frame; never moves; presets editable via `tools/calibrate_zone.py`
|
||||
- **Auto-detect + Freeze**: auto-detects the truck then locks the ROI permanently after 3 consecutive detections (geometry fixed, truck-presence still tracked for batch state machine)
|
||||
|
||||
In multi-model runs, model #1 (primary, alphabetical order) is tracked every frame; supplementary models run every 5th frame; detections from supplementary models get synthetic track IDs so counts and overlays stay stable.
|
||||
@@ -153,9 +153,17 @@ def _resolve_zone(zone_mode: str, zone_preset: str) -> tuple[str, TruckROI | Non
|
||||
if zone_mode != "fixed":
|
||||
return zone_mode, None, zone_preset
|
||||
zone = None
|
||||
reason = "no zone file"
|
||||
if os.path.isfile(ZONES_PATH):
|
||||
zone = get_active_zone(ZONES_PATH, zone_preset or None)
|
||||
try:
|
||||
zone = get_active_zone(ZONES_PATH, zone_preset or None)
|
||||
if zone is None:
|
||||
reason = "no active preset"
|
||||
except (OSError, ValueError, TypeError, AttributeError) as exc:
|
||||
# A corrupt/unreadable calibration must degrade to dynamic, not 500.
|
||||
reason = f"unreadable calibration ({exc})"
|
||||
if zone is None:
|
||||
print(f"[ZONE] {reason} at {ZONES_PATH} — falling back to dynamic")
|
||||
return "dynamic", None, zone_preset
|
||||
return "fixed", _static_roi(zone), zone_preset or "default"
|
||||
|
||||
|
||||
@@ -450,3 +450,25 @@ def test_analyze_falls_back_to_dynamic_without_zone_file(client, buf, analyze_en
|
||||
assert job.fixed_zone is None
|
||||
_wait_job_done(job)
|
||||
|
||||
|
||||
def test_analyze_falls_back_to_dynamic_with_corrupt_zone_file(client, buf, analyze_env, tmp_path, monkeypatch, capsys):
|
||||
"""A corrupt zones.json degrades to dynamic instead of 500."""
|
||||
app_module = analyze_env
|
||||
zones = tmp_path / "zones.json"
|
||||
zones.write_text('{"presets": {"default": ') # truncated JSON
|
||||
monkeypatch.setattr(app_module, "ZONES_PATH", str(zones))
|
||||
|
||||
resp = client.post(
|
||||
"/api/analyze",
|
||||
data={"fcp_mode": "C", "video": (buf, "clip.mp4")},
|
||||
content_type="multipart/form-data",
|
||||
)
|
||||
assert resp.status_code == 202
|
||||
job = app_module.job_queue.get_job(resp.get_json()["job_id"])
|
||||
assert job.zone_mode == "dynamic"
|
||||
assert job.fixed_zone is None
|
||||
_wait_job_done(job)
|
||||
|
||||
out = capsys.readouterr().out
|
||||
assert "unreadable calibration" in out
|
||||
assert "dynamic" in out
|
||||
Reference in new issue
Block a user