74 Commits
Author SHA1 Message Date
jetson 1c26f9f95b feat(zones): use native 1080p zones, sync FCP main, and auto-sync default preset 2026-11-17 12:26:30 +07:00
jetson b9d4bd11b3 feat(counting): align max_step_dy (160) and unload_confirm (1) with FCP main 2026-11-17 11:15:35 +07:00
jetson 3cc0919fb1 feat(pipeline,config): sync detection thresholds, filter order, and multi-model tracking with FCP main 2026-11-17 10:19:54 +07:00
jetson ff55a733d6 feat(counting,zones): align corridor filter and default palet zone with FCP main 2026-11-17 09:39:47 +07:00
jetson 08a0e54065 feat(ui): paste/import zone JSON in the calibrator + surface editor in nav 2026-11-12 16:19:16 +07:00
jetson 3ede31b554 fix(ui): harden the frame API and align the OpenCV calibrator 2026-11-12 14:21:12 +07:00
jetson c34ac85643 feat(ui): interactive zone editor over the analysis frame 2026-11-12 13:52:01 +07:00
jetson 8abc103401 fix(viz): draw the calibrated count band instead of the ROI bounds 2026-11-12 13:17:19 +07:00
jetson 6664cefd18 feat(viz): draw the calibrated counting and truck polygons 2026-11-12 13:06:09 +07:00
jetson 7662890cc5 feat(counting): port FCP's ID-switch, corridor and single-count gates 2026-11-12 11:49:40 +07:00
jetson cd596ca857 fix(zones): close the preset-space and file-handling residuals 2026-11-12 11:20:14 +07:00
jetson a0ea7d9f8e fix(zones): validate the preset space and make zone writes race-free 2026-11-12 11:04:44 +07:00
jetson b00701a936 feat(zones): validate, save and reset zone presets (localhost only) 2026-11-12 10:23:29 +07:00
jetson 7b3c5be2a9 feat(zones): ship FCP's calibrations in the 1280x720 analysis space 2026-11-12 09:40:57 +07:00
jetson 957ab0297d feat(zones): ship FCP's calibration in the 1280x720 analysis space 2026-11-12 09:29:33 +07:00
jetson d3d58ffcde fix: harden the output lifecycle (range requests, temp files, job gate)
Review of the compression branch (ce93c68..d7c1415): one Important and the
cheap real Minors, each with a RED test first.

- app.py: drop the manual Content-Length override - it broke ranged
  requests (206 announcing the full length while sending a slice).
  send_file sets it and the 206/Content-Range itself.
- app.py: the download route serves video extensions only, never the temp
  of an encode in flight.
- src/compress.py: the encode temp is unique per attempt (mkstemp), is
  validated (playable video) and fsynced before it replaces the original;
  a failing os.replace keeps the original and cleans the temp up instead
  of raising into the route. The compressed video keeps the source mode.
- src/compress.py: a stale temp of a killed encode is swept after 2 h
  instead of the 5-day video expiry.
- src/job.py: cancelled and failed jobs are not re-encoded; the job shows
  "Compressing..." while the encode runs.
- ERD.md: the $OUTPUT_DIR/*_compressed.mp4 row is gone.

328 tests pass (was 319).
2026-10-28 15:47:28 +07:00
jetson 5e2a31792f feat: a finished job leaves one compressed video, expired after 5 days
The annotated output was kept uncompressed forever: a 20-minute clip left
a 724 MB file in output/job-*/, and the download route wrote a second
"_compressed.mp4" next to it (both kept).

Now the job compresses its own output when it finishes: the encode goes to
a temp file, is validated, and replaces the source atomically
(os.replace) under the SAME name. One video per job, the client never sees
a "_compressed" file, and the API's output_path stays valid. A failed
encode or a result that still overshoots the cap leaves the original
untouched, so nothing is ever lost.

The job videos are deleted 5 days after the job (scripts/purge_expired_
outputs.py, cron daily 03:17); the job dir, the thumbnail and the sample
frames stay, so the jobs list still renders.
2026-10-28 15:10:05 +07:00
jetson ac2a2350ad fix: dedup across models only - a same-model overlap is a real sack
The merged pipeline ran a same-class IoU-0.5 dedup over ALL detections,
including the primary model's own tracked detections. FCP keeps every
tracked detection - the detector's own NMS already removed the duplicates
inside a model (predict.py:891). Two sacks stacked on the truck overlap by
more than IoU 0.5, so the recounter dropped one of them and lost its
crossing: 54 detections dropped in 400 frames of the test clip, and 3
fewer sacks than FCP on the 20-minute clip (158 vs 161).

The dedup now compares only detections from DIFFERENT models, and the
tracked primary always wins: an extra carries a synthetic track id, and
swapping the id would lose the track's crossing history.
2026-10-28 11:31:03 +07:00
jetson f43044cc9e test: pin the status page's 'Batches closed' label 2026-10-28 10:50:23 +07:00
jetson 59d8c5521d fix: require the truck to be inside the counting area (FCP predict.py:893-902)
The fixed-mode truck signal accepted any truck in the frame; FCP keeps a
truck only when at least 50% of its bbox overlaps the detection polygon
and uses that as the batch's truck signal (predict.py:964).
2026-10-28 10:02:51 +07:00
jetson 1c313d97d8 fix: match FCP's batch lifecycle (count every frame, predict.py:739-745) 2026-10-28 09:57:26 +07:00
jetson 2ca4cb6c3d fix: degrade a broken zone calibration instead of publishing a wrong count
The whole-branch review found three ways a broken zones.json could reach a
published count:

- build_static_roi indexed the truck_area points directly, so a 1-element
  point (IndexError) or an infinite coordinate (OverflowError) escaped the
  app's guard and became a 500. It now reuses _scaled_points and raises
  ValueError, which the guard already handles.
- A missing or short truck_area fell back to an invented heuristic box that
  was still published as a calibrated "fixed" zone. It now degrades to
  dynamic mode instead.
- A degenerate (zero-area) counting polygon was built successfully and
  filtered out every detection, silently publishing zero counts. It is
  now rejected like any other malformed calibration.

Also: the app guard catches IndexError/KeyError/OverflowError, the zone
preset comment no longer claims 1920x1080 coordinates are authored for
1280x720, and two FCP citations are corrected.
2026-10-28 09:45:25 +07:00
jetson 76b902d318 fix: harden the deferred minors from the parity branch review
- zone_config: a count_line without x_start/x_end/y fell back to the
  frame-space ROI bounds and scaled them a second time (400 -> 266).
- app: _resolve_fcp_mode answers JSON 400 when config.yaml is invalid
  instead of raising through to a Flask 500.
- config: the DEFAULTS fallback (missing/empty config.yaml) is validated
  like a real config, and a test pins DEFAULTS to the shipped config.yaml.
- job: add_job downgrades zone_mode "fixed" to "dynamic" when no calibrated
  ROI was supplied — the label now matches what the job counts against.
- counting: correct the FCP citation (src/counting.py:171).
- tests: the analyze_env stub was missing the new result fields, so every
  /upload job ended in FAILED; cover the truncation fields in both job
  endpoints, /upload/reuse zone mode and the broken-config path.
2026-10-28 09:23:14 +07:00
jetson 8a82b8b866 fix: count inside FCP's calibrated count-line x-window (predict.py:701 parity) 2026-10-28 08:41:08 +07:00
jetson 3d9cce2261 feat: flag truncated clips in the job result 2026-10-27 17:28:02 +07:00
jetson fcafc98b17 feat: fail fast on invalid config (FCP src/validation.py parity) 2026-10-27 17:12:40 +07:00
jetson 4697bda488 fix: correct the FCP batch-reset citation and cover the real on_batch_start contract 2026-10-27 17:05:57 +07:00
jetson 5e4add2238 fix: reset per-track counting state at batch start (FCP predict.py:1020 parity) 2026-10-27 16:40:03 +07:00
jetson f54521c1d8 fix: feed the batch seam the counter's own stream and harden the zone polygon builders 2026-10-27 16:27:28 +07:00
jetson fc94189040 fix: drive batch FSM with real crossing events (FCP predict.py:1064 parity) 2026-10-27 15:50:35 +07:00
jetson acc74dcb62 chore: match FCP truck detection cadence (every 5 frames) 2026-10-27 14:55:52 +07:00
jetson 70acfbb90f chore: align stabilizer max_hold with FCP (10 frames) 2026-10-27 14:54:43 +07:00
jetson 3c354c6d81 chore: align detection thresholds with FCP (sack conf 0.30, box area 1000) 2026-10-27 14:53:23 +07:00
jetson fe26410c19 fix: polygon-filter sacks/boxes only and degrade on a malformed calibration 2026-10-27 14:39:42 +07:00
jetson d74ca41e2e feat: filter counts calibrated counting polygon (FCP predict.py:939 parity) 2026-10-27 14:19:26 +07:00
jetson f8f3049531 fix: degrade to dynamic on an unreadable zone calibration 2026-10-27 14:01:24 +07:00
jetson f4e7b5da49 feat: count against calibrated static zone by default (FCP parity) 2026-10-27 13:51:08 +07:00
jetson 354b1b3148 fix: gate unloading on prior loading (FCP src/counting.py:168 parity) 2026-10-27 13:41:34 +07:00
jetson fcdfed1e51 feat: analyse and write at 1280x720 with pinned 640x640 model input (FCP parity) 2026-10-27 12:54:43 +07:00
jetson e963ba0cb4 feat: append source clip name to annotated output filename
Output was a fixed name (merged_annotated.mp4) so every download looked
the same. The source clip name is now appended at the back:
merged_annotated_rekap_2026-10-27.mp4

- src/naming.py: annotated_output_name() + source_stem(); client upload
  name wins, stored file name is the fallback (reuse endpoint), unsafe
  chars replaced, stem capped at 80 chars
- src/job.py: Job.source_stem + add_job(source_stem=...); both output
  paths go through the helper
- app.py: capture the sanitized client filename before the collision
  suffix is added
- cli.py: same helper for the CLI output name

Verified live on .93: POST /api/analyze with 'rekap 2026-10-27.mp4' ->
output/job-e0409b05/merged_annotated_rekap_2026-10-27.mp4, download 200.
2026-10-27 11:26:07 +07:00
jetson 43d1dee8b4 fix: conftest isolates RECOUNTER_API_KEY env for non-auth tests 2026-10-20 15:21:12 +07:00
jetson 371e9593d8 fix: review pass — atomic busy-guard, exact FCP mode filters, docs
- _ANALYZE_LOCK: busy-check through enqueue is atomic; overlapping
  POSTs can no longer both pass the busy guard (one-GPU contract)
- fcp.mode_models now {letter: {stem: engine_classes}} mirroring FCP
  models.modes engines[].classes exactly: B/D use v4-best truck-only
  role (not truck-detector), C filters yolo11n to box only — prevents
  sack double-count and truck-ROI divergence vs FCP batches
- CHANGELOG: document /api/analyze + stem filter fix
- handoff doc: correct precedence (fcp_mode wins over model_stems),
  correct B/D mapping note
- tests: 4 new (mode B/C/D filters, concurrent-submit race) — 195 pass
2026-10-20 11:34:34 +07:00
jetson 540e1b5dcd feat: POST /api/analyze machine endpoint (fcp_mode, 202/409/401)
- /api/analyze: multipart video + fcp_mode letter (A-D) or explicit
  model_stems; 202 {job_id,status_url}; 409 busy guard (one GPU);
  optional X-API-Key auth iff env RECOUNTER_API_KEY set
- config.yaml fcp.mode_models: FCP mode -> recounter stems (mirrors
  platform models.modes; C = current active_mode)
- extract _save_and_queue from /upload (save/transcode/zone/job);
  /upload behavior unchanged
- fix src/job.py: single-model class_filter looked up by filename,
  stem-keyed filters were silently dropped
2026-10-20 10:55:06 +07:00
jetson d09800c634 feat: re-attach orphaned output dirs after restart (deletable from UI)
Jobs are in-memory; output/job-* dirs survived restarts but never
appeared in /jobs, leaving 5.2GB undeletable. JobQueue now registers
stale job-* dirs (>5min old) as COMPLETED ghosts so the existing delete
flow rmtree's them. register_orphans=False opt-out. 177 tests pass (+3).
2026-10-14 11:47:03 +07:00
jetson c2d720e86c fix: scale min_bbox_area from platform 1280x720 reference to frame size
Platform force-resizes frames to 1280x720 before detection, so its
1500/5000 px2 thresholds are authored in that space. Applying them raw
at native 1080p made recounter's effective bar 2.25x weaker — false
divergence in double-check runs. _scaled_min_areas scales by frame area
(1080p: 3375/11250, 720p: unchanged).

Platform's get_min_valid_area perspective gate is dead code (zero call
sites) — deliberately not ported, it would make recounter stricter than
platform. 174 tests pass (+1).
2026-10-13 14:50:32 +07:00
jetson 92fd4cbb38 perf: async writer thread + MJPEG mtime guard
- _AsyncWriter: encode+draw overlap GPU inference (queue maxsize=2
  backpressure, order-preserving, first error surfaced at close, never
  masks original exception) — ~15-35% higher end-to-end FPS
- MJPEG endpoint yields only on preview mtime change instead of re-sending
  the same JPEG every 50ms
- 173 tests pass (+5)
2026-10-13 13:52:15 +07:00
jetson ce604b0574 feat: platform detection parity + download/processing progress bars
Alignment with karung_counter_semarang (recount consistency):
- box_conf 0.35, truck_conf 0.45, suppress_sack_box 0.4
- detector/tracker run at min(sack_conf, box_conf) so 0.35 boxes survive
  inference; _apply_class_confs gates box/box_conf, sack/sack_conf
- _apply_min_area guardrail: sack/box 1500, truck 5000 px2
- 168 tests pass (+5)
2026-10-13 11:30:04 +07:00
jetson 7230e2b3c8 feat: config.yaml as single source of truth for tunables
- config.yaml (root): detection conf, iou thresholds (dedup/suppress/
  synthetic/sticky), roi (ema/deadband/freeze_after), stabilizer, intervals
- src/config.py: deep-merge file over built-in defaults, missing file safe
- pipelines resolve None-sig params from config; CLI --sack-conf/--truck-conf
  override; TruckROITracker sticky_iou param
- 163 tests pass (+8)
2026-10-13 10:02:43 +07:00
jetson 31bfe7cac0 fix: restore accuracy defaults (detect_interval=1, sup_det_interval=5)
Throttled tracking caused ByteTrack ID switches at crossings -> counter
re-initializes new tracks without counting -> lost In counts; sup=10 put
box holds one detection-miss from expiry. Defaults back to every-frame
tracking; params kept for opt-in throttling. 720p/preview gains kept.
2026-09-30 11:08:40 +07:00
jetson 81e6ae6624 feat: live box counts + separate sack/box nets on status page
- live_stats_callback sends box_loading/box_unloading (both pipelines)
- Job live_box_* fields, API JSON exposes them
- status page: 6 live tiles (Sack In/Out/Net, Box In/Out/Net), Box Net
  added to result cards (Jinja + JS), flex-wrap for 6-tile layout
- 155 tests pass (+2)
2026-09-29 16:37:33 +07:00