49 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 0fe59abb4a chore: tidy stale 1920x1080 docstrings and drop dead writer 2026-11-12 15:43:08 +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 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 1b032edfd3 feat: upload models and convert to .engine from web UI 2026-11-04 10:25:27 +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 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 3d9cce2261 feat: flag truncated clips in the job result 2026-10-27 17:28:02 +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 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 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 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 b1dd06e650 fix: remove undefined video_path reference in upload route
Previously, app.py:123-125 tried to use  and
 before  was defined.
This caused NameError and 500 Internal Server Error when users uploaded
new videos and pressed 'start analysis'.

The code block (lines 122-125) was duplicate logic - the later transcoding
at line 138 already handles the height check.

Fixes: # (Issue reference not provided)
2026-10-16 11:47:27 +07:00
jetson 89a265c54c feat: auto-resize uploads to 720p, 720p default output
- src/preview.py: added resize_video_to_max_height() using ffmpeg
  (tries nvenc/v4l2m2m then libx264, atomic overwrite, only if >720p)
- app.py upload: transcode to 720p immediately after save
- app.py upload_reuse: probe first, only transcode if height > 720p
- templates/index.html: 720p output checkbox checked by default
- zones already scale correctly via build_static_roi (reference 1920x1080 -> 720p)
- 177 tests pass
2026-10-15 09:48:23 +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 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
jetson 07289a419a perf: throttle tracker to every 2nd frame, sup interval 10, 720p output option
- detect_interval=2 on both pipelines; stabilizer 10-frame hold bridges
  skipped frames (GPU inference cut ~half during active batch)
- sup_det_interval 5 -> 10 (still <= stabilizer hold / synthetic max_age)
- preview_every_n default 2 -> 5
- AnnotatedVideoWriter: codec auto-chain gstreamer_nvenc -> avc1 -> mp4v,
  max_height downscale (even dims, INTER_AREA); backend logged
- output_max_height plumbed Job -> web checkbox (720p) -> CLI --output-height
- README: 720p option, CLI flag
- 153 tests pass (+13)
2026-09-29 15:58:55 +07:00
jetson ad41bf01e1 feat: stabilize secondary-model detections, box-wins suppression, port 9050
- SyntheticIdAssigner: track_id=None dets get stable negative IDs so the
  stabilizer hold bridges sup_det_interval gaps -> no flicker, boxes count
- apply primary model class filter in merged path (UI checkboxes work)
- _suppress_sacks_under_boxes: sack dets overlapping box dets dropped
  (models without box class label boxes as sack; stops double counting)
- default web port 9000 -> 9050 (WEB_PORT env still overrides)
- README: port refs, counting zone modes section, project tree
- 140 tests pass (+13)
2026-09-29 15:32:07 +07:00
jetson f878110c3c fix: atomic compression writes, enforce size limit, job status guard 2026-09-28 13:38:24 +07:00
jetson 6f86bca204 feat: compress downloads to max 250MB via ffmpeg 2026-09-28 09:39:56 +07:00
jetson 7932119e17 feat: propagate sack vs box counts to results and UI 2026-09-28 09:36:27 +07:00
jetson 35cccd03b3 fix: absolute OUTPUT_DIR, resolution scaling for zones, full reference repo values 2026-09-22 14:30:05 +07:00
jetson f0ea95dd26 feat: web UI zone mode selector with preset dropdown 2026-09-22 13:08:28 +07:00
jetson fc20a521ee feat: merged detection output + parallel model execution
- Multiple models run simultaneously on each frame via ThreadPoolExecutor
- Detections merged with IoU deduplication (same class, high overlap → keep highest conf)
- Single merged_annotated.mp4 output (not per-model videos)
- Single model still uses existing run_pipeline for backward compat
- Active jobs banner on upload page (polls every 5s)
- GPU warning when selecting 3+ models
- 62/62 tests pass
2026-09-22 11:10:41 +07:00
jetson 163280078f fix: toggle preview display bug, add job deletion, optimize pipeline
- Fix: toggle ON now resets img display to block (was stuck on 'waiting')
- Toggle OFF sends API call to stop preview file writes
- Delete button on status page + jobs page cards
- DELETE /api/jobs/<id> endpoint removes job + output files
- PUT /api/jobs/<id>/preview endpoint toggles preview_enabled
- Pipeline skips resize/encode/write when preview_enabled=False
- Reduced preview defaults: 480px max, JPEG quality 60
- 62/62 tests pass
2026-09-22 10:49:06 +07:00
jetson 09a8829575 feat: live preview toggle, FPS indicator, live counting by object
- Toggle ON/OFF switch to disable preview (faster processing)
- FPS badge showing rolling average processing speed
- Live Loading/Unloading/Net counts updated in real-time
- Pipeline callback pushes stats every 10 frames
- Frontend polls and updates display every 2s
- 62/62 tests pass
2026-09-22 10:36:11 +07:00
jetson a5566f3b99 feat: switch live preview from WebSocket to MJPEG streaming
- Pipeline writes JPEG to /tmp/feedmill_preview_{job_id}.jpg (atomic)
- Flask serves MJPEG stream at /api/preview/{job_id}
- Frontend uses native <img src> MJPEG — zero JS needed
- Removed flask-socketio, eventlet, socket.io CDN dependencies
- 33% less bandwidth per frame, native browser decode
- Same proven approach as original karung-counting project
2026-09-22 10:09:22 +07:00
jetson f9e411f407 feat: 15+ FPS live preview via WebSocket push
- flask-socketio + threading mode (no eventlet monkey-patching)
- preview_queue in pipeline: downscale to 640p, JPEG encode, bounded queue
- encoder thread per job reads queue → SocketIO broadcast to room
- Frontend: SocketIO client replaces HTTP polling, handles preview_frame event
- Configurable: preview_every_n, preview_max_dim, preview_jpeg_quality
- 62/62 tests pass
2026-09-21 11:07:42 +07:00
jetson 93daa68668 fix: add explicit GPU memory cleanup between models to prevent OOM 2026-09-21 10:19:29 +07:00
jetson f779f05190 feat: add video reuse — re-analyze previous uploads without re-uploading 2026-09-21 09:35:29 +07:00
jetson dbd79ed442 feat: update Flask routes to use grouped models 2026-09-18 11:46:22 +07:00
jetson 7b19b5b41a fix(ui): add dynamic aria-valuenow, refine focus-visible styles 2026-09-18 08:06:40 +07:00
jetson 1c54bb1a11 feat(ui): status page — progress bar, live preview, result cards, polling 2026-09-17 16:05:22 +07:00
jetson dca6f6b335 feat(api): video preview endpoints — thumbnail, sample frames, live frame 2026-09-17 16:00:02 +07:00
jetson 2b54cc3353 fix: final review wave — CLI kwargs, class filter, job locks, upload order, tests 2026-09-16 15:14:44 +07:00
jetson 40e2dbe453 fix: secure upload/download paths, default filter, status enum compare, upload validation 2026-09-16 15:06:40 +07:00
jetson eb77e5be8a feat: Flask web UI on port 9000 with upload, job status, API endpoints 2026-09-16 15:04:49 +07:00