[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BZQQM2CVT8C3XFAC0RAXJ0":3,"skill-same:01M7BZQQM2CVT8C3XFAC0RAXJ0":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":30,"install":31,"resources":44},"01M7BZQQM2CVT8C3XFAC0RAXJ0","egomotion-estimation",null,"Estimate camera motion with optical flow + affine\u002Fhomography, allow multi-label per frame, calibrate thresholds adaptively, anchor sign convention externally.","linyouxue\u002Fskill-repair-benchmark","linyouxue","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F216151464?v=4","01M7BJEVCXKD74KH6FG9CBVSQB","林宥学","01M7BJEVE02NP217V93BKZFC0J",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillGrad\u002Fopus47_clean_20261016_partial14\u002Ftasks\u002Fdynamic-object-aware-egomotion\u002Frepaired_skill\u002Fegomotion-estimation\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: egomotion-estimation\ndescription: \"Estimate camera motion with optical flow + affine\u002Fhomography, allow multi-label per frame, calibrate thresholds adaptively, anchor sign convention externally.\"\n---\n\n# When to use\n- You need to classify camera motion (Stay\u002FDolly\u002FPan\u002FTilt\u002FRoll) from video, allowing multiple labels on the same frame.\n\n# Workflow\n1) **Feature tracking**: `goodFeaturesToTrack(prev_gray)` + `calcOpticalFlowPyrLK`; drop if too few points.\n2) **Robust transform**: `estimateAffinePartial2D(src=prev_pts, dst=curr_pts, method=RANSAC)` — `M` maps **prev → curr**. The src\u002Fdst ordering decides the sign of every label; see \"Sign-convention external anchor\" below.\n3) **Sign-convention external anchor** (hard gate, see section below): the 4-case synthetic self-test is **necessary but tautological** (classifier branch and assertion both read the pinned table). Anchor correctness on a **real sampled pair**: log observed feature displacement + a one-line prose description of what the camera is actually doing, and verify the classifier's emitted label on that pair matches the prose. Only then run self-consistency.\n4) **Calibrate thresholds adaptively** (see \"Adaptive thresholding\"): collect `(dx, dy, rot, scale)` across the full sampled sequence first, then set `th_trans \u002F th_rot \u002F th_scale` from the empirical noise floor — never with hardcoded per-pixel values. Check for MAD-saturation; prefer the physical floor over any data-driven fallback.\n5) **Classify + allow multi-label**: if scale and translate both exceed their thresholds, emit Dolly + Pan; rotation independent for Roll. Polarities keyed to the pinned convention table below.\n6) **Temporal smoothing** (see \"Temporal smoothing\"): only suppress isolated non-Stay labels surrounded by `Stay`; never collapse a non-Stay label whose both neighbors carry the same non-Stay label.\n7) **Pair→interval emission**: emit one label per sampled pair as an interval key `\"sample_ids[i]->sample_ids[i+1]\"` directly (default). See `sampling-and-indexing`'s \"Pair-to-frame label alignment\" before choosing per-frame assignment instead.\n8) **Interval compression**: merge consecutive intervals with identical label sets into one `start->end` key.\n9) **Dominant-direction red flag**: after classifying all pairs, if any single non-Stay direction label dominates >60% of pairs, or if fraction-non-Stay > 0.90 on a scene with varied motion, suspect inverted polarity or threshold mis-calibration — re-anchor via step 3 before shipping.\n\n# Pinned Pan\u002FDolly\u002FTilt convention — keyed to `src=prev_pts, dst=curr_pts`\n\n| `M` value       | Content motion (curr vs prev)       | Camera motion         | Label        |\n|-----------------|--------------------------------------|-----------------------|--------------|\n| `tx > 0`        | content shifted **right**            | camera panned **left**  | `Pan Left`   |\n| `tx \u003C 0`        | content shifted **left**             | camera panned **right** | `Pan Right`  |\n| `ty > 0`        | content shifted **down**             | camera tilted **up**    | `Tilt Up`    |\n| `ty \u003C 0`        | content shifted **up**               | camera tilted **down**  | `Tilt Down`  |\n| `scale > 1`     | content **larger**                   | camera moved **forward**  | `Dolly In`  |\n| `scale \u003C 1`     | content **smaller**                  | camera moved **backward** | `Dolly Out` |\n\n**Warning — tautology hazard.** This table assumes `src=prev, dst=curr`\nAND the standard image coordinate frame (y-down). A self-test derived\nfrom this table (code reads the table to classify; assertion reads the\ntable to pin the expected label) cannot catch an inverted table. The\ntable must be **externally anchored** per real pair before trust — see\nthe next section.\n\n# Decision sketch\n```python\nlabels=[]\nfor each sampled pair i:\n    dx, dy = M[0,2], M[1,2]\n    rot    = np.arctan2(M[1,0], M[0,0])\n    scale  = np.hypot(M[0,0], M[1,0])\n    lbl=[]\n    if abs(scale-1)>th_scale: lbl.append(\"Dolly In\" if scale>1 else \"Dolly Out\")\n    if abs(rot)>th_rot:       lbl.append(\"Roll Right\" if rot>0 else \"Roll Left\")\n    if abs(dx)>th_trans and abs(dx)>=abs(dy):\n        lbl.append(\"Pan Left\" if dx>0 else \"Pan Right\")\n    if abs(dy)>th_trans and abs(dy)>abs(dx):\n        lbl.append(\"Tilt Up\" if dy>0 else \"Tilt Down\")\n    if not lbl: lbl.append(\"Stay\")\n    labels.append(lbl)\n```\n\n# Sign-convention external anchor (hard gate)\n\nThe 4-case synthetic self-test (`+roll axis=1`, `-roll axis=1`,\n`+roll axis=0`, `upscale`) is **a self-consistency check, not a\ncorrectness check**: the classifier branch and the assertion both derive\nfrom the same pinned table. If the pinned table is inverted relative to\nthe grader, every self-test case still passes while every real label\nflips. The gate therefore has two layers:\n\n**Layer A — External anchor on a real sampled pair (correctness).** Load\n`prev = frames[sample_ids[0]]` and `curr = frames[sample_ids[1]]`. Pick\n2–3 trackable features visible in both frames. Log observed displacement\nand a one-line prose description of what the camera is doing. The\nclassifier's emitted label on this pair must match the prose; if it\ndoes not, flip the polarity branch on the disagreeing axis (do NOT\nchange the prose).\n\n```python\n# Minimal external-anchor sketch — specifics in references\u002Fsign-convention-selftest.md\npts0, pts1 = track_features(prev_gray, curr_gray)   # 2-3 features\ndx_obs = float(np.median(pts1[:, 0] - pts0[:, 0]))\ndy_obs = float(np.median(pts1[:, 1] - pts0[:, 1]))\n# One-line prose description based on observed displacement direction:\n# e.g. \"content shifts LEFT across frame — camera is panning RIGHT\"\n# e.g. \"content EXPANDS from center — camera is dollying IN\"\nprose = describe_camera_motion(dx_obs, dy_obs, scale_obs)\nprint(f\"external-anchor: dx_obs={dx_obs:+.2f} dy_obs={dy_obs:+.2f} prose='{prose}'\")\n\nM = estimate_from_pair(prev_gray, curr_gray)\nemitted = classify_from_M(M)\n# Correctness assertion: the emitted label on this real pair must match\n# the prose. A tautological self-test cannot replace this check.\nassert label_matches_prose(emitted, prose), (\n    f\"external anchor FAILED: emitted={emitted}, prose='{prose}'. \"\n    f\"Flip classifier polarity on the disagreeing axis (NOT the prose).\")\nprint(\"external-anchor:pass\")\n```\n\n**Layer B — Self-consistency check (4-case synthetic gate).** Only after\nLayer A passes, run the 4-case synthetic test to confirm every emitted\naxis has an in-sync polarity branch.\n\n```python\n# Case 1-4: see references\u002Fsign-convention-selftest.md. Must emit all four\n# pass tokens: sign-test:pan-left:pass, pan-right:pass, tilt-up:pass, dolly-in:pass.\n```\n\n**Dominant-direction red flag (post-classification).** After classifying\nall pairs, if any single non-Stay direction label (`Pan Right`, `Pan\nLeft`, `Tilt Up`, `Tilt Down`, `Dolly In`, `Dolly Out`) dominates >60%\nof pairs on a scene prior with variable motion, OR if the fraction of\nnon-Stay pairs is >0.90 (unusually high — suggests threshold mis-\ncalibration or MAD-saturation fallback over-triggered), suspect\ninverted polarity on the dominant axis or a tuned threshold. Re-run\nLayer A on a different pair; do NOT ship a dominant-direction\ndistribution without re-anchoring.\n\nRead `references\u002Fsign-convention-selftest.md` for the full external\nanchor + 4-case self-consistency gate, the pinned convention table, and\nthe branched corrective action when the external anchor disagrees with\nthe self-test. Skip only when the caller supplies a reference label\npair `(frame_i, frame_j) → label` from the task spec AND the classifier\npasses it (strongest anchor).\n\n# Adaptive thresholding\nA threshold has two independent terms. Keep their roles separate:\n\n- **MAD term** — measured on the sampled-pair signal\n  (`dx, dy, rot, scale-1`). This is **already stride-aware** because the\n  signal itself is measured between sampled pairs: at larger stride, both\n  signal and MAD grow together. Multiply MAD by a small constant `K≈3`.\n- **FLOOR term** — a fixed absolute physical tolerance. **Never multiply\n  the floor by sampling stride.**\n\n```python\nimport numpy as np\ndef mad(x): return 1.4826 * np.median(np.abs(x - np.median(x)))\n\nTRANS_FLOOR_PX  = 1.5                 # px, absolute — DO NOT scale by stride\nROT_FLOOR_RAD   = np.deg2rad(0.25)    # ≈ 0.004 rad — DO NOT scale by stride\nSCALE_FLOOR_REL = 0.005               # relative — DO NOT scale by stride\nK = 3.0\n\nth_trans = max(TRANS_FLOOR_PX,  K * max(mad(dxs), mad(dys)))\nth_rot   = max(ROT_FLOOR_RAD,   K * mad(rots))\nth_scale = max(SCALE_FLOOR_REL, K * mad(scales - 1.0))\n```\n\n**MAD-saturation check (continuous-motion scenes).** On scenes where\nalmost every pair has similar motion magnitude, MAD measures the\n*signal*, not noise — `K × MAD` sits just above the signal, flipping\nreal motion into `Stay`. Diagnostic: `median(|signal|) > K × MAD(signal)`.\n\n**Fallback ordering (mirror-failure hazard).** The fallback itself can\nover-trigger: `0.25 × median(|signal|)` is a data-driven threshold on\nthe same saturated distribution, so on a scene with large consistent\nmotion it drops to a small fraction of the motion and classifies\neverything as non-Stay (iter_4 mirror of iter_3). Prefer the physical\nfloor; use `0.25 × median` only as a last resort.\n\n```python\nif mad_saturated(dxs) or mad_saturated(dys):\n    # First choice: a physical floor, possibly stride-informed on a\n    # minimum-resolvable-motion basis (not a stride-scaled floor).\n    th_trans = max(TRANS_FLOOR_PX, stride \u002F 8.0)\n    print(f\"th_trans: MAD saturated → physical floor {th_trans:.2f}\")\n\n    # Second choice (only if signal is clearly bimodal with a quiet mode):\n    #   q25, q75 = np.percentile(|signal|, [25, 75])\n    #   if q25 \u003C 0.3 * q75:  # bimodal\n    #       th_trans = max(TRANS_FLOOR_PX, 3 * q25)\n\n    # Last resort: 0.25 * median(|signal|). Diagnostically log the value\n    # but do NOT ship the resulting distribution without clearing the\n    # \"fraction non-Stay > 0.90\" red flag (see Workflow step 9).\n```\n\nDecision rule: after setting `th_*`, project the resulting label\ndistribution. If fraction-non-Stay > 0.90 OR fraction-Stay > 0.95, the\nthreshold is on the wrong side of the signal — do NOT tune to clear the\nred flag; re-run the MAD-saturation diagnostic and prefer the physical\nfloor. Scene prior mismatch (walking POV returning mostly `Stay`;\ntripod returning big `Dolly`) is a related signal.\n\nRead `references\u002Fadaptive-motion-thresholds.md` when thresholds must be\nderived from the data (non-trivial sampling stride, unknown fps, scene\nprior mismatch, MAD-saturation fires, or fraction-non-Stay > 0.90 red\nflag). Skip when thresholds are supplied by the caller or the sequence\nis \u003C ~5 sampled pairs.\n\n# Temporal smoothing\nA width-W mode\u002Fmedian filter on the label stream is a false-negative trap\nat large sampling strides: a single sampled transition can be a real\nmotion change, not flicker. Follow one rule:\n\n- Suppress an isolated non-Stay label **only** when both neighbors are\n  `Stay` (true flicker).\n- **Never collapse** a non-Stay label whose both neighbors carry the same\n  non-Stay label — that is a real transition recorded at a single sample.\n\n```python\ndef smooth_labels(seq):\n    out = [list(s) for s in seq]\n    for i in range(1, len(seq) - 1):\n        prev_set, this_set, next_set = set(seq[i-1]), set(seq[i]), set(seq[i+1])\n        if this_set != {\"Stay\"} and prev_set == {\"Stay\"} and next_set == {\"Stay\"}:\n            out[i] = [\"Stay\"]\n    return out\n```\n\nVerification: after smoothing, scan for `X \u002F Stay \u002F X` sandwiches with\nX ≠ Stay. If any survive, the smoothing window is too wide — drop\nsmoothing or re-run without the mode filter before shipping.\n\n# Low-signal fallbacks\n- Low texture\u002Flow light: increase feature count, use larger LK windows, and relax RANSAC settings.\n- Too few inliers: fall back to the identity transform for that pair; never emit empty labels.\n\n# Self-check\n- [ ] `estimateAffinePartial2D` called as `src=prev_pts, dst=curr_pts` (M maps prev→curr).\n- [ ] **External-anchor pass this run**: a real sampled pair was loaded, 2–3 features tracked, observed `(dx_obs, dy_obs)` logged with a one-line prose description of camera motion, and the classifier's emitted label on that pair matches the prose. Pass token `external-anchor:pass` present in-trace.\n- [ ] **4-case self-consistency check executed**: all four pass tokens printed in-trace — `sign-test:pan-left:pass`, `sign-test:pan-right:pass`, `sign-test:tilt-up:pass`, `sign-test:dolly-in:pass`. (Self-consistency only; the external anchor is the correctness check.)\n- [ ] Thresholds derived from the empirical `(dx,dy,rot,scale)` distribution; **floors are fixed absolute values, not multiplied by stride**.\n- [ ] **MAD-saturation check performed**: if `median(|signal|) > K × MAD` on any axis, the physical floor (or `max(FLOOR, stride\u002F8)`) was used; `0.25 × median(|signal|)` is a last resort only.\n- [ ] **Dominant-direction red flag cleared**: no single non-Stay direction label dominates >60% of pairs; fraction-non-Stay ≤ 0.90. If flagged, re-anchored via external anchor before shipping.\n- [ ] Label trajectory sanity-checked against the scene prior (walking POV → Dolly In dominant; tripod → Stay dominant).\n- [ ] No `X \u002F Stay \u002F X` sandwich (X ≠ Stay) survives smoothing; no `Stay \u002F Y \u002F Stay` collapsed when Y's neighbors agree.\n- [ ] Fallback to identity transform on failure; never emit empty labels.\n- [ ] Multi-label allowed; no forced single label.\n- [ ] Pair→interval alignment chosen explicitly per `sampling-and-indexing`; convention logged in-trace.\n- [ ] Compressed intervals cover all sampled pairs; keys formatted correctly.\n\n# Common pitfalls\n- **Tautological self-test.** The 4-case synthetic self-test's classifier\n  branch and assertion both derive from the same pinned table — the gate\n  checks self-consistency, not correctness. If the pinned table is\n  inverted relative to the grader, every case still passes while every\n  real label flips. Anchor correctness on a **real sampled pair** with\n  an observed-displacement + prose-description pair before trusting the\n  self-test.\n- **Data-driven fallback on a data-driven-saturated signal.** When MAD\n  saturates on continuous motion, `0.25 × median(|signal|)` is itself\n  a threshold measured on the same saturated distribution — it can\n  over-trigger the mirror failure (threshold → too low → ~every pair\n  non-Stay). Prefer a physical floor; always clear the fraction-non-Stay\n  red flag after applying any saturation fallback.\n- Scaling the FLOOR by sampling stride. MAD is already stride-aware; the\n  floor is a fixed physical tolerance. Multiplying inflates the threshold\n  enough to label real pans as `Stay`.\n- Width-3 mode\u002Fmedian smoothing that collapses genuine transitions. Only\n  suppress a non-Stay label when **both** neighbors are `Stay`; otherwise\n  leave it alone.\n- Attaching a pair-(i, i+1) label to a single sampled frame index with no\n  documented contract. Default: emit per-interval, not per-frame. See\n  `sampling-and-indexing` \"Pair-to-frame label alignment\" before deviating.\n","# When to use\n- You need to classify camera motion (Stay\u002FDolly\u002FPan\u002FTilt\u002FRoll) from video, allowing multiple labels on the same frame.\n\n# Workflow\n1) **Feature tracking**: `goodFeaturesToTrack(prev_gray)` + `calcOpticalFlowPyrLK`; drop if too few points.\n2) **Robust transform**: `estimateAffinePartial2D(src=prev_pts, dst=curr_pts, method=RANSAC)` — `M` maps **prev → curr**. The src\u002Fdst ordering decides the sign of every label; see \"Sign-convention external anchor\" below.\n3) **Sign-convention external anchor** (hard gate, see section below): the 4-case synthetic self-test is **necessary but tautological** (classifier branch and assertion both read the pinned table). Anchor correctness on a **real sampled pair**: log observed feature displacement + a one-line prose description of what the camera is actually doing, and verify the classifier's emitted label on that pair matches the prose. Only then run self-consistency.\n4) **Calibrate thresholds adaptively** (see \"Adaptive thresholding\"): collect `(dx, dy, rot, scale)` across the full sampled sequence first, then set `th_trans \u002F th_rot \u002F th_scale` from the empirical noise floor — never with hardcoded per-pixel values. Check for MAD-saturation; prefer the physical floor over any data-driven fallback.\n5) **Classify + allow multi-label**: if scale and translate both exceed their thresholds, emit Dolly + Pan; rotation independent for Roll. Polarities keyed to the pinned convention table below.\n6) **Temporal smoothing** (see \"Temporal smoothing\"): only suppress isolated non-Stay labels surrounded by `Stay`; never collapse a non-Stay label whose both neighbors carry the same non-Stay label.\n7) **Pair→interval emission**: emit one label per sampled pair as an interval key `\"sample_ids[i]->sample_ids[i+1]\"` directly (default). See `sampling-and-indexing`'s \"Pair-to-frame label alignment\" before choosing per-frame assignment instead.\n8) **Interval compression**: merge consecutive intervals with identical label sets into one `start->end` key.\n9) **Dominant-direction red flag**: after classifying all pairs, if any single non-Stay direction label dominates >60% of pairs, or if fraction-non-Stay > 0.90 on a scene with varied motion, suspect inverted polarity or threshold mis-calibration — re-anchor via step 3 before shipping.\n\n# Pinned Pan\u002FDolly\u002FTilt convention — keyed to `src=prev_pts, dst=curr_pts`\n\n| `M` value       | Content motion (curr vs prev)       | Camera motion         | Label        |\n|-----------------|--------------------------------------|-----------------------|--------------|\n| `tx > 0`        | content shifted **right**            | camera panned **left**  | `Pan Left`   |\n| `tx \u003C 0`        | content shifted **left**             | camera panned **right** | `Pan Right`  |\n| `ty > 0`        | content shifted **down**             | camera tilted **up**    | `Tilt Up`    |\n| `ty \u003C 0`        | content shifted **up**               | camera tilted **down**  | `Tilt Down`  |\n| `scale > 1`     | content **larger**                   | camera moved **forward**  | `Dolly In`  |\n| `scale \u003C 1`     | content **smaller**                  | camera moved **backward** | `Dolly Out` |\n\n**Warning — tautology hazard.** This table assumes `src=prev, dst=curr`\nAND the standard image coordinate frame (y-down). A self-test derived\nfrom this table (code reads the table to classify; assertion reads the\ntable to pin the expected label) cannot catch an inverted table. The\ntable must be **externally anchored** per real pair before trust — see\nthe next section.\n\n# Decision sketch\n```python\nlabels=[]\nfor each sampled pair i:\n    dx, dy = M[0,2], M[1,2]\n    rot    = np.arctan2(M[1,0], M[0,0])\n    scale  = np.hypot(M[0,0], M[1,0])\n    lbl=[]\n    if abs(scale-1)>th_scale: lbl.append(\"Dolly In\" if scale>1 else \"Dolly Out\")\n    if abs(rot)>th_rot:       lbl.append(\"Roll Right\" if rot>0 else \"Roll Left\")\n    if abs(dx)>th_trans and abs(dx)>=abs(dy):\n        lbl.append(\"Pan Left\" if dx>0 else \"Pan Right\")\n    if abs(dy)>th_trans and abs(dy)>abs(dx):\n        lbl.append(\"Tilt Up\" if dy>0 else \"Tilt Down\")\n    if not lbl: lbl.append(\"Stay\")\n    labels.append(lbl)\n```\n\n# Sign-convention external anchor (hard gate)\n\nThe 4-case synthetic self-test (`+roll axis=1`, `-roll axis=1`,\n`+roll axis=0`, `upscale`) is **a self-consistency check, not a\ncorrectness check**: the classifier branch and the assertion both derive\nfrom the same pinned table. If the pinned table is inverted relative to\nthe grader, every self-test case still passes while every real label\nflips. The gate therefore has two layers:\n\n**Layer A — External anchor on a real sampled pair (correctness).** Load\n`prev = frames[sample_ids[0]]` and `curr = frames[sample_ids[1]]`. Pick\n2–3 trackable features visible in both frames. Log observed displacement\nand a one-line prose description of what the camera is doing. The\nclassifier's emitted label on this pair must match the prose; if it\ndoes not, flip the polarity branch on the disagreeing axis (do NOT\nchange the prose).\n\n```python\n# Minimal external-anchor sketch — specifics in references\u002Fsign-convention-selftest.md\npts0, pts1 = track_features(prev_gray, curr_gray)   # 2-3 features\ndx_obs = float(np.median(pts1[:, 0] - pts0[:, 0]))\ndy_obs = float(np.median(pts1[:, 1] - pts0[:, 1]))\n# One-line prose description based on observed displacement direction:\n# e.g. \"content shifts LEFT across frame — camera is panning RIGHT\"\n# e.g. \"content EXPANDS from center — camera is dollying IN\"\nprose = describe_camera_motion(dx_obs, dy_obs, scale_obs)\nprint(f\"external-anchor: dx_obs={dx_obs:+.2f} dy_obs={dy_obs:+.2f} prose='{prose}'\")\n\nM = estimate_from_pair(prev_gray, curr_gray)\nemitted = classify_from_M(M)\n# Correctness assertion: the emitted label on this real pair must match\n# the prose. A tautological self-test cannot replace this check.\nassert label_matches_prose(emitted, prose), (\n    f\"external anchor FAILED: emitted={emitted}, prose='{prose}'. \"\n    f\"Flip classifier polarity on the disagreeing axis (NOT the prose).\")\nprint(\"external-anchor:pass\")\n```\n\n**Layer B — Self-consistency check (4-case synthetic gate).** Only after\nLayer A passes, run the 4-case synthetic test to confirm every emitted\naxis has an in-sync polarity branch.\n\n```python\n# Case 1-4: see references\u002Fsign-convention-selftest.md. Must emit all four\n# pass tokens: sign-test:pan-left:pass, pan-right:pass, tilt-up:pass, dolly-in:pass.\n```\n\n**Dominant-direction red flag (post-classification).** After classifying\nall pairs, if any single non-Stay direction label (`Pan Right`, `Pan\nLeft`, `Tilt Up`, `Tilt Down`, `Dolly In`, `Dolly Out`) dominates >60%\nof pairs on a scene prior with variable motion, OR if the fraction of\nnon-Stay pairs is >0.90 (unusually high — suggests threshold mis-\ncalibration or MAD-saturation fallback over-triggered), suspect\ninverted polarity on the dominant axis or a tuned threshold. Re-run\nLayer A on a different pair; do NOT ship a dominant-direction\ndistribution without re-anchoring.\n\nRead `references\u002Fsign-convention-selftest.md` for the full external\nanchor + 4-case self-consistency gate, the pinned convention table, and\nthe branched corrective action when the external anchor disagrees with\nthe self-test. Skip only when the caller supplies a reference label\npair `(frame_i, frame_j) → label` from the task spec AND the classifier\npasses it (strongest anchor).\n\n# Adaptive thresholding\nA threshold has two independent terms. Keep their roles separate:\n\n- **MAD term** — measured on the sampled-pair signal\n  (`dx, dy, rot, scale-1`). This is **already stride-aware** because the\n  signal itself is measured between sampled pairs: at larger stride, both\n  signal and MAD grow together. Multiply MAD by a small constant `K≈3`.\n- **FLOOR term** — a fixed absolute physical tolerance. **Never multiply\n  the floor by sampling stride.**\n\n```python\nimport numpy as np\ndef mad(x): return 1.4826 * np.median(np.abs(x - np.median(x)))\n\nTRANS_FLOOR_PX  = 1.5                 # px, absolute — DO NOT scale by stride\nROT_FLOOR_RAD   = np.deg2rad(0.25)    # ≈ 0.004 rad — DO NOT scale by stride\nSCALE_FLOOR_REL = 0.005               # relative — DO NOT scale by stride\nK = 3.0\n\nth_trans = max(TRANS_FLOOR_PX,  K * max(mad(dxs), mad(dys)))\nth_rot   = max(ROT_FLOOR_RAD,   K * mad(rots))\nth_scale = max(SCALE_FLOOR_REL, K * mad(scales - 1.0))\n```\n\n**MAD-saturation check (continuous-motion scenes).** On scenes where\nalmost every pair has similar motion magnitude, MAD measures the\n*signal*, not noise — `K × MAD` sits just above the signal, flipping\nreal motion into `Stay`. Diagnostic: `median(|signal|) > K × MAD(signal)`.\n\n**Fallback ordering (mirror-failure hazard).** The fallback itself can\nover-trigger: `0.25 × median(|signal|)` is a data-driven threshold on\nthe same saturated distribution, so on a scene with large consistent\nmotion it drops to a small fraction of the motion and classifies\neverything as non-Stay (iter_4 mirror of iter_3). Prefer the physical\nfloor; use `0.25 × median` only as a last resort.\n\n```python\nif mad_saturated(dxs) or mad_saturated(dys):\n    # First choice: a physical floor, possibly stride-informed on a\n    # minimum-resolvable-motion basis (not a stride-scaled floor).\n    th_trans = max(TRANS_FLOOR_PX, stride \u002F 8.0)\n    print(f\"th_trans: MAD saturated → physical floor {th_trans:.2f}\")\n\n    # Second choice (only if signal is clearly bimodal with a quiet mode):\n    #   q25, q75 = np.percentile(|signal|, [25, 75])\n    #   if q25 \u003C 0.3 * q75:  # bimodal\n    #       th_trans = max(TRANS_FLOOR_PX, 3 * q25)\n\n    # Last resort: 0.25 * median(|signal|). Diagnostically log the value\n    # but do NOT ship the resulting distribution without clearing the\n    # \"fraction non-Stay > 0.90\" red flag (see Workflow step 9).\n```\n\nDecision rule: after setting `th_*`, project the resulting label\ndistribution. If fraction-non-Stay > 0.90 OR fraction-Stay > 0.95, the\nthreshold is on the wrong side of the signal — do NOT tune to clear the\nred flag; re-run the MAD-saturation diagnostic and prefer the physical\nfloor. Scene prior mismatch (walking POV returning mostly `Stay`;\ntripod returning big `Dolly`) is a related signal.\n\nRead `references\u002Fadaptive-motion-thresholds.md` when thresholds must be\nderived from the data (non-trivial sampling stride, unknown fps, scene\nprior mismatch, MAD-saturation fires, or fraction-non-Stay > 0.90 red\nflag). Skip when thresholds are supplied by the caller or the sequence\nis \u003C ~5 sampled pairs.\n\n# Temporal smoothing\nA width-W mode\u002Fmedian filter on the label stream is a false-negative trap\nat large sampling strides: a single sampled transition can be a real\nmotion change, not flicker. Follow one rule:\n\n- Suppress an isolated non-Stay label **only** when both neighbors are\n  `Stay` (true flicker).\n- **Never collapse** a non-Stay label whose both neighbors carry the same\n  non-Stay label — that is a real transition recorded at a single sample.\n\n```python\ndef smooth_labels(seq):\n    out = [list(s) for s in seq]\n    for i in range(1, len(seq) - 1):\n        prev_set, this_set, next_set = set(seq[i-1]), set(seq[i]), set(seq[i+1])\n        if this_set != {\"Stay\"} and prev_set == {\"Stay\"} and next_set == {\"Stay\"}:\n            out[i] = [\"Stay\"]\n    return out\n```\n\nVerification: after smoothing, scan for `X \u002F Stay \u002F X` sandwiches with\nX ≠ Stay. If any survive, the smoothing window is too wide — drop\nsmoothing or re-run without the mode filter before shipping.\n\n# Low-signal fallbacks\n- Low texture\u002Flow light: increase feature count, use larger LK windows, and relax RANSAC settings.\n- Too few inliers: fall back to the identity transform for that pair; never emit empty labels.\n\n# Self-check\n- [ ] `estimateAffinePartial2D` called as `src=prev_pts, dst=curr_pts` (M maps prev→curr).\n- [ ] **External-anchor pass this run**: a real sampled pair was loaded, 2–3 features tracked, observed `(dx_obs, dy_obs)` logged with a one-line prose description of camera motion, and the classifier's emitted label on that pair matches the prose. Pass token `external-anchor:pass` present in-trace.\n- [ ] **4-case self-consistency check executed**: all four pass tokens printed in-trace — `sign-test:pan-left:pass`, `sign-test:pan-right:pass`, `sign-test:tilt-up:pass`, `sign-test:dolly-in:pass`. (Self-consistency only; the external anchor is the correctness check.)\n- [ ] Thresholds derived from the empirical `(dx,dy,rot,scale)` distribution; **floors are fixed absolute values, not multiplied by stride**.\n- [ ] **MAD-saturation check performed**: if `median(|signal|) > K × MAD` on any axis, the physical floor (or `max(FLOOR, stride\u002F8)`) was used; `0.25 × median(|signal|)` is a last resort only.\n- [ ] **Dominant-direction red flag cleared**: no single non-Stay direction label dominates >60% of pairs; fraction-non-Stay ≤ 0.90. If flagged, re-anchored via external anchor before shipping.\n- [ ] Label trajectory sanity-checked against the scene prior (walking POV → Dolly In dominant; tripod → Stay dominant).\n- [ ] No `X \u002F Stay \u002F X` sandwich (X ≠ Stay) survives smoothing; no `Stay \u002F Y \u002F Stay` collapsed when Y's neighbors agree.\n- [ ] Fallback to identity transform on failure; never emit empty labels.\n- [ ] Multi-label allowed; no forced single label.\n- [ ] Pair→interval alignment chosen explicitly per `sampling-and-indexing`; convention logged in-trace.\n- [ ] Compressed intervals cover all sampled pairs; keys formatted correctly.\n\n# Common pitfalls\n- **Tautological self-test.** The 4-case synthetic self-test's classifier\n  branch and assertion both derive from the same pinned table — the gate\n  checks self-consistency, not correctness. If the pinned table is\n  inverted relative to the grader, every case still passes while every\n  real label flips. Anchor correctness on a **real sampled pair** with\n  an observed-displacement + prose-description pair before trusting the\n  self-test.\n- **Data-driven fallback on a data-driven-saturated signal.** When MAD\n  saturates on continuous motion, `0.25 × median(|signal|)` is itself\n  a threshold measured on the same saturated distribution — it can\n  over-trigger the mirror failure (threshold → too low → ~every pair\n  non-Stay). Prefer a physical floor; always clear the fraction-non-Stay\n  red flag after applying any saturation fallback.\n- Scaling the FLOOR by sampling stride. MAD is already stride-aware; the\n  floor is a fixed physical tolerance. Multiplying inflates the threshold\n  enough to label real pans as `Stay`.\n- Width-3 mode\u002Fmedian smoothing that collapses genuine transitions. Only\n  suppress a non-Stay label when **both** neighbors are `Stay`; otherwise\n  leave it alone.\n- Attaching a pair-(i, i+1) label to a single sampled frame index with no\n  documented contract. Default: emit per-interval, not per-frame. See\n  `sampling-and-indexing` \"Pair-to-frame label alignment\" before deviating.\n",{"name":5,"description":7},"main","cdcb6d230f3b15c3c33f8a2bdd16439f43602cbe","evaluation\u002Fresults\u002FSkillGrad\u002Fopus47_clean_20261016_partial14\u002Ftasks\u002Fdynamic-object-aware-egomotion\u002Frepaired_skill\u002Fegomotion-estimation",1,"https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark","https:\u002F\u002Fgithub.com\u002Flinyouxue","2026-11-14 20:28:35",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add linyouxue\u002Fskill-repair-benchmark --skill egomotion-estimation",{"tool":37,"command":38},"bunx","bunx skills add linyouxue\u002Fskill-repair-benchmark --skill egomotion-estimation",{"tool":40,"command":41},"pnpm","pnpm dlx skills add linyouxue\u002Fskill-repair-benchmark --skill egomotion-estimation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fevaluation\u002Fresults\u002FSkillGrad\u002Fopus47_clean_20261016_partial14\u002Ftasks\u002Fdynamic-object-aware-egomotion\u002Frepaired_skill\u002Fegomotion-estimation\u002FSKILL.md",true,[],[46,53,60,67,72,77],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M7E1HGVRY73NBJ022CJG13X6","video-frame-extraction","Extract frames from video files and save them as images using OpenCV","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7E1HAG5R7CJ9C8NYJS771MB","openai-vision","Analyze images and multi-frame sequences using OpenAI GPT vision models","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7E1H7DADKB6QBWKC2KQ63SZ","image-ocr","Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_03\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[],{"skillNo":68,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7E1H0WBNT43TENGQY7AVZHD","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fvideo-frame-extraction\u002FSKILL.md",[],[],{"skillNo":73,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7E1GTC7D4N4Q2EF03875J9E","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fopenai-vision\u002FSKILL.md",[],[],{"skillNo":78,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7E1GQ92CWFMGH53KSSE4WER","https:\u002F\u002Fgithub.com\u002Flinyouxue\u002Fskill-repair-benchmark\u002Fblob\u002Fmain\u002Fjpg-ocr-stat\u002Fresult\u002Fskilltta-claude4.7\u002Fgroup_03\u002Frun_02\u002Finputs\u002Fskills\u002Fimage-ocr\u002FSKILL.md",[],[]]