docs: plan — pin analysis frame to 1280x720 and model input to 640x640 (FCP parity)
Task 0 added to the FCP parity plan: the decoded frame is resized to 1280x720 before inference (FCP predict.py:826), imgsz=640 is passed explicitly on every track()/predict() call (FCP predict.py:467), and the annotated output is written at exactly 1280x720. Consequences pinned in the plan: the static zone and the counting polygon are scaled in FCP's frame (build_static_roi(zone, 1280, 720)), and min_bbox_area becomes literal FCP px^2 (config_loader.py:67) instead of a scaled approximation. Also fixed the Verification snippet: TruckROI has no line_x_start / line_x_end fields, so it printed an AttributeError; expected output is now '220 400 936'. Baseline test count refreshed 195 -> 204.
This commit is contained in:
1 parent
e27b373ac7
commit
167e20f26c
1 file changed
+206
-12
@@ -4,7 +4,7 @@
|
||||
|
||||
**Goal:** Make `feedmill_recounter` produce the same sack/box counts as the Feedmill Counting Platform (FCP = `../karung_counter_semarang`) for the same clip, by porting FCP's counting logic onto the recounter's video-file pipeline — without changing FCP.
|
||||
|
||||
**Architecture:** The recounter keeps its own video-file pipeline (upload → 720p transcode → track → stabilize → count → JSON result). FCP is a live RTSP pipeline with a fixed 1280×720 calibration. Parity = (a) copy FCP's counting predicates and thresholds verbatim into the recounter, (b) make the recounter count against FCP's calibrated static zone instead of its own dynamic truck-derived ROI. Every value is pinned to a `file:line` in FCP, which is read-only.
|
||||
**Architecture:** The recounter keeps its own video-file pipeline (upload → 720p transcode → resize to 1280×720 → track → stabilize → count → JSON result). FCP is a live RTSP pipeline that resizes every decoded frame to 1280×720 before inference (`predict.py:826`) and runs the models at 640×640 (`predict.py:467`) — so all of FCP's geometry and thresholds live in 1280×720 pixels. Parity = (a) copy FCP's counting predicates and thresholds verbatim into the recounter, (b) make the recounter count against FCP's calibrated static zone instead of its own dynamic truck-derived ROI, (c) pin the recounter's analysis frame to 1280×720 and its model input to 640×640 so the geometry is comparable for every clip (Task 0). Every value is pinned to a `file:line` in FCP, which is read-only.
|
||||
|
||||
**Tech Stack:** Python 3.10, Flask, ultralytics (YOLO track), OpenCV, shapely (already a dependency), pytest.
|
||||
|
||||
@@ -15,21 +15,25 @@
|
||||
- FCP (`../karung_counter_semarang`) is READ-ONLY: no edits, no commits, no service runs inside its tree. For the cross-check, copy it to `/tmp/fcp-parity/` and run there.
|
||||
- The recounter stays **video-file based**. FCP's stream-only mechanisms are out of scope: `RTSPStreamReader` (`src/pipeline.py:16`), `_RtspHealth` freeze/drop monitor (`predict.py:365-427`), reconnect/backoff, `stream.resolution`, `inference_stride`.
|
||||
- Counts must match FCP for the same clip. FCP's production path is `predict.py` — NOT `src/main.py` (prints DEPRECATED, `src/main.py:266-270`) and NOT `archive/`.
|
||||
- FCP geometry is authored in 1920×1080 and hard-scaled to 1280×720 (`predict.py:688-689`). The recounter's `zones.json` holds the same polygons in 1920×1080 space and `src/zone_config.build_static_roi` scales them by the real frame size. **Do not re-author the calibration** — the numbers already match (see Verification).
|
||||
- FCP geometry is authored in 1920×1080 and hard-scaled to 1280×720 (`predict.py:688-689`). The recounter's `zones.json` holds the same polygons in 1920×1080 space and `src/zone_config.build_static_roi` scales them by the frame size — which Task 0 pins to 1280×720 for every clip, so the scaling is exactly FCP's. **Do not re-author the calibration** — the numbers already match (see Verification).
|
||||
- **The frame space is 1280×720, always.** The decoded frame is resized to 1280×720 before detection, tracking, counting and drawing (FCP `predict.py:826`), so the count line, the counting polygon and the `min_bbox_area` px² thresholds are all measured in FCP's frame, whatever the clip's native resolution. Task 0.
|
||||
- **The model input is 640×640, always.** `imgsz=640` is passed explicitly on every `track()` / `predict()` call (Task 0). A 1280×720 frame letterboxes to 640×360 content on a 640×640 canvas; the TensorRT engines were exported at `imgsz=640` (`scripts/export_engines.py:29`), so the runtime shape matches the engine profile.
|
||||
- **The annotated output is 1280×720.** The written video *is* the analysis frame: the overlay is drawn at 1280×720 and encoded as-is — no rescale of the boxes, no second resize. Task 0.
|
||||
- FCP's `counting.*` keys (`confirm_delay_sec`, `exit_confirm_delay_sec`, `debounce_frames`, `entry_overlap_threshold`, `exit_overlap_threshold`, `camera_noise_deadband`, `max_reid_transit_distance`, `circle_stay_timeout_sec`, `tolerance_missing_frames`, `max_reid_frames`, `jarak_toleransi_duplikat`, `min_valid_area`) are parsed but **never read** by FCP runtime (`src/config_loader.py:637-662` warns they are ignored). Do not port them — dead in the reference too.
|
||||
- Existing suite must stay green: baseline `195 passed` (`python -m pytest tests/ -q`).
|
||||
- Existing suite must stay green: baseline `204 passed` (`python -m pytest tests/ -q`) — 195 before the output-filename feature (`e963ba0`), 9 added by it.
|
||||
- No new dependency.
|
||||
- Commit after every task; message style follows repo history (`feat:`, `fix:`, `docs:`, `test:`, `chore:`).
|
||||
|
||||
## Review Focus
|
||||
|
||||
Five failure modes a reasonable person would expect to be handled, each pinned to a task below:
|
||||
Six failure modes a reasonable person would expect to be handled, each pinned to a task below:
|
||||
|
||||
1. A sack first seen *below* the line never counted as loading must also never count as unloading (FCP gates unloading on a prior loading) → Task 1.
|
||||
2. A sack crossing outside the calibrated counting polygon must not be counted at all → Task 3.
|
||||
3. A truncated / half-written upload must not report partial counts as if the clip were complete → Task 10.
|
||||
4. Two truck sessions in one clip must not carry per-track dedup state from session 1 into session 2 → Task 7.
|
||||
5. A typo in `config.yaml` must not silently fall back to built-in defaults and quietly change counts → Task 9.
|
||||
6. A clip uploaded at any resolution other than 1280×720 must not shift the count line, the counting polygon or the area thresholds — everything is measured in FCP's 1280×720 frame, and the annotated file is written at 1280×720 → Task 0.
|
||||
|
||||
## Already At Parity — Do Not Touch
|
||||
|
||||
@@ -45,6 +49,16 @@ Five failure modes a reasonable person would expect to be handled, each pinned t
|
||||
| Truck ROI X filter window | 400…936 (`predict.py:715-719`) | same via `build_static_roi` |
|
||||
| Cross-class box-wins suppression | IoU 0.4 (`predict.py:946-948`) | same (`src/pipeline.py:476`) |
|
||||
|
||||
## Frame & Model Geometry (pinned by Task 0)
|
||||
|
||||
| Property | FCP | Recounter today | After Task 0 |
|
||||
|---|---|---|---|
|
||||
| Analysis frame | 1280×720 (`predict.py:826`) | the clip's native size (post-transcode ≤720p) | 1280×720 |
|
||||
| Model input | 640×640 (`predict.py:467`) | ultralytics default 640, implicit | 640×640, explicit `imgsz=640` |
|
||||
| Annotated output | live dashboard, no file | the clip's native size | 1280×720 |
|
||||
| Zone geometry | scaled by 1280/1920 and 720/1080 (`predict.py:688-689`) | scaled by the native frame size | identical to FCP |
|
||||
| `min_bbox_area` unit | px² @1280×720 (`config_loader.py:67`) | px² scaled to the frame area (`src/pipeline.py:518-521`) | px² @1280×720, unscaled |
|
||||
|
||||
---
|
||||
|
||||
## File Structure
|
||||
@@ -52,18 +66,182 @@ Five failure modes a reasonable person would expect to be handled, each pinned t
|
||||
**Modify**
|
||||
- `src/counting.py` — `_loaded_tracks` gate (Task 1), `reset_state()` (Task 7).
|
||||
- `src/zone_config.py` — expose counting-area + truck-area polygons (Task 3, 6).
|
||||
- `src/pipeline.py` — polygon filter (Task 3), real batch events (Task 6), batch-start reset hook (Task 7), truncation flag (Task 10).
|
||||
- `src/pipeline.py` — fixed 1280×720 analysis frame (Task 0), polygon filter (Task 3), real batch events (Task 6), batch-start reset hook (Task 7), truncation flag (Task 10).
|
||||
- `src/batch.py` — none required; `update_sacks()` already accepts real events (`src/batch.py:199`).
|
||||
- `src/config.py` — fail-fast load + validation call (Task 9).
|
||||
- `src/job.py` — `JobResult.truncated` / `frames_expected` (Task 10).
|
||||
- `config.yaml` — parity values (Tasks 4, 5, 8).
|
||||
- `app.py` — `zone_mode` default (Task 2), truncation fields in the job response (Task 10).
|
||||
- `src/tracking.py` — explicit `imgsz=640` (Task 0).
|
||||
- `src/detection.py` — explicit `imgsz=640` (Task 0).
|
||||
- `src/video_writer.py` — encodes the 1280×720 analysis frame (Task 0); no API change.
|
||||
- `app.py` — zone ROI built in the 1280×720 frame (Task 0), `zone_mode` default (Task 2), truncation fields in the job response (Task 10).
|
||||
|
||||
**Create**
|
||||
- `src/validation.py` — `validate_config()` + `InputValidator` mirroring FCP `src/validation.py` (Task 9).
|
||||
- `tests/test_counting.py` — counting-core unit tests (Tasks 1, 7).
|
||||
- `tests/test_batch.py` — batch FSM unit tests (Task 6).
|
||||
- `tests/test_validation.py` — config validation unit tests (Task 9).
|
||||
- `tests/test_frame_geometry.py` — frame size + model-input pinning (Task 0).
|
||||
|
||||
---
|
||||
|
||||
### Task 0: Pin the analysis frame to 1280×720 and the model input to 640×640
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/pipeline.py:196-203` and `:574-581` (resize the decoded frame to 1280×720 and use that size for the writer, the zone geometry and the area thresholds), `src/pipeline.py:280` and `:652` (writer frame size), `src/tracking.py:46-53` (`imgsz=640`), `src/detection.py:43-45` (`imgsz=640`), `app.py:154-161` and `app.py:293-300` (build the zone ROI in the 1280×720 frame instead of the upload's native size)
|
||||
- Test: `tests/test_frame_geometry.py` (create), `tests/test_video_writer.py`, `tests/test_app.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `src.pipeline.ANALYSIS_SIZE: tuple[int, int] = (1280, 720)` — the single source of truth for the frame space.
|
||||
- Produces: `src.pipeline.analysis_size(src_w: int, src_h: int) -> tuple[int, int]` → always `ANALYSIS_SIZE`. The arguments are accepted so callers can pass the decoded size; the function ignores them on purpose — one-line docstring naming the FCP pin.
|
||||
- Produces: `src.video_writer.AnnotatedVideoWriter(..., frame_size=(1280, 720))` → `written_size == (1280, 720)` → the encoded file is 1280×720.
|
||||
- Consumes (unchanged): `build_static_roi(zone, video_w, video_h)` (`src/zone_config.py:24`) — the *callers* now pass `ANALYSIS_SIZE`.
|
||||
|
||||
**FCP reference:**
|
||||
- `predict.py:826` — `frame = cv2.resize(frame, (1280, 720))` — every decoded frame is resized to 1280×720 before anything else touches it.
|
||||
- `predict.py:531-532` and `:648-649` — `width = 1280`, `height = 720` — the entire geometry space.
|
||||
- `predict.py:688-689` — `scale_x = 1280.0 / 1920.0`, `scale_y = 720.0 / 1080.0` — the calibration is *defined* for a 1280×720 frame.
|
||||
- `predict.py:701-719` — the count line and the truck ROI are hard-scaled to that frame (`line_y 220`, ROI x-window `400…936`).
|
||||
- `predict.py:467` — `_ = m(dummy, imgsz=640, device=device, verbose=False)` — the models run at 640×640.
|
||||
- `config_loader.py:67` — `min_bbox_area: int = 1500 # px^2 @1280x720` — the area thresholds are px² of the 1280×720 frame.
|
||||
|
||||
**Why:** today the recounter analyses the clip at its native (post-transcode) resolution, scales the static zone by *that* resolution (`app.py:161`), scales the area thresholds by the frame area (`src/pipeline.py:518-521`) and writes the annotated video at the same native size. Upload a 960×720 (4:3) or a 1600×900 clip and the count line, the counting polygon, the area thresholds and the output resolution all shift — FCP would not. Pinning the frame to 1280×720 makes the recounter's geometry comparable with FCP for every input, and turns `min_bbox_area` into the literal px² values from `config.yaml` (Task 4) instead of a scaled approximation.
|
||||
|
||||
**Frame contract (this is the spec):**
|
||||
1. Decode → `frame = cv2.resize(frame, (1280, 720))` — the aspect ratio is *not* preserved; this is exactly FCP `predict.py:826`.
|
||||
2. Detect and track on that 1280×720 frame, with the model input pinned to 640×640 (letterbox: 640×360 content on a 640×640 canvas). Boxes come back in 1280×720 px.
|
||||
3. Count, draw the overlay and encode that same 1280×720 frame → the annotated file is 1280×720 and the overlay is never rescaled.
|
||||
4. The static zone is built with `build_static_roi(zone, 1280, 720)` → FCP's `line_y 220`, ROI `400…936`, regardless of the upload's native size.
|
||||
5. `min_bbox_area` is applied unscaled, in 1280×720 px² → the literal FCP values (Task 4).
|
||||
6. The upload transcode (`app.py:150`, `resize_video_to_max_height(..., max_height=720)`) stays — it is a storage/speed optimisation, not a geometry knob. It is lossy for sources taller than 720p (FCP decodes the raw stream instead), so pixel-exact cross-checks should use a 720p-or-shorter source.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests** — create `tests/test_frame_geometry.py`:
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
|
||||
def _fake_yolo(recorder):
|
||||
"""Fake ultralytics YOLO that records the kwargs of track()/predict()."""
|
||||
|
||||
class _Result:
|
||||
boxes = None
|
||||
|
||||
class _FakeYOLO:
|
||||
names = {"sack": 0, "box": 0, "truck": 0}
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def track(self, frame, **kwargs):
|
||||
recorder.update(kwargs)
|
||||
return [_Result()]
|
||||
|
||||
def predict(self, frame, **kwargs):
|
||||
recorder.update(kwargs)
|
||||
return [_Result()]
|
||||
|
||||
return _FakeYOLO
|
||||
|
||||
|
||||
def test_analysis_size_is_always_1280x720():
|
||||
"""Every clip is analysed in FCP's 1280x720 frame."""
|
||||
from src.pipeline import ANALYSIS_SIZE, analysis_size
|
||||
assert ANALYSIS_SIZE == (1280, 720)
|
||||
assert analysis_size(1920, 1080) == (1280, 720)
|
||||
assert analysis_size(960, 720) == (1280, 720)
|
||||
assert analysis_size(1280, 960) == (1280, 720)
|
||||
|
||||
|
||||
def test_tracker_pins_imgsz_640(monkeypatch):
|
||||
"""Tracking runs at 640x640 (FCP predict.py:467)."""
|
||||
import src.tracking as tracking_mod
|
||||
calls = {}
|
||||
monkeypatch.setattr(tracking_mod, "YOLO", _fake_yolo(calls))
|
||||
tracker = tracking_mod.ByteTrackTracker("fake.engine", conf=0.3)
|
||||
tracker.update(np.zeros((720, 1280, 3), dtype=np.uint8), [])
|
||||
assert calls["imgsz"] == 640
|
||||
|
||||
|
||||
def test_detector_pins_imgsz_640(monkeypatch):
|
||||
"""Plain detection (the truck detector) runs at 640x640 too."""
|
||||
import src.detection as detection_mod
|
||||
calls = {}
|
||||
monkeypatch.setattr(detection_mod, "YOLO", _fake_yolo(calls))
|
||||
detector = detection_mod.BaseDetector("fake.engine", conf=0.45)
|
||||
detector.detect(np.zeros((720, 1280, 3), dtype=np.uint8))
|
||||
assert calls["imgsz"] == 640
|
||||
```
|
||||
|
||||
In `tests/test_video_writer.py`:
|
||||
|
||||
```python
|
||||
def test_writer_emits_exactly_1280x720(tmp_path):
|
||||
"""The annotated file is 1280x720, whatever the clip was."""
|
||||
from src.video_writer import AnnotatedVideoWriter
|
||||
writer = AnnotatedVideoWriter(str(tmp_path / "out.mp4"), fps=25, frame_size=(1280, 720))
|
||||
assert writer.written_size == (1280, 720)
|
||||
```
|
||||
|
||||
In `tests/test_app.py` — the zone is built in FCP's frame whatever the clip's native size:
|
||||
|
||||
```python
|
||||
ZONE = {
|
||||
"truck_area": [[600, 385], [609, 1076], [1404, 1078], [1381, 343]],
|
||||
"counting_area": [[574, 50], [586, 1077], [1418, 1076], [1397, 50]],
|
||||
"count_line": {"x_start": 577, "x_end": 1401, "y": 330},
|
||||
"reference_resolution": [1920, 1080],
|
||||
}
|
||||
|
||||
|
||||
def test_zone_roi_is_built_at_1280x720():
|
||||
"""The ROI is FCP's calibration, not a function of the clip's resolution."""
|
||||
import app as app_module
|
||||
roi = app_module._static_roi(ZONE)
|
||||
assert roi.line_y == 220
|
||||
assert (roi.x1, roi.x2) == (400, 936)
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run the tests to verify they fail**
|
||||
|
||||
Run: `python -m pytest tests/test_frame_geometry.py tests/test_video_writer.py tests/test_app.py -k "1280 or imgsz" -v`
|
||||
Expected: FAIL — `src.pipeline.analysis_size` does not exist, `imgsz` is not passed, and the ROI is still built from the clip's native size.
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
|
||||
- `src/pipeline.py`: add `ANALYSIS_SIZE = (1280, 720)` and `analysis_size(src_w: int, src_h: int) -> tuple[int, int]` near the top of the module. In **both** runners (`run_pipeline` `:196-203` / `:285`, `run_merged_pipeline` `:574-581` / `:674`): right after `ret, frame = cap.read()` do `frame = cv2.resize(frame, ANALYSIS_SIZE)`, then set `w, h = ANALYSIS_SIZE` for the writer (`:280`, `:652`), the zone geometry and `_scaled_min_areas` (`:518-521`). Keep the decoded size for logging only.
|
||||
- `src/tracking.py:46-53`: add `imgsz=640` to the `self._model.track(...)` call.
|
||||
- `src/detection.py:43-45`: add `imgsz=640` to the `self._model.predict(...)` call.
|
||||
- `app.py:154-161` and `app.py:293-300`: build the zone through a small helper — `def _static_roi(zone): return build_static_roi(zone, *ANALYSIS_SIZE)` (import `ANALYSIS_SIZE` from `src.pipeline`; no import cycle, `src.pipeline` does not import `app`). The `cv2.VideoCapture` probe blocks in both places then go away.
|
||||
- `src/zone_config.py`: unchanged — `build_static_roi(zone, 1280, 720)` already yields FCP's numbers (Verification item 2 proves it).
|
||||
- `src/video_writer.py`: unchanged — with `frame_size=(1280, 720)` it encodes 1280×720. The `max_height` option stays as an explicit opt-in downscale (the `output_height` form field); the parity output is the default one, i.e. leave `output_height` empty.
|
||||
|
||||
- [ ] **Step 4: Run the tests to verify they pass**
|
||||
|
||||
Run: `python -m pytest tests/test_frame_geometry.py tests/test_video_writer.py tests/test_app.py -v` → all pass.
|
||||
|
||||
- [ ] **Step 5: Verify the output really is 1280×720** (end-to-end, not only unit level)
|
||||
|
||||
```bash
|
||||
curl -s -X POST http://127.0.0.1:9050/api/analyze -H "X-API-Key: $RECOUNTER_API_KEY" \
|
||||
-F "fcp_mode=C" -F "video=@<clip>.mp4"
|
||||
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 \
|
||||
output/job-*/merged_annotated_*.mp4
|
||||
```
|
||||
Expected: `1280,720`.
|
||||
|
||||
- [ ] **Step 6: Run the full suite, then commit**
|
||||
|
||||
Run: `python -m pytest tests/ -q` → zero failures (baseline 204 + the new tests).
|
||||
```bash
|
||||
git add src/pipeline.py src/tracking.py src/detection.py app.py \
|
||||
tests/test_frame_geometry.py tests/test_video_writer.py tests/test_app.py
|
||||
git commit -m "feat: analyse and write at 1280x720 with a pinned 640x640 model input (FCP parity)"
|
||||
```
|
||||
|
||||
**Note:** this changes published counts for clips whose native resolution is not 1280×720 (their geometry now matches FCP's). A 1280×720 clip is unaffected — same pixels, same thresholds. Announce it in the PR/CHANGELOG.
|
||||
|
||||
**Blocks:** Task 2 (zone ROI), Task 3 (counting polygon) and Task 4 (`min_bbox_area` px²) all assume a 1280×720 frame — land Task 0 first.
|
||||
|
||||
---
|
||||
|
||||
@@ -219,6 +397,7 @@ Expected: FAIL — current default is `"dynamic"`.
|
||||
- `app.py:128`, `:260`, `:284`: `request.form.get("zone_mode", "dynamic")` → `request.form.get("zone_mode", "fixed")`.
|
||||
- `src/job.py:70`, `:119`: `zone_mode: str = "dynamic"` → `zone_mode: str = "fixed"`.
|
||||
- In `_save_and_queue` (`app.py:149-159`) and the reuse path (`app.py:284-296`): when `zone_mode == "fixed"` but no active zone is found, set `zone_mode = "dynamic"` so an uncalibrated deployment still runs. Add a one-line comment naming why.
|
||||
- The ROI itself is built in FCP's 1280×720 frame (Task 0): `build_static_roi(zone, *ANALYSIS_SIZE)`. Nothing about the calibration changes here.
|
||||
|
||||
- [ ] **Step 4: Run the test to verify it passes**
|
||||
|
||||
@@ -281,6 +460,7 @@ Expected: FAIL — `build_counting_polygon` does not exist; signature has no `co
|
||||
`keep = counting_polygon.contains(Point((b[0]+b[2])/2.0, (b[1]+b[3])/2.0))`
|
||||
Import `Point` from `shapely.geometry`.
|
||||
- `src/job.py` / `app.py`: build the polygon from the same zone dict used for `build_static_roi` and pass it into the job (Task 2 already builds the zone dict at `app.py:150-158`).
|
||||
- The polygon is scaled in the same frame as the ROI: `build_counting_polygon(zone, *ANALYSIS_SIZE)` (Task 0 pins the frame to 1280×720) → it matches FCP's `detection_polygon` (`predict.py:690-698`) exactly.
|
||||
|
||||
- [ ] **Step 4: Run the tests to verify they pass**
|
||||
|
||||
@@ -302,13 +482,15 @@ git commit -m "feat: filter counts by calibrated counting polygon (FCP predict.p
|
||||
- Test: `tests/test_config.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `load_config(path) -> dict` (`src/config.py:78`), `_scaled_min_areas(cfg, w, h)` (`src/pipeline.py:515`).
|
||||
- Consumes: `load_config(path) -> dict` (`src/config.py:78`), `_scaled_min_areas(cfg, w, h)` (`src/pipeline.py:518-521`).
|
||||
- Produces: no new API.
|
||||
|
||||
FCP reference: `config.yaml:83-93` — `truck {conf 0.45, iou 0.7, min_bbox_area 5000}`, `sack {conf 0.30, iou 0.7, min_bbox_area 1500}`, `box {conf 0.35, iou 0.7, min_bbox_area 1000}`. The sack conf 0.30 carries the comment *"live gate used hardcode 0.50; 0.30 reduce undercounting"*.
|
||||
|
||||
Note on inference conf: FCP runs the sack tracker at `dp_sack.conf = 0.30` and the box tracker at 0.35 (`predict.py:491`, `:504`). The recounter runs ONE shared tracker at `min(sack_conf, box_conf)` and then re-gates per class (`src/pipeline.py:212-214`, `:489-501`), so with `sack_conf = 0.30` the effective tracker conf becomes 0.30 and boxes are still gated at `box_conf = 0.35` — net effect matches FCP. No code change needed beyond the config value.
|
||||
|
||||
Note on `min_bbox_area` units: FCP applies them as px² of the 1280×720 frame (`config_loader.py:67`, `predict.py:868-872`) — no scaling. After Task 0 the recounter's frame *is* 1280×720, so `_scaled_min_areas` has a scale factor of exactly 1.0 and the config values below are literal FCP px². Only the values change, not the units.
|
||||
|
||||
- [ ] **Step 1: Write the failing test** — add to `tests/test_config.py`:
|
||||
|
||||
```python
|
||||
@@ -757,7 +939,7 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
|
||||
## Verification
|
||||
|
||||
1. **Unit suite**: `python -m pytest tests/ -q` → zero failures (baseline was 195 passed; new tests added in Tasks 1, 3, 4, 5, 6, 7, 8, 9, 10).
|
||||
1. **Unit suite**: `python -m pytest tests/ -q` → zero failures (baseline was 204 passed; new tests added in Tasks 0, 1, 3, 4, 5, 6, 7, 8, 9, 10).
|
||||
2. **Calibration equality** (static geometry must match FCP exactly):
|
||||
```bash
|
||||
python - <<'PY'
|
||||
@@ -767,11 +949,23 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
"counting_area": [[574,50],[586,1077],[1418,1076],[1397,50]],
|
||||
"reference_resolution": [1920,1080]}
|
||||
roi = build_static_roi(zone, 1280, 720)
|
||||
print(roi.line_y, roi.line_x_start, roi.line_x_end, roi.x1, roi.x2)
|
||||
print(roi.line_y, roi.x1, roi.x2)
|
||||
PY
|
||||
```
|
||||
Expected: `220 384 934 400 936` — identical to FCP `predict.py:701-719`.
|
||||
3. **Cross-check against FCP on one real clip** (read-only w.r.t. the FCP repo):
|
||||
Expected: `220 400 936` — identical to FCP `predict.py:701-719` (FCP's count-line x-range `384…934` is not carried by the recounter's `TruckROI`, which has no such fields).
|
||||
3. **Frame and model input are pinned** (Task 0):
|
||||
```bash
|
||||
grep -n "imgsz=640" src/tracking.py src/detection.py
|
||||
python -c "from src.pipeline import ANALYSIS_SIZE; print(ANALYSIS_SIZE)"
|
||||
```
|
||||
Expected: one `imgsz=640` in each file, and `(1280, 720)`.
|
||||
4. **The annotated output is 1280×720** — every job, whatever the clip's native size:
|
||||
```bash
|
||||
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 \
|
||||
output/job-*/merged_annotated_*.mp4
|
||||
```
|
||||
Expected: `1280,720`.
|
||||
5. **Cross-check against FCP on one real clip** (read-only w.r.t. the FCP repo):
|
||||
```bash
|
||||
rm -rf /tmp/fcp-parity && cp -r ../karung_counter_semarang /tmp/fcp-parity
|
||||
# run FCP on the clip (file source, not RTSP) from the copy
|
||||
@@ -780,4 +974,4 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
curl -F "fcp_mode=C" -F "video=@<clip.mp4>" http://127.0.0.1:9050/api/analyze
|
||||
```
|
||||
Expected: `loading_count` / `unloading_count` agree, or differ by at most the documented platform-only differences (FCP counts a live session per truck batch; the recounter counts the whole clip). Record the actual delta in the PR description.
|
||||
4. **Manual spot check**: play the annotated output of one clip and confirm the counted sacks are exactly the ones that crossed the calibrated line inside the counting polygon.
|
||||
6. **Manual spot check**: play the annotated output of one clip and confirm the counted sacks are exactly the ones that crossed the calibrated line inside the counting polygon.
|
||||
Reference in new issue
Block a user