Skip to content

fix: refine the photo outline past background lines and refuse outlines shifted across the card - #521

Merged
Reilley64 merged 2 commits into
spec/493-detector-replayfrom
fix/493-device
Oct 22, 2026
Merged

Reilley64 merged 2 commits into
spec/493-detector-replayfrom
fix/493-device

Conversation

@Reilley64

@Reilley64 Reilley64 commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes from the device check of the #493 integration tip (comment). Diagnosis on the throwaway branch diag/493-device.

 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 feat: measure the card detector offline with a detector replay #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.

…es shifted across the card

The device check of the #493 integration tip found that photo refinement failed on
real photos: wood grain outside the card took all 5 line slots of an edge in the
15% search band, so the card edge was never tried (6 of 9 not_refined). The photo
now uses a band of 2 x cornerMotionMax. The edge refiner also refuses an outline
whose opposite edges move in opposite directions by more than 2% of the short
side (oppositeEdgeShiftMax), the outline that cut 4-5 mm off held-still cards.

The photo asked for bar no longer counts a clip whose photo outline is an inside
outline, and the branch-alone run drops its Mac timing limit. A real device photo
with EXIF orientation backs a PhotoOutline test.

Refs #493
In parallel on the 3-core macos-15 runner the suite hung with every test started
and none finished, also with the device-photo test skipped. Each test passes
alone, and the suite passes one at a time in 19 seconds.

Refs #493
@Reilley64
Reilley64 merged commit 29c0aa6 into spec/493-detector-replay Oct 22, 2026
10 checks passed
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