Egomotion dynmask

From XuShuwenn/RedAct · View interactive version

Egomotion dynmask is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Estimate camera egomotion between sampled video frames and produce dynamic-object masks with CSR storage; validates outputs for downstream use.

How to use this skill

Skill file

Dynamic-Object-Aware Egomotion

This skill provides a reusable workflow to:

Use this when a task requests camera-motion labeling over frame intervals and sparse dynamic masks per sampled frame.

Valid motion labels:

Key outputs expected:

Core Workflow

Phase 1 — Sample at target FPS (default 6):

Phase 2 — Egomotion estimation between consecutive samples:

1) Convert to grayscale

2) Detect features (e.g., goodFeaturesToTrack)

3) Track with calcOpticalFlowPyrLK

4) Estimate global transform with RANSAC (estimateAffinePartial2D); optional: try homography for strong parallax

5) Extract parameters from affine M:

Phase 3 — Dynamic mask per sampled frame (motion-compensated differencing):

1) Warp previous gray to current using the transform

2) Build a valid region mask by warping an all-ones image (avoid border artifacts)

3) Compute diff = abs(curr_gray - warped_prev)

4) Robust threshold on valid pixels:

thr = max(20, median + k * 1.4826 * MAD), with k≈3 (increase to ≈5 in strong parallax scenes)

5) raw = (diff > thr) within valid region

6) Morphological open then close (e.g., 3×3 then 7×7)

7) Connected components; keep regions with area ≥ max(50, area_ratio * H * W), with area_ratio in [0.0005, 0.005] depending on noise/parallax

Phase 4 — Interval compression and serialization:

Phase 5 — Verification (must pass before delivery):

Common Pitfalls and How to Avoid Them

Success Criteria

Optional Script Usage

A validator is provided to check both outputs against the video and target FPS.

Example:

It verifies JSON key/value format, interval coverage against the sampled frame count, NPZ shape, per-frame CSR integrity, and frame count consistency.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.