Skip to content

feat: measure the card detector offline with a detector replay - #504

Draft
Reilley64 wants to merge 10 commits into
mainfrom
spec/493-detector-replay
Draft

Reilley64 wants to merge 10 commits into
mainfrom
spec/493-detector-replay

Conversation

@Reilley64

@Reilley64 Reilley64 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Integration branch for spec #493: measure the card detector offline, and keep the card outline on the card edge under hand movement and tilt.

Each ticket merges here through its own PR. The code review fixes are in #518, and main is merged in. This PR goes to main once every ticket is in and the code review is done.

Ticket PR State
#494 Detector replay: first run on plain and empty surfaces #502 merged here
#498 Training crop scorer #501 merged here
#495 Run the detector replay in CI and gate detector PRs #505 merged here
#496 Hard conditions and camera tilt in the detector replay #506 merged here
#497 Clips through automatic capture in the detector replay #510 merged here
#499 Check the card aspect on the card, not in the frame #515 merged here; device check pending
#500 Refine the card outline on the photo #514 merged here; device check pending

Part of #493

Part of #494

## Summary

`bun run detector:replay` measures the card detector on a Mac, with no
phone and no hosted access. It renders pinned synthetic frames, runs the
detector on the branch and on the merge base in one run, and prints one
table. It exits 1 when a pass bar fails.

```text
detector:replay (modules/card-detector/scripts/replay.ts)
  renderFrames          uv run test/scanner-evidence/detector/frames.py, then check frames.sha256
  buildCommand(branch)  swift build card-detector, which compiles ios/Detector unchanged
  buildCommand(base)    git archive of the merge base's Package.swift, ios/Detector, macos
  card-detector frames  one JSON line per frame: the detection sample fields and the time of the detector call
  scoreReplay           corner error, inside outlines, size error, detection rate, false outlines, Mac p95
  compareReplays        the #493 bars, plus "same detector code gives the same numbers"
```

```diff
 apps/mobile/
 ├── modules/card-detector/
 │   ├── Package.swift                      # + card-detector executable target
+│   ├── macos/CardDetectorCommand/main.swift
+│   └── scripts/replay.ts
 └── test/
+    ├── detector-replay.test.ts
     └── scanner-evidence/
+        └── detector/                       # frames.py, cards.json, frames.sha256, score.ts
```

- The command reaches the detector's internal types through `@testable
import`. The replay builds it with `-Xswiftc -enable-testing` in
release.
- The frame recipe has `plain` and `empty-plain` for now, 30 frames
each. Each frame comes from a camera pose: focal length, and a tilt of 0
for now. Each frame draws its random numbers from its condition and its
index, so #496 can add conditions and tilt without changing these
frames. Labels record the true corners, the border colour, the tilt, and
the intrinsic matrix.
- When the merge base has no detector command (true until this spec
lands on `main`), the replay builds the branch's command against the
merge base's detector files.
- When both sides have the same detector files and command, every number
except timing must match, or the replay fails. That is how the replay
checks that two runs on the same commit give the same numbers.

## Evidence

Replay on this branch against `origin/main` (Apple M3, macOS 27.0.1,
Xcode 26.3):

| Condition | Metric | Merge base | Branch | Bar | Result |
| --- | --- | --: | --: | --- | --- |
| plain | Detection rate | 22 of 30 | 22 of 30 | not lower by more than
1 | pass |
| plain | Corner error median | 0.01 mm | 0.01 mm | not worse by more
than 0.1 mm | pass |
| plain | Corner error p90 | 0.07 mm | 0.07 mm | not worse by more than
0.5 mm | pass |
| plain | Inside outlines | 1 | 1 | no new one | pass |
| plain | Size error, width x height | 0.00 mm x 0.00 mm | 0.00 mm x
0.00 mm | reported | |
| empty-plain | False outlines | 0 | 0 | zero | pass |
| | Mac timing p95 | 3.6 ms | 3.5 ms | at most 1.2 times the merge base
| pass |
|  | Same detector code | same | same numbers | same numbers | pass |

- The 8 plain misses are all borderless cards. Their bottom edge is
dark, so its step has the other polarity from the other three edges, and
the edge refiner refuses the outline.
- The 1 inside outline is `plain-018.png`, a black-bordered card
outlined on its inner frame, 2.6 to 6.7 mm inside.
- `--base HEAD`, where the merge base has its own command (the path on
`main` after merge), gives the same table.
- **Same numbers.** Two more full runs gave the same `base.json` and
`branch.json` except timing.
- **Planted regression.** I made the edge refiner pick the innermost
lines (`outwardness <` in `CardEdgeRefiner.swift`), ran the replay once,
then reverted the change:
  - Before: exit 0, every bar passes.
- After: exit 1. Inside outlines went from 1 to 19, and the median
corner error from 0.01 to 9.89 mm. The list of failing outlines named
the 18 new ones.
- **Scorer test** (`test/detector-replay.test.ts`, 5 tests): corner
error in mm on the card, a planted inside outline fails its bar, an
outline 0.8 mm inside is not an inside outline, a false outline fails,
and the same detector code with other numbers fails.
- Mutation: raising the inside outline limit to 10 mm turns 2 tests red.
- Mutation: making the same-numbers check always pass turns 1 test red.
- `bun run detector:test` (14 tests), `typecheck`, and `lint` pass
locally.

## Merge Danger

**Door:** two-way

The command, the scripts, and the recipe are new files. `ios/Detector`
and the app do not change.

**Blast Radius:** tooling

The Detector workflow builds the package, now with the command target.
#495 runs the replay in CI.
)

Part of #496

## Summary

The detector replay now covers the known weak spots of the card
detector. Each frame comes from a camera pose with a tilt angle and a
focal length, so the replay can split frames by tilt.

```diff
 detector/frames.py
   conditions
     plain, empty-plain
+    patterned, shadow, sleeve, glare, motion-blur, hand, empty-patterned
+  tilt buckets: 0, 0-7.5, 7.5-15, 15-25 degrees, 30 frames each per condition
+  labels.json: + tiltBucket (tiltDegrees and intrinsicMatrix were already there)
+detector/textures.json   # 12 Poly Haven textures, CC0, with page and download
 detector/score.ts
-  bars per condition
+  bars per condition and tilt bucket
+  reported: per condition and border colour, per border colour and tilt bucket
 replayTable
-  one row per bar
+  one row per condition and tilt bucket, merge base → branch in each cell
```

- The frame set has 9 conditions x 4 tilt buckets x 30 frames, 1,080
frames in all. Each condition, border colour, and tilt bucket has 10
frames.
- The 60 frames from #494 (`plain-000` to `plain-029` and
`empty-plain-000` to `empty-plain-029`) keep the same bytes. Only
`labels.json` changes in their part of `frames.sha256`.
- Patterned surfaces are half procedural: high-contrast stripes, checks,
a grid, dots, text, or a clutter of rectangles. The other half are CC0
photo textures from Poly Haven, scaled and turned at random. The pattern
lies on the table plane, so it takes the camera pose too.
- The bars are the same as in #494. They now apply to each condition and
tilt bucket, so the new metrics take part in the gate that #505 runs in
CI.
- The list of failing outlines now gives each frame's tilt bucket and
border colour.

## Evidence

**Before (#494):** 2 conditions, 60 frames, every frame flat.

**After:** `bun run detector:replay` on this branch against
`origin/main` (`a6fcfaf`), on an Apple M3 with macOS 27.0.1 and Xcode
26.3. Every bar passes. The table on `main` shows the known weak spots:

| Weak spot | On `main` |
| --- | --- |
| Inside outlines rise with tilt on black-bordered cards | 3, 12, 17,
and 39 of 70 frames in the 0, 0-7.5, 7.5-15, and 15-25 degree buckets |
| Outlines on the sleeve edge | Size error -1.08 x -1.14 mm at no tilt,
about the sleeve margin |
| Low detection rate on patterned surfaces | 61 of 120 frames, against
82 of 120 on plain surfaces. For black and white borders, 56 of 80
against 73 of 80. |
| No false outlines on empty surfaces | 0 of 240 empty plain and
patterned frames |

<details>
<summary>The full table</summary>

Card frames by condition and tilt in degrees, merge base → branch:

| Condition | Tilt | Detection rate | Corner error median | Corner error
p90 | Inside outlines | Size error, width x height | Result |
| --- | --- | --: | --: | --: | --: | --: | --- |
| plain | 0 | 22 of 30 → 22 of 30 | 0.01 mm → 0.01 mm | 0.07 mm → 0.07
mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 0-7.5 | 18 of 30 → 18 of 30 | 0.01 mm → 0.01 mm | 0.02 mm →
0.02 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 7.5-15 | 21 of 30 → 21 of 30 | 0.01 mm → 0.01 mm | 5.34 mm →
5.34 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 15-25 | 21 of 30 → 21 of 30 | 3.04 mm → 3.04 mm | 5.60 mm →
5.60 mm | 12 → 12 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| patterned | 0 | 12 of 30 → 12 of 30 | 0.02 mm → 0.02 mm | 4.65 mm →
4.65 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 0-7.5 | 17 of 30 → 17 of 30 | 0.05 mm → 0.05 mm | 4.89 mm
→ 4.89 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 7.5-15 | 16 of 30 → 16 of 30 | 0.04 mm → 0.04 mm | 8.70 mm
→ 8.70 mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 15-25 | 16 of 30 → 16 of 30 | 4.19 mm → 4.19 mm | 8.75 mm
→ 8.75 mm | 12 → 12 | 1.81 x 1.48 mm → 1.81 x 1.48 mm | pass |
| shadow | 0 | 25 of 30 → 25 of 30 | 2.60 mm → 2.60 mm | 4.84 mm → 4.84
mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 0-7.5 | 24 of 30 → 24 of 30 | 0.19 mm → 0.19 mm | 5.13 mm →
5.13 mm | 3 → 3 | -0.01 x -0.09 mm → -0.01 x -0.09 mm | pass |
| shadow | 7.5-15 | 26 of 30 → 26 of 30 | 1.84 mm → 1.84 mm | 5.74 mm →
5.74 mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 15-25 | 20 of 30 → 20 of 30 | 4.27 mm → 4.27 mm | 5.92 mm →
5.92 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| sleeve | 0 | 29 of 30 → 29 of 30 | 1.67 mm → 1.67 mm | 2.29 mm → 2.29
mm | 0 → 0 | -1.08 x -1.14 mm → -1.08 x -1.14 mm | pass |
| sleeve | 0-7.5 | 26 of 30 → 26 of 30 | 1.50 mm → 1.50 mm | 2.27 mm →
2.27 mm | 2 → 2 | -1.00 x -0.97 mm → -1.00 x -0.97 mm | pass |
| sleeve | 7.5-15 | 27 of 30 → 27 of 30 | 1.95 mm → 1.95 mm | 3.30 mm →
3.30 mm | 4 → 4 | -0.73 x -0.84 mm → -0.73 x -0.84 mm | pass |
| sleeve | 15-25 | 25 of 30 → 25 of 30 | 3.32 mm → 3.32 mm | 5.36 mm →
5.36 mm | 16 → 16 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0 | 22 of 30 → 22 of 30 | 0.02 mm → 0.02 mm | 0.10 mm → 0.10
mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0-7.5 | 22 of 30 → 22 of 30 | 0.02 mm → 0.02 mm | 6.26 mm →
6.26 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 7.5-15 | 24 of 30 → 24 of 30 | 0.04 mm → 0.04 mm | 5.49 mm →
5.49 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 15-25 | 20 of 30 → 20 of 30 | 3.47 mm → 3.47 mm | 7.69 mm →
7.69 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0 | 18 of 30 → 18 of 30 | 0.09 mm → 0.09 mm | 3.98 mm →
3.98 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0-7.5 | 19 of 30 → 19 of 30 | 0.45 mm → 0.45 mm | 7.64
mm → 7.64 mm | 6 → 6 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| motion-blur | 7.5-15 | 17 of 30 → 17 of 30 | 0.23 mm → 0.23 mm | 7.84
mm → 7.84 mm | 7 → 7 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| motion-blur | 15-25 | 17 of 30 → 17 of 30 | 6.58 mm → 6.58 mm | 9.77
mm → 9.77 mm | 14 → 14 | 2.01 x 3.92 mm → 2.01 x 3.92 mm | pass |
| hand | 0 | 22 of 30 → 22 of 30 | 0.01 mm → 0.01 mm | 0.14 mm → 0.14 mm
| 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 0-7.5 | 24 of 30 → 24 of 30 | 0.01 mm → 0.01 mm | 0.22 mm →
0.22 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 7.5-15 | 25 of 30 → 25 of 30 | 0.14 mm → 0.14 mm | 5.42 mm →
5.42 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 15-25 | 23 of 30 → 23 of 30 | 4.27 mm → 4.27 mm | 6.44 mm →
6.44 mm | 15 → 15 | 0.00 x 1.81 mm → 0.00 x 1.81 mm | pass |

Empty frames:

| Condition | Tilt | False outlines | Result |
| --- | --- | --: | --- |
| empty-plain | 0 | 0 → 0 | pass |
| empty-plain | 0-7.5 | 0 → 0 | pass |
| empty-plain | 7.5-15 | 0 → 0 | pass |
| empty-plain | 15-25 | 0 → 0 | pass |
| empty-patterned | 0 | 0 → 0 | pass |
| empty-patterned | 0-7.5 | 0 → 0 | pass |
| empty-patterned | 7.5-15 | 0 → 0 | pass |
| empty-patterned | 15-25 | 0 → 0 | pass |

Card frames by condition and border colour, reported:

| Condition | Border colour | Detection rate | Corner error median |
Corner error p90 | Inside outlines | Size error, width x height |
| --- | --- | --: | --: | --: | --: | --: |
| plain | black | 37 of 40 → 37 of 40 | 0.01 mm → 0.01 mm | 5.93 mm →
5.93 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | white | 36 of 40 → 36 of 40 | 0.01 mm → 0.01 mm | 4.48 mm →
4.48 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | borderless | 9 of 40 → 9 of 40 | 0.43 mm → 0.43 mm | 3.91 mm →
3.91 mm | 4 → 4 | 0.01 x 0.02 mm → 0.01 x 0.02 mm |
| patterned | black | 27 of 40 → 27 of 40 | 0.05 mm → 0.05 mm | 8.33 mm
→ 8.33 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | white | 29 of 40 → 29 of 40 | 0.04 mm → 0.04 mm | 8.55 mm
→ 8.55 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | borderless | 5 of 40 → 5 of 40 | 3.01 mm → 3.01 mm | 4.78
mm → 4.78 mm | 3 → 3 | 0.03 x 1.48 mm → 0.03 x 1.48 mm |
| shadow | black | 39 of 40 → 39 of 40 | 3.37 mm → 3.37 mm | 5.82 mm →
5.82 mm | 11 → 11 | -0.13 x -0.92 mm → -0.13 x -0.92 mm |
| shadow | white | 39 of 40 → 39 of 40 | 0.02 mm → 0.02 mm | 5.74 mm →
5.74 mm | 9 → 9 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| shadow | borderless | 17 of 40 → 17 of 40 | 3.86 mm → 3.86 mm | 5.08
mm → 5.08 mm | 7 → 7 | -0.37 x -1.09 mm → -0.37 x -1.09 mm |
| sleeve | black | 40 of 40 → 40 of 40 | 1.43 mm → 1.43 mm | 3.48 mm →
3.48 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| sleeve | white | 39 of 40 → 39 of 40 | 2.23 mm → 2.23 mm | 5.36 mm →
5.36 mm | 8 → 8 | -1.03 x -1.21 mm → -1.03 x -1.21 mm |
| sleeve | borderless | 28 of 40 → 28 of 40 | 1.84 mm → 1.84 mm | 3.32
mm → 3.32 mm | 4 → 4 | -1.18 x -1.14 mm → -1.18 x -1.14 mm |
| glare | black | 39 of 40 → 39 of 40 | 0.01 mm → 0.01 mm | 7.69 mm →
7.69 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | white | 39 of 40 → 39 of 40 | 0.04 mm → 0.04 mm | 4.33 mm →
4.33 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | borderless | 10 of 40 → 10 of 40 | 2.56 mm → 2.56 mm | 3.92 mm
→ 3.92 mm | 6 → 6 | 0.02 x 1.26 mm → 0.02 x 1.26 mm |
| motion-blur | black | 32 of 40 → 32 of 40 | 1.07 mm → 1.07 mm | 9.66
mm → 9.66 mm | 15 → 15 | 0.01 x 0.01 mm → 0.01 x 0.01 mm |
| motion-blur | white | 35 of 40 → 35 of 40 | 0.45 mm → 0.45 mm | 7.60
mm → 7.60 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| motion-blur | borderless | 4 of 40 → 4 of 40 | 0.59 mm → 0.59 mm |
6.19 mm → 6.19 mm | 1 → 1 | 0.00 x -0.01 mm → 0.00 x -0.01 mm |
| hand | black | 40 of 40 → 40 of 40 | 0.01 mm → 0.01 mm | 4.57 mm →
4.57 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | white | 40 of 40 → 40 of 40 | 0.01 mm → 0.01 mm | 5.80 mm →
5.80 mm | 14 → 14 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | borderless | 14 of 40 → 14 of 40 | 0.43 mm → 0.43 mm | 6.44 mm
→ 6.44 mm | 6 → 6 | 0.03 x 0.02 mm → 0.03 x 0.02 mm |

Card frames by border colour and tilt, reported:

| Border colour | Tilt | Detection rate | Corner error median | Corner
error p90 | Inside outlines | Size error, width x height |
| --- | --- | --: | --: | --: | --: | --: |
| black | 0 | 65 of 70 → 65 of 70 | 0.03 mm → 0.03 mm | 2.84 mm → 2.84
mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 0-7.5 | 64 of 70 → 64 of 70 | 0.03 mm → 0.03 mm | 6.26 mm →
6.26 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 7.5-15 | 64 of 70 → 64 of 70 | 0.04 mm → 0.04 mm | 5.49 mm →
5.49 mm | 17 → 17 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 15-25 | 61 of 70 → 61 of 70 | 4.04 mm → 4.04 mm | 8.59 mm →
8.59 mm | 39 → 39 | 0.00 x 0.01 mm → 0.00 x 0.01 mm |
| white | 0 | 65 of 70 → 65 of 70 | 0.02 mm → 0.02 mm | 2.27 mm → 2.27
mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 0-7.5 | 66 of 70 → 66 of 70 | 0.02 mm → 0.02 mm | 3.84 mm →
3.84 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 7.5-15 | 66 of 70 → 66 of 70 | 0.09 mm → 0.09 mm | 8.04 mm →
8.04 mm | 23 → 23 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 15-25 | 60 of 70 → 60 of 70 | 3.84 mm → 3.84 mm | 7.60 mm →
7.60 mm | 39 → 39 | 0.00 x 0.01 mm → 0.00 x 0.01 mm |
| borderless | 0 | 20 of 70 → 20 of 70 | 1.72 mm → 1.72 mm | 3.86 mm →
3.86 mm | 4 → 4 | -0.95 x -0.96 mm → -0.95 x -0.96 mm |
| borderless | 0-7.5 | 20 of 70 → 20 of 70 | 1.46 mm → 1.46 mm | 3.64 mm
→ 3.64 mm | 2 → 2 | -0.03 x -0.09 mm → -0.03 x -0.09 mm |
| borderless | 7.5-15 | 26 of 70 → 26 of 70 | 2.22 mm → 2.22 mm | 3.92
mm → 3.92 mm | 9 → 9 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| borderless | 15-25 | 21 of 70 → 21 of 70 | 3.06 mm → 3.06 mm | 6.19 mm
→ 6.19 mm | 16 → 16 | 0.01 x 1.45 mm → 0.01 x 1.45 mm |

The whole run:

| Metric | Merge base | Branch | Bar | Result |
| --- | --: | --: | --- | --- |
| Mac timing p95 | 4.5 ms | 4.9 ms | at most 1.2 times the merge base |
pass |
| Same detector code | same | same numbers | same numbers | pass |

Bars for each condition and tilt:

- Detection rate: not lower by more than 1
- Corner error median: not worse by more than 0.1 mm
- Corner error p90: not worse by more than 0.5 mm
- Inside outlines: no new one
- False outlines: zero

Every bar passes.

</details>

- **Run time.** From nothing, with the card images downloaded: 2 minutes
33 seconds. Rendering the frames takes about 30 seconds of that on the
M3 (8 cores), and the two builds and two detector runs about 70 seconds.
With the frames already rendered, the replay takes 63 seconds. The
frames take 1.6 GB on disk.
- **Same numbers.** Two full runs gave the same `base.json` and
`branch.json` except timing.
- **Planted regression.** I tightened the aspect gate
(`aspectRatioTolerance` 0.02 to 0.012 in `CardQuadGeometry.swift`), ran
the replay once, then reverted it. The replay exited 1. 20 of the 28
condition and tilt rows failed, and 8 passed: `plain` at 0 and 0-7.5,
`patterned`, `sleeve`, `motion-blur`, and `hand` at 0, and `glare` at 0
and 0-7.5. The list named 29 new inside outlines.
- **Mac timing.** One run failed the Mac timing bar with the same
detector code (5.8 ms against 13.7 ms). Another session was running the
recognizer replay on the same Mac at a load average of about 14. The
next run passed (4.5 ms against 4.9 ms). #505 interleaves the two
builds, which should remove most of this noise.
- **Scorer tests** (`test/detector-replay.test.ts`, 9 tests, 4 new):
bars per condition and tilt bucket, inside outlines per border colour
and tilt bucket, one table row per condition and tilt bucket, and rows
per condition and border colour.
- **Mutation.** Grouping the bars by condition alone turns 2 tests red.
- `typecheck`, `lint`, and the changed test file pass locally.

## Merge Danger

**Door:** two-way

The recipe, the scorer, and the table change. `ios/Detector` and the app
do not change.

**Blast Radius:** tooling

The replay renders 18 times as many frames, so it takes longer and needs
1.6 GB for the frames. It downloads 12 textures, about 11 MB, from Poly
Haven once. Once #505 lands, its frame cache holds the frames. Its cache
does not hold the textures yet.
…se (#501)

**Owner OK needed:** this PR commits the 10 training crops of the #421
A/B (about 1.5 MB) and the Scryfall `normal` images of their 3 card
printings (about 250 KB) as a test fixture. Please approve before merge,
or say to drop or move them.

Part of #498

## Summary

`bun run training-crops:score <folder>` scores a folder that `bun run
crops pull` wrote. It needs no hosted access.

```text
for each card in labels.json
  reference = <images>/<scryfallId>.jpg, downloaded from Scryfall when missing
  starts = SIFT affine fit (ratio test, RANSAC), then scales 1.0, 0.94, 1.06
  correlation, warp = best ECC (affine, Sobel edge images, 488 x 680) over the starts
  if correlation < 0.6
    unscored: no sides, size, or shift
  else
    sides in mm (7.75 px = 1 mm), size, shift
    inside outline = a side more than 1 mm inside the card edge
print totals by app build (recognizer_version), every inside outline, every unscored crop
write crop-scores.json
```

```diff
 apps/mobile/test/scanner-evidence/
+└── training-crops/
+    ├── score.py            # uv script, numpy 2.5.3 and opencv 5.0.0.93 pinned as in simulate.py
+    ├── test_score.py       # bun run training-crops:test
+    └── fixture-421/        # crops/, labels.json, evidence.json as crops pull writes them, and references/
```

README (Training crops) says how to run it after a release. GLOSSARY
adds **Inside outline**.

- The test uses the committed references and does not download. A test
that downloads would depend on the network, and Scryfall can replace a
scan, which would move the numbers. The committed bytes match today's
Scryfall images and the gallery build cache.
- The scale starts stay beside the SIFT start. With the SIFT start
alone, the current detector's Exultant Skymarcher crop gives -1.24 mm
width against -2.2 mm in #421.
- The fixture's evidence records carry only `crop_id`,
`recognizer_version`, `saved_printing_id`, and `feature_print_model`.
The crops were copied off the phone, not pulled, so the other fields
were not recorded. Both A/B builds report `0.0.0 (1)`, so the build
totals test labels the two halves as two builds in a copy of the
fixture.

## Evidence

The #421 table against the scorer, in mm, as "#421 / scorer". Largest
difference: 0.27 mm.

| Detector | Scan | Size, width | Size, height | Shift, horizontal |
Shift, vertical | Correlation | Inside outline |
| --- | --- | --: | --: | --: | --: | --: | --- |
| trial | Vraska, Soul of Stone (foil) | -0.4 / -0.52 | -0.2 / -0.29 |
-0.4 / -0.35 | +0.3 / +0.33 | 0.888 | no |
| trial | Doctor Doom (foil) | -0.1 / -0.10 | -0.3 / -0.31 | -0.8 /
-0.79 | +0.8 / +0.81 | 0.962 | no |
| trial | Exultant Skymarcher | +3.7 / +3.83 | +5.4 / +5.17 | +0.4 /
+0.33 | -0.0 / +0.03 | 0.83 | yes |
| trial | Vraska, Soul of Stone (foil) | +0.7 / +0.71 | +1.0 / +0.99 |
-0.0 / -0.01 | +0.4 / +0.42 | 0.955 | yes |
| trial | Vraska, Soul of Stone (foil) | +0.3 / +0.33 | +0.7 / +0.68 |
-0.6 / -0.58 | +0.5 / +0.58 | 0.884 | yes |
| current | Vraska, Soul of Stone (foil) | -0.1 / -0.19 | -0.0 / -0.03 |
-0.1 / -0.12 | +0.2 / +0.20 | 0.926 | no |
| current | Doctor Doom (foil) | -0.6 / -0.69 | -2.0 / -2.08 | +0.7 /
+0.79 | -0.8 / -0.83 | 0.842 | no |
| current | Exultant Skymarcher | -2.2 / -2.24 | -3.9 / -4.17 | -0.3 /
-0.47 | +1.2 / +1.08 | 0.765 | no |
| current | Vraska, Soul of Stone | +0.0 / -0.02 | -1.0 / -0.99 | -0.2 /
-0.15 | -4.8 / -4.83 | 0.886 | yes |
| current | Vraska, Soul of Stone (foil) | +0.1 / +0.03 | +0.3 / +0.26 |
-0.2 / -0.19 | +0.2 / +0.24 | 0.943 | no |

```text
$ uv run test/scanner-evidence/training-crops/test_score.py -v
test_a_crop_below_the_correlation_floor_is_unscored ... ok
test_it_marks_every_inside_outline_of_the_421_table ... ok
test_it_reproduces_the_421_table_within_0_3_mm ... ok
test_totals_are_split_by_app_build ... ok
Ran 4 tests in 19.4s
OK
```

Mutation checks, each reverted:

- **Before:** no SIFT start. The 4.8 mm shift crop falls below the
correlation floor and is unscored, so the table test errors and the
inside outline and build totals tests fail.
  **After:** all 4 pass.
- **Before:** correlation floor at 0. The Doctor Doom crop labelled as
Vraska is scored, and the unscored test fails.
  **After:** it is unscored.
- **Before:** SIFT start only, no scale starts. The table test fails on
Skymarcher width, -1.24 against -2.2.
  **After:** within 0.3 mm.

The scorer also reads WebP crops. The fixture re-encoded as WebP at
quality 90 scores within 0.05 mm of the JPEGs. Type check and lint pass
in `apps/mobile`. No CI job runs `training-crops:test`, because the app
checks run on Ubuntu without `uv`. It is a local check, like the
recognizer replay.

## Merge Danger

**Door:** two-way

**Blast Radius:** none. It adds an owner script, a fixture, and docs. No
app code changes.
…510)

Part of #497

## Summary

The detector replay now replays 20 short clips through the app's
automatic capture rule. It reports whether a photo is asked for, the
settle time, jitter, and the photo outline. These bars join the replay's
pass or fail, so the CI gate from #495 runs them once it lands.

```text
detector/frames.py
  render_clip            plain, patterned, shadow, sleeve: 5 clips each
    hand path            arrival (25 to 45 mm, rests at 600 ms), slow drift (1 to 8 mm/s), shake (3 to 10 Hz)
    10 frames            720 x 1280, one every 200 ms
    photo                2268 x 4032 JPEG, 100 to 300 ms after the frame at 1,200 ms
replay.ts
  card-detector frames   now also runs every clip frame
detector/clips.ts
  scoreClip
    observeSample        imported from src/scan/capture.ts, not copied
    settle time          first frame until requestPhoto
    photo outline        the held-still outline in fractions of the photo, against the photo's true corners
    hand shift           the same, with the true corners of that frame
    jitter               spread of each corner error on the frames after the card rests
  compareClips           bars per clip condition
```

- The hand path turns the camera about its centre. So the whole scene
moves on the table plane, and each frame keeps the intrinsic matrix in
`labels.json`.
- A clip renders one scene with the scene functions from #496. A `View`
(warp and size) lets the same functions render the photo at photo
resolution. The 1,080 frames keep the same bytes. In `frames.sha256`,
only `labels.json` changes and 220 lines are added.
- The photo has a fixed time, about 400 ms after the outline holds
still. A detector that finds the card on every frame asks for the photo
at 1,200 ms.
- `geometry.ts` holds the homography and the corner alignment. The
frames and the clips both use it.

## Evidence

**Before:** the replay had no clips. Settle time, jitter, and the photo
outline had no measure.

**After:** `bun run detector:replay` against `origin/main` (`a6fcfaf`),
from nothing, on an Apple M3 with macOS 27.0.1 and Xcode 26.3. Every bar
passes. Clips:

| Condition | Photo asked for | Settle time median | Jitter median |
Photo outline median | Hand shift median | Result |
| --- | --: | --: | --: | --: | --: | --- |
| plain | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.02 mm → 0.02 mm | 0.83
mm → 0.83 mm | 0.83 mm → 0.83 mm | pass |
| patterned | 3 of 5 → 3 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
1.04 mm → 1.04 mm | 1.04 mm → 1.04 mm | pass |
| shadow | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.00 mm → 0.00 mm |
1.45 mm → 1.45 mm | 0.60 mm → 0.60 mm | pass |
| sleeve | 5 of 5 → 5 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
2.79 mm → 2.79 mm | 0.94 mm → 0.94 mm | pass |

- **Hand movement shows on `main`, as in #421.** The hand moves the card
0.3 to 2.1 mm between the sample that held still and the photo, 0.9 mm
at the median. On the 7 clips whose held-still outline sits on the card
edge, the photo outline error is that shift: 0.2 to 1.7 mm. On the other
clips, the inner frame or the sleeve edge adds to it. #421 measured 0.1
to 4.8 mm on the phone.
- 16 of 20 clips ask for a photo. 3 of the 4 that don't show a
borderless card, which the detector misses on every surface.
- **Same numbers.** A render from nothing matched `frames.sha256`. The
scores matched an earlier run except timing.
- **Planted regression.** I raised the edge support gate in
`DetectionSample.swift` from 0.7 to 0.9, ran the replay once, then
reverted it. The replay exited 1. `patterned` fell from 3 to 2 photos
asked for, and `sleeve` from 5 to 4. It named `patterned-clip-003` and
`sleeve-clip-002` as clips that stopped asking for a photo.
- **Scorer tests** (`test/detector-replay.test.ts`, 8 new, 17 in all):
settle time through `observeSample`, photo outline and hand shift, an
inner-frame outline in the photo outline, jitter only after the card
rests, the photo asked for, settle time, jitter, and photo outline bars,
and the clips table.
- `typecheck`, `lint`, and the changed test file pass locally.

## Merge Danger

**Door:** two-way

The recipe, the scorer, and the README change. `ios/Detector` and the
app do not change.

**Blast Radius:** tooling

- The replay renders 20 photos at 2268 x 4032. A run from nothing took 3
minutes 38 seconds on a busy M3. The frames take 1.9 GB.
- `frames.sha256` changes, so the frame cache from #495 misses once.
- When #495 lands, its `step` mode and timing rounds change `replay.ts`
and `scoreReplay`. The clip frames then need to go into its frame list.

## Assumptions

- The photo is 2268 x 4032. That is a 12 MP photo with the frame's 9:16
aspect. The app takes the largest 16:9 photo the format supports, and
its size on the iPhone 16e is not recorded.
- The analysis rate is one frame every 200 ms: the 0.19 s interval on a
30 fps camera.
- The photo comes 100 to 300 ms after the sample that asks for it. This
delay is not measured on the phone.
- Until photo refinement (#499) sets its 0.5 mm bar, the photo outline
median may not be worse than the merge base by more than 0.1 mm, the
corner error median bar.
- "Not fewer" photos asked for applies to every surface, not only
patterned.
- Jitter compares at 0.01 mm, the table's precision.
Part of #495

## Summary

The Detector workflow has a new `replay` job. It runs `bun run
detector:replay` on a `macos-15` runner, with the PR's base branch as
`--base`. The branch and the merge base run in the same job, so Vision
and the hardware are the same on both sides. A missed bar fails the job,
and the job summary shows the table under a "Detector replay" heading.

```text
Detector workflow
  fixtures   bun run detector:test                       (unchanged)
  module     xcodebuild for the Simulator                (unchanged)
+ replay
+   restore the card images   (cache key: detector/cards.json)
+   restore the textures      (cache key: detector/textures.json)
+   restore the frames        (cache key: detector/frames.sha256)
+   bun run detector:replay --base origin/<base branch, or main when run by hand>
+   append "## Detector replay" and comparison.md to the job summary, even when a bar fails
```

The timing is less noisy now. Before, the replay ran all 60 frames on
the merge base, then all 60 on the branch, and took the p95 of those 60
calls.

```diff
 detector:replay
-  card-detector frames <every frame>        base first, then branch
-  Mac timing = p95 of 60 calls
+  card-detector step <every frame and clip frame>   base and branch start together and read their frames once
+  round 1: every frame and clip frame; rounds 2 and 3: the frames
+  for each of them
+    detect on base and on branch, back to back
+    swap which side goes first on each frame and each round
+  outlines and clips from the first round
+  Mac timing = p95 over frames of each frame's median time over the rounds
```

- `step` is a new mode of the macOS detector command. It reads frame
indices on its input and writes one JSON line for each. `frames` stays
for use by hand.
- `--rounds <n>` sets the number of rounds. The default is 3.
- The merge base on `spec/493-detector-replay` has a command without
`step`. So the fallback rule now reads: "when the merge base has no
detector command with the `step` mode, build the branch's command with
the merge base's detector files". Before, the rule was "no detector
command".
- `comparison.md` now starts with the commits, the base ref, and the
number of rounds.
- The workflow also runs on changes to
`apps/mobile/test/scanner-evidence/detector/**` and to the automatic
capture rule in `apps/mobile/src/scan/capture.ts`, which the clips use.
- The job caches the card images, the textures, and the rendered frames.
- The README describes how CI runs the replay and how a PR shows its
table. A PR that changes the card detector copies the table from the job
summary under a "Detector replay" heading, and links the run.

## Evidence

**A missed bar fails the job.** I planted the regression from #502 on a
throwaway branch: `outwardness <` in `CardEdgeRefiner.swift`, so the
edge refiner picks the innermost lines. Then I ran the workflow by hand:
[run
39546178053](https://github.com/Reilley64/mtgscan/actions/runs/39546178053).
The replay job failed with exit code 1, and the job summary got the
table and the list of failing outlines. I deleted the branch after the
run. The fixtures job failed too, as it should.

| Condition | Metric | Merge base | Branch | Bar | Result |
| --- | --- | --: | --: | --- | --- |
| plain | Detection rate | 21 of 30 | 21 of 30 | not lower by more than
1 | pass |
| plain | Corner error median | 0.01 mm | 9.99 mm | not worse by more
than 0.1 mm | fail |
| plain | Corner error p90 | 0.07 mm | 11.55 mm | not worse by more than
0.5 mm | fail |
| plain | Inside outlines | 1 | 18 | no new one | fail |
| plain | Size error, width x height | 0.00 mm x -0.00 mm | 4.14 mm x
5.62 mm | reported | |
| empty-plain | False outlines | 0 | 0 | zero | pass |
| | Mac timing p95 | 67.1 ms | 66.8 ms | at most 1.2 times the merge
base | pass |

**Job time, with the 1,080 frames from #506 and the 20 clips from
#497.** The workflow timeout is 30 minutes.

| Run | Frames | Frames cache | Replay job |
| --- | --- | --- | --: |
| [PR, final
head](https://github.com/Reilley64/mtgscan/actions/runs/39578379495) |
1,080 and 20 clips | hit | 10 min 6 s |
| [PR](https://github.com/Reilley64/mtgscan/actions/runs/39573404410) |
1,080 and 20 clips | miss | 8 min 36 s |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39573456606) |
1,080 and 20 clips | miss | 12 min 32 s |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39576758186) |
1,080 and 20 clips | hit, 25 s to restore | 11 min 16 s |
| [PR](https://github.com/Reilley64/mtgscan/actions/runs/39552916165) |
1,080 | miss | 9 min 16 s |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39555007902) |
1,080 | miss | 11 min 56 s |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39556431307) |
1,080 | hit, 42 s to restore | 10 min 16 s |
| first PR run | 60 | miss | 1 min 42 s |

- The runner rendered every frame, clip frame, and photo with the same
bytes as `frames.sha256`. The replay checks the hashes on every run,
also after a cache restore. A mismatch fails the job and names the first
frame that differs.
- The frames cache holds the frames, the clip frames, and the photos,
1.9 GB. The textures from #506 have their own cache, keyed by
`detector/textures.json`.
- The detector calls take most of the job: 3 rounds of the 1,080 frames
and one round of the clip frames, on both sides. One call takes 45 to
100 ms on the runner. Without the cache, the render takes about 1.5
minutes.
- Clip frames run once, in the first round. Only the frames count for
Mac timing.

**Timing noise.** Vision is about 20 times slower on the runner than on
an M3. One detector call takes 60 to 100 ms there. These are CI runs
with the same detector code on both sides. The first 7 used the first 60
frames:

| Run | Rounds | Merge base | Branch | Ratio |
| --- | --: | --: | --: | --: |
| [PR, first
push](https://github.com/Reilley64/mtgscan/actions/runs/39546152968) | 5
| 57.8 ms | 59.7 ms | 1.03 |
| [planted
run](https://github.com/Reilley64/mtgscan/actions/runs/39546178053) | 5
| 67.1 ms | 66.8 ms | 1.00 |
| [PR, second
push](https://github.com/Reilley64/mtgscan/actions/runs/39548592954) | 3
| 98.6 ms | 96.4 ms | 0.98 |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39548853311) | 3
| 71.5 ms | 70.7 ms | 0.99 |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39549088491) | 3
| 67.9 ms | 64.6 ms | 0.95 |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39549379328) | 3
| 92.7 ms | 86.2 ms | 0.93 |
| [by
hand](https://github.com/Reilley64/mtgscan/actions/runs/39549715695) | 3
| 71.9 ms | 72.0 ms | 1.00 |
| [PR, 1,080
frames](https://github.com/Reilley64/mtgscan/actions/runs/39552916165) |
3 | 64.1 ms | 64.0 ms | 1.00 |
| [by hand, 1,080
frames](https://github.com/Reilley64/mtgscan/actions/runs/39555007902) |
3 | 82.8 ms | 84.9 ms | 1.03 |
| [by hand, 1,080
frames](https://github.com/Reilley64/mtgscan/actions/runs/39556431307) |
3 | 76.3 ms | 76.2 ms | 1.00 |
| [PR, with
clips](https://github.com/Reilley64/mtgscan/actions/runs/39573404410) |
3 | 46.3 ms | 46.0 ms | 0.99 |
| [PR, final
head](https://github.com/Reilley64/mtgscan/actions/runs/39578379495) | 3
| 71.1 ms | 71.7 ms | 1.01 |
| [by hand, with
clips](https://github.com/Reilley64/mtgscan/actions/runs/39573456606) |
3 | 83.6 ms | 85.8 ms | 1.03 |
| [by hand, with
clips](https://github.com/Reilley64/mtgscan/actions/runs/39576758186) |
3 | 86.0 ms | 88.8 ms | 1.03 |

On my M3, busy with other work, 10 runs of each method with the same
detector code gave these ratios:

| Method | Lowest | Highest | Over 1.2 |
| --- | --: | --: | --: |
| Before: base pass, then branch pass, p95 of 60 calls | 0.71 | 1.70 | 1
of 10 |
| Interleaved, 1 round | 0.59 | 1.05 | 0 |
| Interleaved, 3 rounds | 0.96 | 1.04 | 0 |
| Interleaved, 5 rounds | 0.96 | 1.04 | 0 |

**Scorer tests** (`test/detector-replay.test.ts`, 19 tests with those
from #506 and #497). Two are new:

```text
one slow round does not fail the Mac timing bar when the other rounds hold steady
  base [4, 4, 4] ms, branch [4, 40, 4] ms  ->  4.0 ms against 4.0 ms, pass
a branch slower than 1.2 times the merge base on most rounds fails the Mac timing bar
  base [4, 4, 4] ms, branch [4, 5, 5] ms   ->  5.0 ms against 4.0 ms, fail
```

- Mutation: timing from the first round only turns the second test red.
- Mutation: timing from the slowest round turns the first test red.
- `bun run detector:test` (14 tests), `typecheck`, and `lint` pass
locally.

Local replay of this branch against `origin/spec/493-detector-replay`,
with the clips (Apple M3, macOS 27.0.1, Xcode 26.3): every bar passes,
Mac timing p95 6.5 ms against 6.5 ms, and the clip table matches #497's
numbers. The run took 2 min 7 s with the frames already rendered.

## Merge Danger

**Door:** two-way

The job, the `step` mode, and the rounds are tooling. `ios/Detector` and
the app do not change.

**Blast Radius:** CI

Every detector PR now runs the replay, and a missed bar blocks it. The
runner's macOS gives other numbers than macOS 27 on the M3, such as 21
of 30 plain frames detected at no tilt against 22. Both sides run in the
same job, so the comparison holds. The job now takes 8.5 to 12.5
minutes. Each new PR saves 1.9 GB of frames to the Actions cache,
because PRs share no cache. Both commands hold every frame buffer in
memory, about 1.5 GB each with 1,080 frames, plus 14 MB for each photo.
Part of #500

## Summary

`takePhoto` now returns the photo outline from photo refinement. The
recognizer and the JavaScript interface do not change.

```diff
 CameraSession.captureOutput            (frame loop)
   CardQuadDetector.detect
+  keep the pixel buffer and outline of the last frame with a detected card
 CameraSession.takePhoto(held-still outline)
+  take the kept frame if its outline is the held-still outline
   capturePhoto
     photoOutput(didFinishProcessingPhoto)   (outside the frame loop)
+      PhotoOutline.refine(photo, frame, held-still outline)
+        read the photo at the analysis size, as luma
+        VNHomographicImageRegistrationRequest: frame against photo
+        moved outline = held-still outline moved by that motion
+        CardEdgeRefiner.refine(proposal: moved outline) on the photo
+        size check:   refuse an outline more than 2% narrower or shorter than the moved one
+        motion check: refuse a corner more than 2% of the short side from the moved one
+        on a refusal or an error: the held-still outline
-  return photo + held-still outline
+  return photo + photo outline
```

- `card-detector refine <frame> <photo> <outline JSON>` runs
`PhotoOutline.refine`, and the `step` mode takes the same request as a
JSON line. The detector replay asks each side for the photo outline of
every clip that asks for a photo. A merge base with no refine mode keeps
the held-still outline.
- New clip bars: **Photo outline median, held still on the card edge**
below 0.5 mm, and **Inside photo outlines** no new one. The "not worse
by 0.1 mm" photo outline bar stays.
- The camera session logs to the unified log (`dev.reilley.mtgscan`,
`card-detector`): the zero shutter lag and geometric distortion
correction state when the camera starts, and the outcome, time, and
photo-after-frame delay of each photo refinement.
- README, the scanner evidence pack README, and `GLOSSARY.md` (**Photo
refinement**) describe it. The evidence README records the replay
results behind both refusal limits.

## Evidence

### Detector replay

From the CI job summary of the [Detector workflow
run](https://github.com/Reilley64/mtgscan/actions/runs/39587720379)
(replay job), against the integration branch:

The branch at c44b7cf against the merge base 1e68ee5 with
origin/spec/493-detector-replay, 3 timing rounds.

Card frames by condition and tilt in degrees, merge base → branch:

| Condition | Tilt | Detection rate | Corner error median | Corner error
p90 | Inside outlines | Size error, width x height | Result |
| --- | --- | --: | --: | --: | --: | --: | --- |
| plain | 0 | 21 of 30 → 21 of 30 | 0.01 mm → 0.01 mm | 0.07 mm → 0.07
mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 0-7.5 | 18 of 30 → 18 of 30 | 0.01 mm → 0.01 mm | 0.01 mm →
0.01 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 7.5-15 | 21 of 30 → 21 of 30 | 0.02 mm → 0.02 mm | 5.41 mm →
5.41 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 15-25 | 20 of 30 → 20 of 30 | 3.69 mm → 3.69 mm | 5.60 mm →
5.60 mm | 12 → 12 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| patterned | 0 | 12 of 30 → 12 of 30 | 0.02 mm → 0.02 mm | 4.64 mm →
4.64 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 0-7.5 | 18 of 30 → 18 of 30 | 0.05 mm → 0.05 mm | 4.89 mm
→ 4.89 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 7.5-15 | 16 of 30 → 16 of 30 | 0.03 mm → 0.03 mm | 8.04 mm
→ 8.04 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 15-25 | 15 of 30 → 15 of 30 | 3.69 mm → 3.69 mm | 9.61 mm
→ 9.61 mm | 11 → 11 | 1.81 x 1.49 mm → 1.81 x 1.49 mm | pass |
| shadow | 0 | 24 of 30 → 24 of 30 | 2.12 mm → 2.12 mm | 4.84 mm → 4.84
mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 0-7.5 | 22 of 30 → 22 of 30 | 0.96 mm → 0.96 mm | 5.11 mm →
5.11 mm | 3 → 3 | -0.03 x -0.47 mm → -0.03 x -0.47 mm | pass |
| shadow | 7.5-15 | 27 of 30 → 27 of 30 | 2.95 mm → 2.95 mm | 5.84 mm →
5.84 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 15-25 | 20 of 30 → 20 of 30 | 4.15 mm → 4.15 mm | 5.92 mm →
5.92 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| sleeve | 0 | 29 of 30 → 29 of 30 | 1.68 mm → 1.68 mm | 2.31 mm → 2.31
mm | 0 → 0 | -1.08 x -1.14 mm → -1.08 x -1.14 mm | pass |
| sleeve | 0-7.5 | 25 of 30 → 25 of 30 | 1.51 mm → 1.51 mm | 2.26 mm →
2.26 mm | 1 → 1 | -1.01 x -0.97 mm → -1.01 x -0.97 mm | pass |
| sleeve | 7.5-15 | 28 of 30 → 28 of 30 | 1.95 mm → 1.95 mm | 3.43 mm →
3.43 mm | 5 → 5 | -0.67 x -0.63 mm → -0.67 x -0.63 mm | pass |
| sleeve | 15-25 | 26 of 30 → 26 of 30 | 3.35 mm → 3.35 mm | 5.79 mm →
5.79 mm | 18 → 18 | -0.02 x 0.01 mm → -0.02 x 0.01 mm | pass |
| glare | 0 | 22 of 30 → 22 of 30 | 0.02 mm → 0.02 mm | 0.10 mm → 0.10
mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0-7.5 | 23 of 30 → 23 of 30 | 0.02 mm → 0.02 mm | 6.26 mm →
6.26 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 7.5-15 | 24 of 30 → 24 of 30 | 0.04 mm → 0.04 mm | 5.49 mm →
5.49 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 15-25 | 19 of 30 → 19 of 30 | 3.60 mm → 3.60 mm | 8.46 mm →
8.46 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0 | 17 of 30 → 17 of 30 | 0.09 mm → 0.09 mm | 4.74 mm →
4.74 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0-7.5 | 20 of 30 → 20 of 30 | 0.29 mm → 0.29 mm | 6.89
mm → 6.89 mm | 7 → 7 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| motion-blur | 7.5-15 | 18 of 30 → 18 of 30 | 0.23 mm → 0.23 mm | 10.75
mm → 10.75 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 15-25 | 15 of 30 → 15 of 30 | 7.22 mm → 7.22 mm | 11.08
mm → 11.08 mm | 12 → 12 | 2.00 x 4.36 mm → 2.00 x 4.36 mm | pass |
| hand | 0 | 21 of 30 → 21 of 30 | 0.01 mm → 0.01 mm | 0.10 mm → 0.10 mm
| 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 0-7.5 | 23 of 30 → 23 of 30 | 0.01 mm → 0.01 mm | 0.08 mm →
0.08 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 7.5-15 | 23 of 30 → 23 of 30 | 0.05 mm → 0.05 mm | 4.91 mm →
4.91 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 15-25 | 24 of 30 → 24 of 30 | 4.27 mm → 4.27 mm | 7.21 mm →
7.21 mm | 16 → 16 | 0.00 x 1.81 mm → 0.00 x 1.81 mm | pass |

Empty frames:

| Condition | Tilt | False outlines | Result |
| --- | --- | --: | --- |
| empty-plain | 0 | 0 → 0 | pass |
| empty-plain | 0-7.5 | 0 → 0 | pass |
| empty-plain | 7.5-15 | 0 → 0 | pass |
| empty-plain | 15-25 | 0 → 0 | pass |
| empty-patterned | 0 | 0 → 0 | pass |
| empty-patterned | 0-7.5 | 0 → 0 | pass |
| empty-patterned | 7.5-15 | 0 → 0 | pass |
| empty-patterned | 15-25 | 0 → 0 | pass |

Clips by condition, merge base → branch:

| Condition | Photo asked for | Settle time median | Jitter median |
Photo outline median | Photo outline median, held still on the card edge
| Inside photo outlines | Hand shift median | Result |
| --- | --: | --: | --: | --: | --: | --: | --: | --- |
| plain | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.02 mm → 0.02 mm | 0.83
mm → 0.03 mm | 0.83 mm → 0.03 mm | 1 → 1 | 0.83 mm → 0.83 mm | pass |
| patterned | 3 of 5 → 3 of 5 | 1200 ms → 1200 ms | 0.05 mm → 0.05 mm |
1.04 mm → 0.05 mm | 0.19 mm → 0.02 mm | 1 → 1 | 1.04 mm → 1.04 mm | pass
|
| shadow | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.00 mm → 0.00 mm |
1.46 mm → 0.04 mm | 0.60 mm → 0.03 mm | 1 → 0 | 0.60 mm → 0.60 mm | pass
|
| sleeve | 5 of 5 → 5 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
2.79 mm → 1.95 mm | none → none | 1 → 1 | 1.03 mm → 1.03 mm | pass |

Card frames by condition and border colour, reported:

| Condition | Border colour | Detection rate | Corner error median |
Corner error p90 | Inside outlines | Size error, width x height |
| --- | --- | --: | --: | --: | --: | --: |
| plain | black | 37 of 40 → 37 of 40 | 0.01 mm → 0.01 mm | 5.94 mm →
5.94 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | white | 35 of 40 → 35 of 40 | 0.01 mm → 0.01 mm | 4.48 mm →
4.48 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | borderless | 8 of 40 → 8 of 40 | 1.33 mm → 1.33 mm | 4.05 mm →
4.05 mm | 4 → 4 | 0.02 x 0.02 mm → 0.02 x 0.02 mm |
| patterned | black | 27 of 40 → 27 of 40 | 0.06 mm → 0.06 mm | 5.49 mm
→ 5.49 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | white | 28 of 40 → 28 of 40 | 0.03 mm → 0.03 mm | 8.04 mm
→ 8.04 mm | 11 → 11 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | borderless | 6 of 40 → 6 of 40 | 3.01 mm → 3.01 mm | 4.78
mm → 4.78 mm | 4 → 4 | 0.04 x 1.46 mm → 0.04 x 1.46 mm |
| shadow | black | 38 of 40 → 38 of 40 | 3.37 mm → 3.37 mm | 5.84 mm →
5.84 mm | 11 → 11 | -0.19 x -0.96 mm → -0.19 x -0.96 mm |
| shadow | white | 38 of 40 → 38 of 40 | 0.02 mm → 0.02 mm | 6.84 mm →
6.84 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| shadow | borderless | 17 of 40 → 17 of 40 | 3.63 mm → 3.63 mm | 5.08
mm → 5.08 mm | 9 → 9 | -0.20 x -0.28 mm → -0.20 x -0.28 mm |
| sleeve | black | 40 of 40 → 40 of 40 | 1.47 mm → 1.47 mm | 3.60 mm →
3.60 mm | 11 → 11 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| sleeve | white | 40 of 40 → 40 of 40 | 2.23 mm → 2.23 mm | 5.40 mm →
5.40 mm | 9 → 9 | -1.07 x -1.21 mm → -1.07 x -1.21 mm |
| sleeve | borderless | 28 of 40 → 28 of 40 | 1.86 mm → 1.86 mm | 3.35
mm → 3.35 mm | 4 → 4 | -1.20 x -1.15 mm → -1.20 x -1.15 mm |
| glare | black | 39 of 40 → 39 of 40 | 0.01 mm → 0.01 mm | 7.85 mm →
7.85 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | white | 39 of 40 → 39 of 40 | 0.03 mm → 0.03 mm | 4.33 mm →
4.33 mm | 10 → 10 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | borderless | 10 of 40 → 10 of 40 | 1.28 mm → 1.28 mm | 3.98 mm
→ 3.98 mm | 5 → 5 | 0.02 x 0.00 mm → 0.02 x 0.00 mm |
| motion-blur | black | 33 of 40 → 33 of 40 | 4.74 mm → 4.74 mm | 9.66
mm → 9.66 mm | 18 → 18 | 1.86 x 1.77 mm → 1.86 x 1.77 mm |
| motion-blur | white | 33 of 40 → 33 of 40 | 0.29 mm → 0.29 mm | 10.82
mm → 10.82 mm | 11 → 11 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| motion-blur | borderless | 4 of 40 → 4 of 40 | 0.59 mm → 0.59 mm |
6.19 mm → 6.19 mm | 1 → 1 | 0.01 x 0.23 mm → 0.01 x 0.23 mm |
| hand | black | 40 of 40 → 40 of 40 | 0.01 mm → 0.01 mm | 4.59 mm →
4.59 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | white | 38 of 40 → 38 of 40 | 0.01 mm → 0.01 mm | 5.51 mm →
5.51 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | borderless | 13 of 40 → 13 of 40 | 0.16 mm → 0.16 mm | 7.21 mm
→ 7.21 mm | 6 → 6 | 0.02 x 0.02 mm → 0.02 x 0.02 mm |

Card frames by border colour and tilt, reported:

| Border colour | Tilt | Detection rate | Corner error median | Corner
error p90 | Inside outlines | Size error, width x height |
| --- | --- | --: | --: | --: | --: | --: |
| black | 0 | 64 of 70 → 64 of 70 | 0.02 mm → 0.02 mm | 3.37 mm → 3.37
mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 0-7.5 | 64 of 70 → 64 of 70 | 0.03 mm → 0.03 mm | 6.38 mm →
6.38 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 7.5-15 | 65 of 70 → 65 of 70 | 0.04 mm → 0.04 mm | 6.22 mm →
6.22 mm | 17 → 17 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 15-25 | 61 of 70 → 61 of 70 | 4.04 mm → 4.04 mm | 9.61 mm →
9.61 mm | 40 → 40 | 0.03 x 0.01 mm → 0.03 x 0.01 mm |
| white | 0 | 64 of 70 → 64 of 70 | 0.02 mm → 0.02 mm | 2.26 mm → 2.26
mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 0-7.5 | 64 of 70 → 64 of 70 | 0.02 mm → 0.02 mm | 2.26 mm →
2.26 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 7.5-15 | 65 of 70 → 65 of 70 | 0.13 mm → 0.13 mm | 8.72 mm →
8.72 mm | 23 → 23 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 15-25 | 58 of 70 → 58 of 70 | 3.72 mm → 3.72 mm | 8.39 mm →
8.39 mm | 37 → 37 | 0.00 x 0.01 mm → 0.00 x 0.01 mm |
| borderless | 0 | 18 of 70 → 18 of 70 | 1.72 mm → 1.72 mm | 4.33 mm →
4.33 mm | 5 → 5 | -0.95 x -0.96 mm → -0.95 x -0.96 mm |
| borderless | 0-7.5 | 21 of 70 → 21 of 70 | 1.46 mm → 1.46 mm | 3.63 mm
→ 3.63 mm | 3 → 3 | -0.01 x -0.01 mm → -0.01 x -0.01 mm |
| borderless | 7.5-15 | 27 of 70 → 27 of 70 | 2.40 mm → 2.40 mm | 3.98
mm → 3.98 mm | 9 → 9 | -0.01 x 0.00 mm → -0.01 x 0.00 mm |
| borderless | 15-25 | 20 of 70 → 20 of 70 | 3.86 mm → 3.86 mm | 6.44 mm
→ 6.44 mm | 16 → 16 | 0.00 x 1.47 mm → 0.00 x 1.47 mm |

The whole run:

| Metric | Merge base | Branch | Bar | Result |
| --- | --: | --: | --- | --- |
| Mac timing p95 | 42.3 ms | 42.5 ms | at most 1.2 times the merge base
| pass |

Bars for each condition and tilt:

- Detection rate: not lower by more than 1
- Corner error median: not worse by more than 0.1 mm
- Corner error p90: not worse by more than 0.5 mm
- Inside outlines: no new one
- False outlines: zero

Bars for each clip condition:

- Photo asked for: not fewer
- Settle time median: not worse
- Jitter median: not worse, to 0.01 mm
- Photo outline median: not worse by more than 0.1 mm
- Photo outline median, held still on the card edge: below 0.5 mm
- Inside photo outlines: no new one

Every bar passes.

Photo refinement on the merge base: none, its detector command has no
refine mode.

Photo refinement on the branch: 16 refined, of 16 clips that ask for a
photo. Median 76 ms on the Mac.

Refusal limits, from the replay (details in the scanner evidence pack
README, Photo refinement):

| Check | Accepted outlines on the replay | Outlines it must refuse |
| --- | --- | --- |
| Size, 2% | within 0.4% of the moved size | inner frame, 6% to 9%
smaller (run from the true card edge) |
| Motion, 2% of the short side | 14 of 15 move at most 0.4% | sleeve or
shadow edge jumps, 2.9% to 3.7% |

Vision's registration puts the moved outline within 0.2 mm of the card
on all 20 photos when the held-still outline is the true card edge.
Photo refinement takes 34 to 50 ms at the median on an Apple M3, and 76
to 117 ms on the CI runner over two runs. On the M3, the motion check
refuses one sleeve clip at 15 to 25 degrees of tilt, which keeps its
held-still outline. On the CI runner, all 16 pass. The detector's frame
loop does not change, and Mac timing p95 holds.

### Fixture tests (`bun run detector:test`, 20 pass)

```text
keeps a photo outline within the size and motion checks
refuses a photo outline more than 2% smaller than the moved outline, and keeps the held-still outline   (97% wide, 97% tall, 90% both)
refuses a photo outline whose corners sit far from the moved outline, and keeps the held-still outline
keeps the held-still outline when the edge refiner finds no outline on the photo
keeps the held-still outline when the photo cannot be read
moves the held-still outline onto the card in a photo taken after the hand moved   (JPEG photo at 2x, card moved 14 x -10 px and turned)
```

Mutation checks, each red:

- size check off: the size refusal test fails
- motion check off: the motion refusal test fails
- a refusal returns the moved outline: the size refusal test fails on
every argument
- no y flip in the registration mapping: the hand-moved photo test
fails, 20.6 px off
- scorer ignores the refined photo outline, the 0.5 mm bar always
passes, or the inside photo outlines bar always passes: the matching
Jest test fails

Jest `test/detector-replay.test.ts` 23 pass. Type check and lint pass.
CameraSession and the detector files type-check against the iOS 17 SDK
in Swift 6 mode.

### Not yet measured: device check on the iPhone

Done later by the owner with a development build. Scan with a hand that
moves, and measure the training crops as in #421. In Console.app, filter
subsystem `dev.reilley.mtgscan`, category `card-detector`:

- `camera: zero shutter lag supported …, enabled …; geometric distortion
correction supported …, enabled …; photo W x H`. Record whether zero
shutter lag is on with the app's capture format, and whether geometric
distortion correction is on. The flag is on the device, so it does not
show by itself that the frame and the photo get the same correction. The
photo outline error near the frame edges, in the training crops, does.
- `photo outline: <refined | size_refused | motion_refused | not_refined
| failed> in N ms, photo M ms after the frame`. N is the photo
refinement time on the iPhone, inside the recognition budget (bin-deck
run p95 1.5 s). M below about 0 ms means the photo came from before the
frame, with zero shutter lag.
- `photo outline: held still, no analyzed frame with this outline`
should not show. It would mean the outline from JavaScript did not match
the kept frame.

## Merge Danger

**Door:** two-way

Revert the commit to go back to the held-still outline.

**Blast Radius:** scanning

Every scan photo is straightened along the new outline. A wrong photo
outline would hurt recognition. The checks and the fallback keep the
held-still outline whenever photo refinement is unsure. The camera
session keeps one analyzed pixel buffer alive between frames.
…atrix (#515)

Part of #499

## Summary

The card aspect gate now checks the aspect on the card, not in the
frame.

```diff
 CameraSession.captureOutput
+  intrinsicMatrix = sampleBuffer attachment kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix
-  CardQuadDetector.detect(pixelBuffer, .right)
+  CardQuadDetector.detect(pixelBuffer, .right, intrinsicMatrix)
+    orientedMatrix = transform.orientedIntrinsicMatrix(intrinsicMatrix)   # landscape buffer -> upright frame
     CardEdgeRefiner.refine(proposal, plane, transform, orientedMatrix)
       for each candidate quad
-        aspect = mean side ratio in the frame;   pass if |aspect - 63/88| <= 0.02
+        if orientedMatrix
+          aspect = CardQuadGeometry.aspectRatioOnCard(quad, orientedMatrix);   pass if |aspect - 63/88| <= 0.012
+        else
+          aspect = mean side ratio in the frame;   pass if |aspect - 63/88| <= 0.02
```

- `aspectRatioOnCard` is the Zhang and He rectangle aspect from one
view. It is pure geometry, a few dozen operations per candidate quad.
- The camera session turns on intrinsic matrix delivery on the video
connection.
- The detector replay command takes each frame's matrix after the frame
index on its input. It turns the portrait matrix from `labels.json` into
the landscape matrix the camera gives, and passes it to the detector.
The replay sends the matrix only to a command whose source names
`intrinsicMatrix`, so the merge base command still runs.
- The `photo-requested` capture event logs the `aspectRatio` that the
gate checked.
- Photo refinement (#514) calls the edge refiner on the photo with no
matrix, so it keeps the check in the frame there.
- The replay scorer changes its bars, as the owner decided:
- **Detection rate** counts correct outlines only: all four corners
within 1 mm of the true corners. The allowance stays at 1 frame in 30.
- **Wrong outlines** is a new metric for each group: detected outlines
that are not correct. Bar: not more than the merge base.
- **Corner error** median and p90 bars compare the frames with a correct
outline on both the merge base and the branch. They apply when a group
has at least 10 such frames (`minimumPairedFrames`). A smaller group is
reported. The bars stay the same. The table still shows each side's own
median and p90 over its correct outlines.
- **Inside outlines** compares the count of each condition and tilt
group: not more than the merge base plus 1 frame in 30. The replay still
lists each new inside outline, for information.
- The Detector workflow uploads `base.json`, `branch.json`, and
`comparison.md` as the `detector-replay-reports` artifact, also when a
bar fails.
- The README describes the gate. The scanner evidence pack README
describes the matrix on the command input.

Tolerance on the card: 0.012. The research model of an inner frame (a
2.4 to 3.4 mm black border on the replay's cards) is 0.016 or more off
63:88, so it fails. A sleeve up to about 1.9 mm still passes. A frame
with no matrix keeps 0.02 in the frame.

## Evidence

Swift fixture tests (`bun run detector:test`), new:

```text
measures the card aspect on the card from the intrinsic matrix at known camera poses   (4 poses, 7 to 24 degrees)
measures a flat card's aspect as today's check in the frame does
passes the outer edge and refuses the inner frame of a tilted black-bordered card    (3 poses up to 15 degrees, 2.4 mm border)
maps the landscape camera's intrinsic matrix to the portrait frame
finds the outer edge of a tilted black-bordered card with the camera's intrinsic matrix   (detect() end to end, < 1.5 px)
keeps today's check in the frame for a frame with no intrinsic matrix                    (same frame, outline not on the outer edge)
```

Mutation checks, each turns tests red:

- tolerance on the card back to 0.02: the inner-frame test fails.
- no landscape to portrait mapping of the matrix: the mapping test and
the end-to-end test fail.
- `metrics` ignores the matrix: the inner-frame and end-to-end tests
fail.
- the detector does not pass the matrix to the edge refiner: the
end-to-end test fails.

### Detector replay

From the CI job summary of [run 39618471816, job
replay](https://github.com/Reilley64/mtgscan/actions/runs/39618471816/job/119285329734),
merge base with `origin/spec/493-detector-replay`. Every bar passes. The
per-frame results are in its `detector-replay-reports` artifact.

Card frames by condition and tilt in degrees, merge base → branch:

| Condition | Tilt | Detection rate | Wrong outlines | Corner error
median | Corner error p90 | Inside outlines | Size error, width x height
| Result |
| --- | --- | --: | --: | --: | --: | --: | --: | --- |
| plain | 0 | 20 of 30 → 20 of 30 | 1 → 1 | 0.01 mm → 0.01 mm | 0.03 mm
→ 0.03 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 0-7.5 | 18 of 30 → 18 of 30 | 0 → 0 | 0.01 mm → 0.01 mm | 0.01
mm → 0.01 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 7.5-15 | 12 of 30 → 17 of 30 | 9 → 2 | 0.01 mm → 0.01 mm |
0.02 mm → 0.03 mm | 8 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 15-25 | 8 of 30 → 17 of 30 | 12 → 3 | 0.01 mm → 0.01 mm | 0.06
mm → 0.03 mm | 12 → 2 | 0.00 x 0.01 mm → 0.00 x 0.00 mm | pass |
| patterned | 0 | 10 of 30 → 10 of 30 | 2 → 1 | 0.02 mm → 0.02 mm | 0.06
mm → 0.06 mm | 2 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 0-7.5 | 13 of 30 → 13 of 30 | 5 → 4 | 0.03 mm → 0.03 mm |
0.13 mm → 0.13 mm | 4 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 7.5-15 | 11 of 30 → 14 of 30 | 5 → 1 | 0.02 mm → 0.02 mm |
0.06 mm → 0.06 mm | 5 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 15-25 | 4 of 30 → 11 of 30 | 11 → 2 | 0.01 mm → 0.02 mm |
0.13 mm → 0.06 mm | 11 → 2 | 1.81 x 1.49 mm → 0.00 x 0.00 mm | pass |
| shadow | 0 | 8 of 30 → 9 of 30 | 16 → 13 | 0.01 mm → 0.01 mm | 0.08 mm
→ 0.08 mm | 7 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 0-7.5 | 11 of 30 → 13 of 30 | 11 → 7 | 0.02 mm → 0.03 mm |
0.17 mm → 0.71 mm | 3 → 3 | -0.03 x -0.47 mm → -0.01 x 0.00 mm | pass |
| shadow | 7.5-15 | 11 of 30 → 14 of 30 | 16 → 10 | 0.01 mm → 0.01 mm |
0.07 mm → 0.26 mm | 8 → 9 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 15-25 | 4 of 30 → 12 of 30 | 16 → 8 | 0.00 mm → 0.01 mm |
0.22 mm → 0.32 mm | 12 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| sleeve | 0 | 6 of 30 → 6 of 30 | 23 → 23 | 0.01 mm → 0.01 mm | 0.02 mm
→ 0.02 mm | 0 → 0 | -1.08 x -1.14 mm → -1.08 x -1.14 mm | pass |
| sleeve | 0-7.5 | 8 of 30 → 8 of 30 | 17 → 16 | 0.01 mm → 0.01 mm |
0.07 mm → 0.07 mm | 1 → 1 | -1.01 x -0.97 mm → -0.99 x -0.99 mm | pass |
| sleeve | 7.5-15 | 5 of 30 → 6 of 30 | 23 → 22 | 0.02 mm → 0.01 mm |
0.05 mm → 0.05 mm | 5 → 4 | -0.67 x -0.63 mm → -0.73 x -0.63 mm | pass |
| sleeve | 15-25 | 2 of 30 → 6 of 30 | 24 → 20 | 0.01 mm → 0.01 mm |
0.03 mm → 0.19 mm | 18 → 2 | -0.02 x 0.01 mm → -1.26 x -1.31 mm | pass |
| glare | 0 | 21 of 30 → 21 of 30 | 1 → 1 | 0.02 mm → 0.02 mm | 0.06 mm
→ 0.06 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0-7.5 | 18 of 30 → 18 of 30 | 5 → 4 | 0.01 mm → 0.01 mm | 0.09
mm → 0.09 mm | 4 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 7.5-15 | 16 of 30 → 18 of 30 | 8 → 3 | 0.02 mm → 0.02 mm |
0.07 mm → 0.07 mm | 8 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 15-25 | 7 of 30 → 19 of 30 | 12 → 2 | 0.01 mm → 0.02 mm | 0.06
mm → 0.12 mm | 12 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0 | 12 of 30 → 12 of 30 | 5 → 5 | 0.06 mm → 0.06 mm |
0.34 mm → 0.34 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0-7.5 | 13 of 30 → 13 of 30 | 7 → 6 | 0.11 mm → 0.11 mm
| 0.63 mm → 0.63 mm | 7 → 6 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| motion-blur | 7.5-15 | 10 of 30 → 12 of 30 | 8 → 5 | 0.02 mm → 0.03 mm
| 0.23 mm → 0.23 mm | 8 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 15-25 | 3 of 30 → 6 of 30 | 12 → 6 | 0.72 mm → 0.18 mm |
0.83 mm → 0.91 mm | 12 → 6 | 2.00 x 4.36 mm → 0.00 x 0.02 mm | pass |
| hand | 0 | 21 of 30 → 21 of 30 | 0 → 0 | 0.01 mm → 0.01 mm | 0.10 mm →
0.10 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 0-7.5 | 21 of 30 → 21 of 30 | 2 → 1 | 0.01 mm → 0.01 mm | 0.06
mm → 0.06 mm | 2 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 7.5-15 | 16 of 30 → 18 of 30 | 7 → 4 | 0.01 mm → 0.01 mm | 0.14
mm → 0.14 mm | 7 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 15-25 | 8 of 30 → 18 of 30 | 16 → 5 | 0.01 mm → 0.01 mm | 0.04
mm → 0.06 mm | 16 → 4 | 0.00 x 1.81 mm → 0.00 x 0.00 mm | pass |

Empty frames:

| Condition | Tilt | False outlines | Result |
| --- | --- | --: | --- |
| empty-plain | 0 | 0 → 0 | pass |
| empty-plain | 0-7.5 | 0 → 0 | pass |
| empty-plain | 7.5-15 | 0 → 0 | pass |
| empty-plain | 15-25 | 0 → 0 | pass |
| empty-patterned | 0 | 0 → 0 | pass |
| empty-patterned | 0-7.5 | 0 → 0 | pass |
| empty-patterned | 7.5-15 | 0 → 0 | pass |
| empty-patterned | 15-25 | 0 → 0 | pass |

Clips by condition, merge base → branch:

| Condition | Photo asked for | Settle time median | Jitter median |
Photo outline median | Photo outline median, held still on the card edge
| Inside photo outlines | Hand shift median | Result |
| --- | --: | --: | --: | --: | --: | --: | --: | --- |
| plain | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.02 mm → 0.00 mm | 0.03
mm → 0.03 mm | 0.03 mm → 0.03 mm | 1 → 1 | 0.83 mm → 0.83 mm | pass |
| patterned | 3 of 5 → 3 of 5 | 1200 ms → 1200 ms | 0.05 mm → 0.05 mm |
0.05 mm → 0.05 mm | 0.02 mm → 0.05 mm | 1 → 0 | 1.04 mm → 1.04 mm | pass
|
| shadow | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.00 mm → 0.00 mm |
0.04 mm → 0.04 mm | 0.03 mm → 0.04 mm | 0 → 0 | 0.60 mm → 0.60 mm | pass
|
| sleeve | 5 of 5 → 5 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
1.95 mm → 1.95 mm | none → none | 1 → 1 | 1.03 mm → 1.03 mm | pass |

Card frames by condition and border colour, reported:

| Condition | Border colour | Detection rate | Wrong outlines | Corner
error median | Corner error p90 | Inside outlines | Size error, width x
height |
| --- | --- | --: | --: | --: | --: | --: | --: |
| plain | black | 27 of 40 → 34 of 40 | 10 → 2 | 0.01 mm → 0.01 mm |
0.02 mm → 0.02 mm | 10 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | white | 28 of 40 → 35 of 40 | 7 → 2 | 0.01 mm → 0.01 mm | 0.01
mm → 0.02 mm | 7 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | borderless | 3 of 40 → 3 of 40 | 5 → 2 | 0.07 mm → 0.07 mm |
0.07 mm → 0.07 mm | 4 → 0 | 0.02 x 0.02 mm → 0.02 x 0.00 mm |
| patterned | black | 20 of 40 → 23 of 40 | 7 → 4 | 0.03 mm → 0.03 mm |
0.10 mm → 0.10 mm | 7 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | white | 17 of 40 → 24 of 40 | 11 → 3 | 0.02 mm → 0.02 mm |
0.07 mm → 0.06 mm | 11 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | borderless | 1 of 40 → 1 of 40 | 5 → 1 | 0.22 mm → 0.22 mm
| 0.22 mm → 0.22 mm | 4 → 0 | 0.04 x 1.46 mm → 0.04 x 0.00 mm |
| shadow | black | 6 of 40 → 15 of 40 | 32 → 22 | 0.17 mm → 0.17 mm |
0.96 mm → 0.71 mm | 11 → 9 | -0.19 x -0.96 mm → -0.08 x -0.10 mm |
| shadow | white | 28 of 40 → 33 of 40 | 10 → 5 | 0.01 mm → 0.01 mm |
0.06 mm → 0.05 mm | 10 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| shadow | borderless | 0 of 40 → 0 of 40 | 17 → 11 | none → none | none
→ none | 9 → 7 | -0.20 x -0.28 mm → -0.33 x -0.55 mm |
| sleeve | black | 15 of 40 → 17 of 40 | 25 → 22 | 0.01 mm → 0.01 mm |
0.03 mm → 0.03 mm | 11 → 3 | 0.00 x 0.00 mm → -0.01 x -0.01 mm |
| sleeve | white | 4 of 40 → 6 of 40 | 36 → 34 | 0.01 mm → 0.01 mm |
0.07 mm → 0.07 mm | 9 → 3 | -1.07 x -1.21 mm → -1.23 x -1.21 mm |
| sleeve | borderless | 2 of 40 → 3 of 40 | 26 → 25 | 0.05 mm → 0.05 mm
| 0.05 mm → 0.19 mm | 4 → 1 | -1.20 x -1.15 mm → -1.27 x -1.28 mm |
| glare | black | 29 of 40 → 34 of 40 | 10 → 6 | 0.01 mm → 0.01 mm |
0.04 mm → 0.03 mm | 10 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | white | 29 of 40 → 37 of 40 | 10 → 2 | 0.03 mm → 0.03 mm |
0.07 mm → 0.07 mm | 10 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | borderless | 4 of 40 → 5 of 40 | 6 → 2 | 0.10 mm → 0.33 mm |
0.67 mm → 0.67 mm | 5 → 1 | 0.02 x 0.00 mm → 0.07 x 0.00 mm |
| motion-blur | black | 14 of 40 → 17 of 40 | 19 → 13 | 0.06 mm → 0.06
mm | 0.63 mm → 0.56 mm | 18 → 12 | 1.86 x 1.77 mm → 0.00 x 0.01 mm |
| motion-blur | white | 21 of 40 → 23 of 40 | 12 → 9 | 0.05 mm → 0.07 mm
| 0.72 mm → 0.81 mm | 11 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| motion-blur | borderless | 3 of 40 → 3 of 40 | 1 → 0 | 0.59 mm → 0.59
mm | 0.63 mm → 0.63 mm | 1 → 0 | 0.01 x 0.23 mm → 0.01 x 0.23 mm |
| hand | black | 33 of 40 → 38 of 40 | 7 → 2 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 7 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | white | 26 of 40 → 31 of 40 | 12 → 6 | 0.01 mm → 0.00 mm | 0.02
mm → 0.01 mm | 12 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | borderless | 7 of 40 → 9 of 40 | 6 → 2 | 0.08 mm → 0.07 mm |
0.16 mm → 0.16 mm | 6 → 1 | 0.02 x 0.02 mm → 0.00 x 0.00 mm |

Card frames by border colour and tilt, reported:

| Border colour | Tilt | Detection rate | Wrong outlines | Corner error
median | Corner error p90 | Inside outlines | Size error, width x height
|
| --- | --- | --: | --: | --: | --: | --: | --: |
| black | 0 | 45 of 70 → 46 of 70 | 19 → 18 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 4 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 0-7.5 | 43 of 70 → 45 of 70 | 21 → 18 | 0.01 mm → 0.01 mm |
0.12 mm → 0.17 mm | 13 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 7.5-15 | 40 of 70 → 50 of 70 | 25 → 13 | 0.01 mm → 0.02 mm |
0.06 mm → 0.06 mm | 17 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 15-25 | 16 of 70 → 37 of 70 | 45 → 22 | 0.01 mm → 0.01 mm |
0.22 mm → 0.22 mm | 40 → 13 | 0.03 x 0.01 mm → 0.00 x 0.00 mm |
| white | 0 | 49 of 70 → 49 of 70 | 15 → 14 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 5 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 0-7.5 | 51 of 70 → 51 of 70 | 13 → 13 | 0.02 mm → 0.02 mm |
0.09 mm → 0.09 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 7.5-15 | 34 of 70 → 42 of 70 | 31 → 21 | 0.01 mm → 0.01 mm |
0.07 mm → 0.05 mm | 23 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 15-25 | 19 of 70 → 47 of 70 | 39 → 13 | 0.01 mm → 0.01 mm |
0.06 mm → 0.06 mm | 37 → 7 | 0.00 x 0.01 mm → 0.00 x 0.00 mm |
| borderless | 0 | 4 of 70 → 4 of 70 | 14 → 12 | 0.07 mm → 0.07 mm |
0.67 mm → 0.67 mm | 5 → 3 | -0.95 x -0.96 mm → -1.01 x -1.03 mm |
| borderless | 0-7.5 | 8 of 70 → 8 of 70 | 13 → 7 | 0.08 mm → 0.08 mm |
0.63 mm → 0.63 mm | 3 → 0 | -0.01 x -0.01 mm → -0.01 x 0.00 mm |
| borderless | 7.5-15 | 7 of 70 → 7 of 70 | 20 → 13 | 0.07 mm → 0.07 mm
| 0.59 mm → 0.59 mm | 9 → 6 | -0.01 x 0.00 mm → -0.09 x -0.01 mm |
| borderless | 15-25 | 1 of 70 → 5 of 70 | 19 → 11 | 0.06 mm → 0.07 mm |
0.06 mm → 0.33 mm | 16 → 1 | 0.00 x 1.47 mm → -0.26 x -0.82 mm |

The whole run:

| Metric | Merge base | Branch | Bar | Result |
| --- | --: | --: | --- | --- |
| Mac timing p95 | 77.1 ms | 81.6 ms | at most 1.2 times the merge base
| pass |

Bars for each condition and tilt:

- Detection rate: correct outlines not lower by more than 1
- Wrong outlines: not more than the merge base
- Corner error median: not worse by more than 0.1 mm, on frames with a
correct outline on both sides
- Corner error p90: not worse by more than 0.5 mm, on frames with a
correct outline on both sides
- Inside outlines: not more than the merge base plus 1
- False outlines: zero

Bars for each clip condition:

- Photo asked for: not fewer
- Settle time median: not worse
- Jitter median: not worse, to 0.01 mm
- Photo outline median: not worse by more than 0.1 mm
- Photo outline median, held still on the card edge: below 0.5 mm
- Inside photo outlines: no new one

Every bar passes.

New inside outlines and false outlines, in frame pixels:

- shadow-009.png, tilt 0, black border: outline at (127, 197) (596, 198)
(596, 853) (126, 854), sides inside top -4.0 mm, right 0.0 mm, bottom
4.0 mm, left 0.0 mm
- shadow-070.png, tilt 7.5-15, white border: outline at (142, 202) (571,
168) (605, 747) (219, 795), sides inside top 3.5 mm, right 3.1 mm,
bottom -4.0 mm, left -2.8 mm
- shadow-077.png, tilt 7.5-15, borderless border: outline at (313, 312)
(589, 425) (479, 818) (166, 712), sides inside top -3.1 mm, right -0.2
mm, bottom 4.0 mm, left -0.2 mm
- shadow-083.png, tilt 7.5-15, borderless border: outline at (283, 228)
(647, 289) (592, 807) (176, 735), sides inside top -5.0 mm, right 0.0
mm, bottom 3.9 mm, left -0.8 mm
- shadow-086.png, tilt 7.5-15, borderless border: outline at (223, 427)
(642, 470) (563, 1004) (184, 958), sides inside top 4.2 mm, right -2.2
mm, bottom -3.2 mm, left 1.8 mm
- sleeve-074.png, tilt 7.5-15, borderless border: outline at (296, 303)
(652, 357) (584, 867) (179, 780), sides inside top -1.2 mm, right 1.0
mm, bottom 3.9 mm, left -1.2 mm

Photo refinement on the merge base: 16 refined, of 16 clips that ask for
a photo. Median 148 ms on the Mac.

Photo refinement on the branch: 11 refined, 2 size refused, 3 motion
refused, of 16 clips that ask for a photo. Median 148 ms on the Mac.

### What the replay shows

Over all 1,080 card frames, merge base to branch, from a local run on an
Apple Mac before #514 (CI's Vision gives slightly other outlines, with
the same picture):

| Tilt | Inside outlines | Outlines within 1 mm | Detected |
| --- | --: | --: | --: |
| 0 | 12 → 10 | 100 → 101 | 150 → 145 |
| 0-7.5 | 21 → 16 | 104 → 106 | 150 → 141 |
| 7.5-15 | 49 → 24 | 81 → 99 | 156 → 143 |
| 15-25 | 94 → 21 | 38 → 90 | 142 → 136 |

Every bar passes, in CI and locally. Notes:

- **Inside outlines, `shadow` at 7.5-15:** 8 → 9, within the allowance
of 1. The new inside outlines are listed under the table. Most are
shifted outlines: a hard shadow edge on one side and an inner line on
the other, the size of the card. This is the hard-shadow weak spot
(research 4.3), which is out of scope here.
- **Corner error, `motion-blur` at 15-25:** the group has 3 frames with
a correct outline on both sides, so it is reported. The artifact shows
the frame that failed the paired median in the run before:
motion-blur-118, 0.72 → 0.91 mm. The other two are motion-blur-099 (0.83
mm on both sides) and motion-blur-112 (0.05 mm on both sides).
- Black-bordered cards up to 15 degrees: inside outlines 34 → 25 in CI.
Not zero. Each one left passes the gate with an aspect within 0.012 on
the card. On those frames the edge refiner found no line on the card
edge, for example a black border on a dark surface, a hard shadow,
motion blur, or glare. The aspect gate cannot fix those.
- Photo refinement: on the merge base 16 of 16 clips refine. On the
branch 11 refine, and 5 are size or motion refused, so those keep the
held-still outline. The clip bars pass. The photo refinement runs the
gate in the frame on the photo, with no matrix. This goes to the code
review.

Tolerance 0.02 on the card was also tried locally. It gives 10 new
inside outlines in 6 groups, and the inner frame of a 2.4 mm border
passes the gate. Inside outlines over all frames: 176 → 94, against 71
at 0.012.

Mac timing p95 holds: 77.1 → 81.6 ms in CI (a slow runner), 5.0 → 5.0 ms
locally.

## Merge Danger

**Door:** two-way

One constant (`aspectRatioToleranceOnCard`) and one call argument turn
it off.

**Blast Radius:** scanner

- On the phone, the gate now depends on the delivered matrix. A wrong
matrix refuses real cards. The device check below must confirm it.
- Fewer wrong outlines are detected, so automatic capture asks for a
photo less often on hard shadows and blur.

Post-merge steps:

- Device check on the iPhone with a development build: scan
black-bordered cards with the phone tilted about 15 degrees, and measure
the training crops (training crop scorer). The `detector-timing` capture
line must keep p95 below 20 ms at 4.5 Hz or more.
…replay (#518)

## Summary

The fix round for the #493 code review. `main` is merged in, up to #517.

```diff
 takePhoto(outline)
-  frame = last analyzed frame, if its outline == outline
+  frame = KeptFrames.frame(withOutline: outline)    # copies of the frames with a card from about the last second
   PhotoOutline.refine(photo, frame, frameIntrinsicMatrix, heldStill)
     moved = registration(frame -> photo)(heldStill)
-    refine on the photo, aspect checked in the frame
+    refine on the photo, aspect checked on the card with the frame's intrinsic matrix
-    on a size or motion refusal: heldStill
+    on a size or motion refusal, or no refined outline: moved
     on a registration or photo error, or no kept frame: heldStill
```

```diff
 detector:replay --base <ref>
-  merge base without the step mode: build the branch's command with the merge base's detector files
+  merge base without the step mode: "has no detector replay", run the branch alone against fixed limits
+    no false outline, at most 1 inside outline on plain at tilt 0, Mac p95 below 20 ms
   bars
-    photo outline median below 0.5 mm, on clips whose held-still outline is on the card edge
+    photo outline median below 0.5 mm, over all clips; medians by condition are reported
+  every failing bar lists its frames or clips, with where the outline was
```

Also from the standards review:

- `OrientationTransform` holds the intrinsic matrix, so `detect → refine
→ quadrilateral → metrics` no longer pass it.
- One `millimetres`, one list of metric names, one pixel mapping, typed
`Condition`, `TiltBucket`, and `BorderColor`.
- `frames.py` and `simulate.py` import one `image_download.py`. Its code
is the old `download` with the user agent as an argument.
- The detector command keeps only the `step` mode. `PhotoOutline.chosen`
is `checkedOutline`, and `sides()` is `meanSideLengths`. The clashing
`run`s are `runProcess` and `wholeRun`.
- GLOSSARY: **Held-still outline**, **Photo outline**, **Card aspect**.
"color" everywhere in the detector replay.
- The Detector workflow also runs on `src/scan/capture-log.ts` and
`image_download.py`.

## Evidence

- `bun run detector:test`: 32 tests pass. New tests:
- Photo refinement of a tilted black-bordered card: `refined` with the
frame's intrinsic matrix, not refined without it. Mutation: drop the
matrix in `PhotoLuma`, and the test fails with `sizeRefused`.
- A size or motion refusal, or no refined outline, keeps the moved
outline.
- `KeptFrames` finds the frame that held still after later frames, and
forgets frames older than a second. Mutation: keep only the last frame,
and 2 tests fail.
  - `copiedPlanes` copies a frame into a new buffer with the same bytes.
- `bunx jest test/detector-replay.test.ts`: 35 tests pass, with new
tests for the frames and clips listed under each failing bar, the photo
outline bar over all clips, and the fixed limits.
- `frames.py` with the shared download renders every frame, clip frame,
photo, and `labels.json` with the bytes in `frames.sha256`.
- Photo refinement against `spec/493-detector-replay` at `204b40f`:
**Before:** 11 refined, 2 size refused, 3 motion refused, of 16.
**After:** 16 refined, of 16. The photo outline median over all clips
falls from 0.90 to 0.06 mm.
- `bun run detector:replay --base origin/main`: "The merge base 8e3e450
with origin/main has no detector replay", and the branch passes the
fixed limits: 0 false outlines, 1 inside outline on plain at tilt 0, Mac
p95 5.9 ms. Exit 0.
- The refusal limits stay at 2%. The scanner evidence pack README (Photo
refinement) has the new results behind them.

### Detector replay

From the job summary of [the last Detector
run](https://github.com/Reilley64/mtgscan/actions/runs/39684805406) on
`macos-15`:

The branch at 5fdf7a8 against the merge base 204b40f with
origin/spec/493-detector-replay, 3 timing rounds.

Card frames by condition and tilt in degrees, merge base → branch:

| Condition | Tilt | Detection rate | Wrong outlines | Corner error
median | Corner error p90 | Inside outlines | Size error, width x height
| Result |
| --- | --- | --: | --: | --: | --: | --: | --: | --- |
| plain | 0 | 20 of 30 → 20 of 30 | 1 → 1 | 0.01 mm → 0.01 mm | 0.03 mm
→ 0.03 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 0-7.5 | 18 of 30 → 18 of 30 | 0 → 0 | 0.01 mm → 0.01 mm | 0.01
mm → 0.01 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 7.5-15 | 17 of 30 → 17 of 30 | 2 → 2 | 0.01 mm → 0.01 mm |
0.03 mm → 0.03 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| plain | 15-25 | 17 of 30 → 17 of 30 | 3 → 3 | 0.01 mm → 0.01 mm | 0.03
mm → 0.03 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 0 | 10 of 30 → 10 of 30 | 1 → 1 | 0.02 mm → 0.02 mm | 0.06
mm → 0.06 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 0-7.5 | 13 of 30 → 13 of 30 | 4 → 4 | 0.03 mm → 0.03 mm |
0.13 mm → 0.13 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 7.5-15 | 14 of 30 → 14 of 30 | 1 → 1 | 0.02 mm → 0.02 mm |
0.06 mm → 0.06 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| patterned | 15-25 | 11 of 30 → 11 of 30 | 2 → 2 | 0.02 mm → 0.02 mm |
0.06 mm → 0.06 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 0 | 9 of 30 → 9 of 30 | 13 → 13 | 0.01 mm → 0.01 mm | 0.08 mm
→ 0.08 mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 0-7.5 | 13 of 30 → 13 of 30 | 7 → 7 | 0.03 mm → 0.03 mm |
0.71 mm → 0.71 mm | 3 → 3 | -0.01 x 0.00 mm → -0.01 x 0.00 mm | pass |
| shadow | 7.5-15 | 14 of 30 → 14 of 30 | 10 → 10 | 0.01 mm → 0.01 mm |
0.26 mm → 0.26 mm | 9 → 9 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 15-25 | 12 of 30 → 12 of 30 | 8 → 8 | 0.01 mm → 0.01 mm |
0.32 mm → 0.32 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| sleeve | 0 | 6 of 30 → 6 of 30 | 23 → 23 | 0.01 mm → 0.01 mm | 0.02 mm
→ 0.02 mm | 0 → 0 | -1.08 x -1.14 mm → -1.08 x -1.14 mm | pass |
| sleeve | 0-7.5 | 8 of 30 → 8 of 30 | 16 → 16 | 0.01 mm → 0.01 mm |
0.07 mm → 0.07 mm | 1 → 1 | -0.99 x -0.99 mm → -0.99 x -0.99 mm | pass |
| sleeve | 7.5-15 | 6 of 30 → 6 of 30 | 22 → 22 | 0.01 mm → 0.01 mm |
0.05 mm → 0.05 mm | 4 → 4 | -0.73 x -0.63 mm → -0.73 x -0.63 mm | pass |
| sleeve | 15-25 | 6 of 30 → 6 of 30 | 20 → 20 | 0.01 mm → 0.01 mm |
0.19 mm → 0.19 mm | 2 → 2 | -1.26 x -1.31 mm → -1.26 x -1.31 mm | pass |
| glare | 0 | 21 of 30 → 21 of 30 | 1 → 1 | 0.02 mm → 0.02 mm | 0.06 mm
→ 0.06 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0-7.5 | 18 of 30 → 18 of 30 | 4 → 4 | 0.01 mm → 0.01 mm | 0.09
mm → 0.09 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 7.5-15 | 18 of 30 → 18 of 30 | 3 → 3 | 0.02 mm → 0.02 mm |
0.07 mm → 0.07 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 15-25 | 19 of 30 → 19 of 30 | 2 → 2 | 0.02 mm → 0.02 mm | 0.12
mm → 0.12 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0 | 12 of 30 → 12 of 30 | 5 → 5 | 0.06 mm → 0.06 mm |
0.34 mm → 0.34 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0-7.5 | 13 of 30 → 13 of 30 | 6 → 6 | 0.11 mm → 0.11 mm
| 0.63 mm → 0.63 mm | 6 → 6 | 0.00 x 0.01 mm → 0.00 x 0.01 mm | pass |
| motion-blur | 7.5-15 | 12 of 30 → 12 of 30 | 5 → 5 | 0.03 mm → 0.03 mm
| 0.23 mm → 0.23 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 15-25 | 6 of 30 → 6 of 30 | 6 → 6 | 0.18 mm → 0.18 mm |
0.91 mm → 0.91 mm | 6 → 6 | 0.00 x 0.02 mm → 0.00 x 0.02 mm | pass |
| hand | 0 | 21 of 30 → 21 of 30 | 0 → 0 | 0.01 mm → 0.01 mm | 0.10 mm →
0.10 mm | 0 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 0-7.5 | 21 of 30 → 21 of 30 | 1 → 1 | 0.01 mm → 0.01 mm | 0.06
mm → 0.06 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 7.5-15 | 18 of 30 → 18 of 30 | 4 → 4 | 0.01 mm → 0.01 mm | 0.14
mm → 0.14 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 15-25 | 18 of 30 → 18 of 30 | 5 → 5 | 0.01 mm → 0.01 mm | 0.06
mm → 0.06 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |

Empty frames:

| Condition | Tilt | False outlines | Result |
| --- | --- | --: | --- |
| empty-plain | 0 | 0 → 0 | pass |
| empty-plain | 0-7.5 | 0 → 0 | pass |
| empty-plain | 7.5-15 | 0 → 0 | pass |
| empty-plain | 15-25 | 0 → 0 | pass |
| empty-patterned | 0 | 0 → 0 | pass |
| empty-patterned | 0-7.5 | 0 → 0 | pass |
| empty-patterned | 7.5-15 | 0 → 0 | pass |
| empty-patterned | 15-25 | 0 → 0 | pass |

Clips by condition, merge base → branch:

| Condition | Photo asked for | Settle time median | Jitter median |
Photo outline median | Inside photo outlines | Hand shift median |
Result |
| --- | --: | --: | --: | --: | --: | --: | --- |
| plain | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.00 mm → 0.00 mm | 0.03
mm → 0.03 mm | 1 → 0 | 0.83 mm → 0.83 mm | pass |
| patterned | 3 of 5 → 3 of 5 | 1200 ms → 1200 ms | 0.05 mm → 0.05 mm |
0.05 mm → 0.05 mm | 0 → 0 | 1.04 mm → 1.04 mm | pass |
| shadow | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.00 mm → 0.00 mm |
0.04 mm → 0.04 mm | 0 → 0 | 0.60 mm → 0.60 mm | pass |
| sleeve | 5 of 5 → 5 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
1.95 mm → 1.95 mm | 1 → 1 | 1.03 mm → 1.03 mm | pass |

Card frames by condition and border color, reported:

| Condition | Border color | Detection rate | Wrong outlines | Corner
error median | Corner error p90 | Inside outlines | Size error, width x
height |
| --- | --- | --: | --: | --: | --: | --: | --: |
| plain | black | 34 of 40 → 34 of 40 | 2 → 2 | 0.01 mm → 0.01 mm | 0.02
mm → 0.02 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | white | 35 of 40 → 35 of 40 | 2 → 2 | 0.01 mm → 0.01 mm | 0.02
mm → 0.02 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| plain | borderless | 3 of 40 → 3 of 40 | 2 → 2 | 0.07 mm → 0.07 mm |
0.07 mm → 0.07 mm | 0 → 0 | 0.02 x 0.00 mm → 0.02 x 0.00 mm |
| patterned | black | 23 of 40 → 23 of 40 | 4 → 4 | 0.03 mm → 0.03 mm |
0.10 mm → 0.10 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | white | 24 of 40 → 24 of 40 | 3 → 3 | 0.02 mm → 0.02 mm |
0.06 mm → 0.06 mm | 3 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| patterned | borderless | 1 of 40 → 1 of 40 | 1 → 1 | 0.22 mm → 0.22 mm
| 0.22 mm → 0.22 mm | 0 → 0 | 0.04 x 0.00 mm → 0.04 x 0.00 mm |
| shadow | black | 15 of 40 → 15 of 40 | 22 → 22 | 0.17 mm → 0.17 mm |
0.71 mm → 0.71 mm | 9 → 9 | -0.08 x -0.10 mm → -0.08 x -0.10 mm |
| shadow | white | 33 of 40 → 33 of 40 | 5 → 5 | 0.01 mm → 0.01 mm |
0.05 mm → 0.05 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| shadow | borderless | 0 of 40 → 0 of 40 | 11 → 11 | none → none | none
→ none | 7 → 7 | -0.33 x -0.55 mm → -0.33 x -0.55 mm |
| sleeve | black | 17 of 40 → 17 of 40 | 22 → 22 | 0.01 mm → 0.01 mm |
0.03 mm → 0.03 mm | 3 → 3 | -0.01 x -0.01 mm → -0.01 x -0.01 mm |
| sleeve | white | 6 of 40 → 6 of 40 | 34 → 34 | 0.01 mm → 0.01 mm |
0.07 mm → 0.07 mm | 3 → 3 | -1.23 x -1.21 mm → -1.23 x -1.21 mm |
| sleeve | borderless | 3 of 40 → 3 of 40 | 25 → 25 | 0.05 mm → 0.05 mm
| 0.19 mm → 0.19 mm | 1 → 1 | -1.27 x -1.28 mm → -1.27 x -1.28 mm |
| glare | black | 34 of 40 → 34 of 40 | 6 → 6 | 0.01 mm → 0.01 mm | 0.03
mm → 0.03 mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | white | 37 of 40 → 37 of 40 | 2 → 2 | 0.03 mm → 0.03 mm | 0.07
mm → 0.07 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| glare | borderless | 5 of 40 → 5 of 40 | 2 → 2 | 0.33 mm → 0.33 mm |
0.67 mm → 0.67 mm | 1 → 1 | 0.07 x 0.00 mm → 0.07 x 0.00 mm |
| motion-blur | black | 17 of 40 → 17 of 40 | 13 → 13 | 0.06 mm → 0.06
mm | 0.56 mm → 0.56 mm | 12 → 12 | 0.00 x 0.01 mm → 0.00 x 0.01 mm |
| motion-blur | white | 23 of 40 → 23 of 40 | 9 → 9 | 0.07 mm → 0.07 mm
| 0.81 mm → 0.81 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| motion-blur | borderless | 3 of 40 → 3 of 40 | 0 → 0 | 0.59 mm → 0.59
mm | 0.63 mm → 0.63 mm | 0 → 0 | 0.01 x 0.23 mm → 0.01 x 0.23 mm |
| hand | black | 38 of 40 → 38 of 40 | 2 → 2 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 2 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | white | 31 of 40 → 31 of 40 | 6 → 6 | 0.00 mm → 0.00 mm | 0.01
mm → 0.01 mm | 6 → 6 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| hand | borderless | 9 of 40 → 9 of 40 | 2 → 2 | 0.07 mm → 0.07 mm |
0.16 mm → 0.16 mm | 1 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |

Card frames by border color and tilt, reported:

| Border color | Tilt | Detection rate | Wrong outlines | Corner error
median | Corner error p90 | Inside outlines | Size error, width x height
|
| --- | --- | --: | --: | --: | --: | --: | --: |
| black | 0 | 46 of 70 → 46 of 70 | 18 → 18 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 0-7.5 | 45 of 70 → 45 of 70 | 18 → 18 | 0.01 mm → 0.01 mm |
0.17 mm → 0.17 mm | 12 → 12 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 7.5-15 | 50 of 70 → 50 of 70 | 13 → 13 | 0.02 mm → 0.02 mm |
0.06 mm → 0.06 mm | 8 → 8 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| black | 15-25 | 37 of 70 → 37 of 70 | 22 → 22 | 0.01 mm → 0.01 mm |
0.22 mm → 0.22 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 0 | 49 of 70 → 49 of 70 | 14 → 14 | 0.01 mm → 0.01 mm | 0.08
mm → 0.08 mm | 4 → 4 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 0-7.5 | 51 of 70 → 51 of 70 | 13 → 13 | 0.02 mm → 0.02 mm |
0.09 mm → 0.09 mm | 5 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 7.5-15 | 42 of 70 → 42 of 70 | 21 → 21 | 0.01 mm → 0.01 mm |
0.05 mm → 0.05 mm | 13 → 13 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| white | 15-25 | 47 of 70 → 47 of 70 | 13 → 13 | 0.01 mm → 0.01 mm |
0.06 mm → 0.06 mm | 7 → 7 | 0.00 x 0.00 mm → 0.00 x 0.00 mm |
| borderless | 0 | 4 of 70 → 4 of 70 | 12 → 12 | 0.07 mm → 0.07 mm |
0.67 mm → 0.67 mm | 3 → 3 | -1.01 x -1.03 mm → -1.01 x -1.03 mm |
| borderless | 0-7.5 | 8 of 70 → 8 of 70 | 7 → 7 | 0.08 mm → 0.08 mm |
0.63 mm → 0.63 mm | 0 → 0 | -0.01 x 0.00 mm → -0.01 x 0.00 mm |
| borderless | 7.5-15 | 7 of 70 → 7 of 70 | 13 → 13 | 0.07 mm → 0.07 mm
| 0.59 mm → 0.59 mm | 6 → 6 | -0.09 x -0.01 mm → -0.09 x -0.01 mm |
| borderless | 15-25 | 5 of 70 → 5 of 70 | 11 → 11 | 0.07 mm → 0.07 mm |
0.33 mm → 0.33 mm | 1 → 1 | -0.26 x -0.82 mm → -0.26 x -0.82 mm |

The whole run:

| Metric | Merge base | Branch | Bar | Result |
| --- | --: | --: | --- | --- |
| Mac timing p95 | 90.6 ms | 91.1 ms | at most 1.2 times the merge base
| pass |
| Photo outline median, all clips | 0.90 mm | 0.05 mm | below 0.5 mm |
pass |

Bars for each condition and tilt:

- Detection rate: correct outlines not lower by more than 1
- Wrong outlines: not more than the merge base
- Corner error median: not worse by more than 0.1 mm, on frames with a
correct outline on both sides
- Corner error p90: not worse by more than 0.5 mm, on frames with a
correct outline on both sides
- Inside outlines: not more than the merge base plus 1
- False outlines: zero

Bars for each clip condition:

- Photo asked for: not fewer
- Settle time median: not worse
- Jitter median: not worse, to 0.01 mm
- Inside photo outlines: no new one

Every bar passes.

Photo refinement on the merge base: 11 refined, 2 size refused, 3 motion
refused, of 16 clips that ask for a photo. Median 119 ms on the Mac.

Photo refinement on the branch: 16 refined, of 16 clips that ask for a
photo. Median 117 ms on the Mac.

## Merge Danger

**Door:** two-way

**Blast Radius:** scanner

The camera session now copies each analyzed frame with a card, about 1.4
MB, and keeps about 6 of them. Photo refinement now accepts outlines it
refused before, at tilt. Both need the device check (#499, #500): no
Simulator or device was used here.

Part of #493
# Conflicts:
#	README.md
#	apps/mobile/modules/card-detector/ios/CameraSession.swift
…es shifted across the card (#521)

## Summary

Fixes from the device check of the #493 integration tip
([comment](https://github.com/Reilley64/mtgscan/issues/493#issuecomment-6330746264)).
Diagnosis on the throwaway branch `diag/493-device`.

```diff
 PhotoOutline.refine
   register the kept frame against the photo, move the held-still outline
-  CardEdgeRefiner.refine(proposal: moved)                       # band 15% of the short side
+  CardEdgeRefiner.refine(proposal: moved, searchFraction: 0.04)  # 2 x cornerMotionMax
   size check, motion check

 CardEdgeRefiner.refine, for each combination of edge lines
   same step sign
+  not two opposite edges moving apart from the proposal, each > 2% of the short side   # oppositeEdgeShiftMax
   card-shaped quad
   pick the most outward
```

- Replay bar: **Photo asked for** no longer counts a clip whose photo
outline is an inside outline.
- Branch-alone run (no merge base replay, as #504 into `main`): no Mac
timing limit. The limits on false outlines and on inside outlines on
`plain` frames at tilt `0` stay. CI run 39688321178 failed only on
timing (65 ms on the runner against 20 ms).
- Fixture: one real photo from the phone
(`macos/CardDetectorTests/Fixtures/device-photo`). It has the photo at
1280 x 720 with EXIF orientation 6, the kept frame's luma as PNG, and
the held-still outline and intrinsic matrix. It is 0.9 MB. The owner
approved it.
- The existing test "moves an inset proposal out to the card's outer
edges" moved its proposal down by 6% of the card height, so the bottom
edge moved in while the top moved out, and the new rule refuses that. It
now moves the proposal down by 2%.
- `detector:test` runs the Swift fixture tests one at a time
(`--no-parallel`). Run in parallel on the 3-core `macos-15` runner, the
suite hung twice with every test started and none finished. It also hung
with the device-photo test skipped. Each test passes alone on the
runner, and the suite passes one at a time in 19 s (probe runs
39715264925 and 39719853270 on the throwaway branch
`diag/521-ci-probe`).

## Evidence

- **Before:** on the phone, 6 of 9 photos were `not_refined`, 2 were
`refined` and 1 was `motion_refused`. The new tests fail as follows:
- Without the narrow band, `refines the outline on a device photo with
EXIF orientation…` and `…background lines parallel to the card's top
edge` give `.notRefined`.
- Without the rule, `keeps the card's edges when a line outside one edge
and a line inside the opposite edge would shift the outline` fails.
- The new jest test for the photo asked for bar fails on the old bar (`1
of 1 → 0 of 1`).
- **After:** `detector:test` passes 35 of 35, jest
`detector-replay.test.ts` passes 36 of 36, and typecheck and lint pass.
The device dumps run offline with this code:
- The 9 photos give 9 `refined`, 0.2 to 3.6 px from the held-still
outline.
- Of the 201 frames, only frame 85 changes, from a wrong outline (top +9
px, bottom -34 px) to no outline.

Replay against `origin/spec/493-detector-replay` (M3). Every bar passes,
exit 0. Rows that changed:

| Condition | Tilt | Detection rate | Wrong outlines | Corner error
median | Corner error p90 | Inside outlines | Size error, width x height
| Result |
| --- | --- | --: | --: | --: | --: | --: | --: | --- |
| shadow | 7.5-15 | 15 of 30 → 16 of 30 | 8 → 6 | 0.01 mm → 0.01 mm |
0.26 mm → 0.26 mm | 7 → 5 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| shadow | 15-25 | 12 of 30 → 13 of 30 | 8 → 7 | 0.00 mm → 0.00 mm |
0.32 mm → 0.32 mm | 3 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| glare | 0 | 21 of 30 → 21 of 30 | 1 → 0 | 0.02 mm → 0.02 mm | 0.06 mm
→ 0.06 mm | 1 → 0 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 0 | 13 of 30 → 13 of 30 | 5 → 4 | 0.07 mm → 0.07 mm |
0.56 mm → 0.56 mm | 2 → 1 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| motion-blur | 15-25 | 6 of 30 → 6 of 30 | 7 → 6 | 0.18 mm → 0.18 mm |
0.83 mm → 0.83 mm | 6 → 5 | 0.00 x 0.10 mm → 0.00 x 0.00 mm | pass |
| hand | 7.5-15 | 17 of 30 → 17 of 30 | 4 → 3 | 0.01 mm → 0.01 mm | 0.22
mm → 0.22 mm | 4 → 3 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |
| hand | 15-25 | 18 of 30 → 18 of 30 | 3 → 2 | 0.01 mm → 0.01 mm | 0.10
mm → 0.10 mm | 3 → 2 | 0.00 x 0.00 mm → 0.00 x 0.00 mm | pass |

['| Condition | Photo asked for | Settle time median | Jitter median |
Photo outline median | Inside photo outlines | Hand shift median |
Result |']
| --- | --: | --: | --: | --: | --: | --: | --- |
| sleeve | 4 of 5 → 4 of 5 | 1200 ms → 1200 ms | 0.06 mm → 0.06 mm |
1.96 mm → 1.84 mm | 1 → 0 | 1.03 mm → 0.94 mm | pass |

`sleeve-clip-003` no longer asks for a photo. On the integration branch,
its photo outline was an inside outline, 5.5 mm off. Mac timing p95 is
6.7 → 6.8 ms, and the photo outline median over all clips stays at 0.06
mm.

Replay against `origin/main` (branch alone): every fixed limit passes,
exit 0.

## Merge Danger

**Door:** two-way

**Blast Radius:** detector

Every frame-loop outline goes through the new rule. A Vision proposal
that is shifted by more than about 4% of the card height and also inset
is now refused, where before it was refined. On the device frames this
happened only on the wrong outline in frame 85.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant