Commit Graph
87 Commits
Author SHA1 Message Date
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 ca0583b734 docs: AI handoff for FCP-side phase 2 (clip repush button) 2026-10-20 11:06: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 97507f8bf8 docs: add ERD.md (Mermaid) and CHANGELOG.md
ERD: no DB in this repo — models in-memory Job/JobResult entities plus
filesystem artifacts (uploads/, output/job-*/, zones.json, models/),
with status state machine and restart/orphan hazards.

CHANGELOG: Keep a Changelog format covering all 83 commits grouped by
date, from 2026-09-15 init through the /upload NameError 500 fix.
2026-10-20 09:24:30 +07:00
jetson 8012f45a5c add: plan for fixed zone mode 2026-10-16 14:18:05 +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 37e2d3e296 sync: mirror platform counting params (stabilizer hold, track_buffer, tracker iou)
- stabilizer max_hold 10 -> 25 frames (~1s occlusion hold, platform parity)
- cfg/tracker.yaml track_buffer 60 -> 90 (identical to platform now)
- ByteTrackTracker gains iou=0.7 (passed to model.track, platform parity)
- stabilizer/tracking modules now byte-identical to karung_counter_semarang
- 177 tests pass
2026-10-15 14:12:35 +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 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 2efcdb2316 fix: hide 'Waiting for first frame' placeholder once MJPEG delivers
No load handler existed — placeholder overlay (absolute inset:0) stayed
on top of the live stream forever. Hide on img load; toggle OFF already
re-shows it.
2026-10-13 10:47:44 +07:00
jetson d89c985134 feat: start/stop/restart dashboard scripts 2026-10-13 10:08:43 +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 f2b564446f feat: fixed ROI zone mode as default selection
- index.html: checked moves from dynamic to fixed radio; preset config
  visible on load (was only added on change event)
- app.js: when no zone presets exist, fall back to dynamic radio + hide
  preset config (server already falls back to dynamic)
2026-09-29 16:54:18 +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 4bd9de58e1 feat: freeze ROI mode, deadband+sticky jitter fix, explicit fixed/frozen ROI flags
- zone_mode=freeze: TruckROITracker locks box after 3 consecutive truck
  detections; geometry stays fixed while presence stays live (truck
  departure -> confidence 0 -> batch transitions keep working)
- jitter: 10px deadband skips EMA on tiny bbox noise; sticky main-truck
  pick (IoU>=0.3) prevents ROI jumps between parked trucks
- TruckROI.fixed/frozen flags replace dashboard confidence>=1.0 heuristic
- gate truck_centroid on truck_present in both pipelines
- +22 tests (test_truck_roi.py, test_freeze_plumbing.py); 127 pass
2026-09-28 14:36:21 +07:00
jetson 9a276b21f2 fix: isolate tests from real output/ dir via conftest autouse fixture
Tests imported the global job_queue (bound to real OUTPUT_DIR), creating
8 junk job-* dirs per pytest run (test_app x3, test_download_compress x4,
test_preview x1). Fixture redirects _output_dir to tmp_path and clears
the job registry before each test.
2026-09-28 13:55:47 +07:00
jetson f878110c3c fix: atomic compression writes, enforce size limit, job status guard 2026-09-28 13:38:24 +07:00
jetson 1dbfecaac3 fix: consistent Sack In/Out labels across live and results cards 2026-09-28 13:31:47 +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 d38375986e fix: exclude truck class from counting, use MultiClassLineCounter, real class labels 2026-09-28 09:30:13 +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 2b462318ac feat: visual distinction for fixed zone vs dynamic ROI 2026-09-22 13:12:17 +07:00
jetson 859d6a0f0f feat: interactive zone calibration tool 2026-09-22 13:10:45 +07:00
jetson f0ea95dd26 feat: web UI zone mode selector with preset dropdown 2026-09-22 13:08:28 +07:00
jetson 7c91081ea8 feat: add zone_mode and fixed_zone fields to Job 2026-09-22 13:03:37 +07:00
jetson ad3e7a7e9e feat: add fixed_zone param to pipelines, skip truck detection when set 2026-09-22 13:01:40 +07:00
jetson 4ad4284d9a feat: zone config loader and static ROI builder 2026-09-22 12:57:36 +07:00
jetson 5bf44d6457 fix: use tracker for counting + throttle supplementary detectors
- Primary model uses ByteTrackTracker.update() every frame (gives track_ids)
- Supplementary models run every 5th frame only (reduces GPU load N->1)
- Counter only receives detections with track_id (fixes zero counts)
- Dashboard draws all detections (tracker + supplementary merged)
2026-09-22 11:42:10 +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 b6379e14c9 fix: show live preview img by default (was display:none from SocketIO era) 2026-09-22 10:29:12 +07:00
jetson 39b582a481 docs: update README.md with current features and API
- Added live preview (MJPEG), auto truck detection, video reuse/delete
- Added abort button, model groups with format dropdown
- Updated API endpoints table with all current routes
- Added configuration section with env variables
- Added model formats and truck detection sections
- Updated project structure with preview.py
2026-09-22 10:18:36 +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 1e28eb49e2 fix: pass truck centroid to batch manager for state transitions
The legacy batch_mgr.update() method was calling update_truck() with
truck_centroid=None, which prevented the batch from transitioning
from IDLE to TRUCK_STABILIZING (centroid must be non-None).

Now pipeline computes centroid from ROI and passes it through.

Verified: old run had 0 cyan pixels (no tracking), new run has 28190
cyan pixels (tracking active, bounding boxes drawn).
2026-09-21 16:07:04 +07:00
jetson 57afb62542 fix: auto-use truck-detector when model lacks truck class
When a model without 'truck' class is selected (best, karung-dimuat,
yolo11n-bbox), the pipeline now automatically loads the truck-detector
model for truck detection. This ensures the batch manager transitions
to COUNTING_SACKS state and draws bounding boxes on output video.

Changes:
- Added find_truck_detector() helper in model_registry.py
- Added truck_model_config parameter to run_pipeline()
- job.py auto-selects truck-detector when model lacks truck class
- Verified with best.engine + batch-3.mp4: bounding boxes drawn
2026-09-21 13:37:01 +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 42c80fd0fc fix: remove required attr from file input when existing video is selected 2026-09-21 10:32:14 +07:00
jetson d353272a0b feat: add video delete button for uploaded videos 2026-09-21 10:20:02 +07:00
jetson 93daa68668 fix: add explicit GPU memory cleanup between models to prevent OOM 2026-09-21 10:19:29 +07:00
jetson 6783ff3970 feat: add abort button for job cancellation 2026-09-21 09:40:57 +07:00
jetson f779f05190 feat: add video reuse — re-analyze previous uploads without re-uploading 2026-09-21 09:35:29 +07:00
jetson a75db4ca49 fix: pin numpy<2.0 to resolve Jetson torch incompatibility 2026-09-21 09:00:44 +07:00