Dynamic object aware egomotion

From XuShuwenn/RedAct · View interactive version

Dynamic object aware egomotion is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Analyze video files for camera motion (egomotion) and detect dynamic objects, outputting motion labels and binary masks.

How to use this skill

Skill file

Dynamic Object Aware Egomotion Detection

When to Use

Completion Rule

Treat the task as incomplete until both output files exist at the required paths:

Do not stop at environment exploration, package inspection, frame extraction, or a written summary. Use reconnaissance only to unblock execution, then run the analysis and save the artifacts.

If the environment or task specifies a required runtime/tool-call protocol or exact completion string, follow it exactly.

Treat protocol requirements as hard correctness constraints.

Output Files

  1. /root/pred_instructions.json - Frame intervals to motion labels
  2. /root/pred_dyn_masks.npz - Binary masks for dynamic objects

Important indexing and coverage rules:

Motion Labels

Valid labels: Stay, Dolly In, Dolly Out, Pan Left, Pan Right, Tilt Up, Tilt Down, Roll Left, Roll Right

Format:

{
  "0->1": ["Pan Right"]
}

Use interval keys over sampled-frame positions, not raw frame IDs. If sampled frames are [0, 10, 20, 30] in the source video, transitions are keyed as "0->1", "1->2", "2->3" — not "0->10", "10->20".

Treat motion predictions as labels for transitions between consecutive sampled frames, not labels for individual frames. If you have N sampled frames, there are N-1 adjacent transitions; a per-transition label at position i maps to interval "i->i+1" before any compression/merging. Do not assign a standalone motion label to frame 0 by itself.

Stay is mutually exclusive with all active motion labels; do not emit Stay together with Pan, Tilt, Roll, or Dolly for the same interval.

Prefer the smallest plausible label set per interval. Treat motion prediction as selecting the single dominant camera-motion label by default unless the task specification explicitly permits multi-label intervals with clear visual evidence. After any smoothing, merging, or voting, re-enforce that if Stay is present, it is the only label for that interval.

When compressing consecutive sampled-frame motions into intervals, ensure coverage spans the full sampled sequence, including the final sampled frame. Example: if 22 sampled frames all share one motion label, use "0->21".

Do not use a reduced classifier that can only emit pan/tilt/stay. The task label space includes Dolly In, Dolly Out, Roll Left, and Roll Right.

Before writing JSON, verify that interval keys use sampled-frame index space and that every label is one of: Stay, Dolly In, Dolly Out, Pan Left, Pan Right, Tilt Up, Tilt Down, Roll Left, Roll Right.

Proven baseline for motion inference: estimate a global partial affine transform between consecutive sampled frames from tracked features (for example with goodFeaturesToTrack + calcOpticalFlowPyrLK + estimateAffinePartial2D), then map translation, scale, and rotation to the allowed motion labels.

Mask Format (CSR Sparse)

For frame i, store in NPZ:

Index mask entries by sampled-frame position.

Implementation guardrails:

Dynamic-object detection default: when the camera moves, estimate global inter-frame motion first, warp one frame into the other view, then threshold residual differences rather than relying on raw frame differencing.

CSR serialization hint: when writing keys without SciPy, derive indices and indptr from the binary mask row-by-row so indices, data, and indptr stay internally consistent even for empty rows or fully empty frames.

After saving the NPZ, run a quick programmatic validation that checks key presence, shared shape, and CSR consistency before finalizing.

Key Parameters

Required Workflow and Done Criteria

  1. At startup, check for any task-specific protocol constraints on tool calls or final signaling; protocol compliance is part of completion.
  2. After brief reconnaissance, switch to execution. If you catch yourself preparing a report before both artifacts exist, stop and resume the pipeline.
  3. Prefer one end-to-end pipeline/script that samples frames once and produces both deliverables from the same sampled-frame sequence; reuse shared decoding, tracking, and motion estimates so JSON intervals and NPZ mask indices stay aligned.
  4. If a traceback identifies a concrete fix, inspect the surrounding code for the reported line/function, patch the exact failing line or call, verify the edit is present, then rerun.
  5. After any failed run, treat existing /root/pred_instructions.json and /root/pred_dyn_masks.npz as stale until a later successful run regenerates them.
  6. If transform estimation fails on some interval, handle that interval explicitly rather than silently skipping frames or leaving coverage gaps.
  7. Before writing outputs, run a spec-first validation pass independent of the generator: confirm JSON interval endpoints are sampled-frame indices, NPZ keys are f_0_* through f_{N-1}_* for the same sampled-frame sequence, and no raw source-frame numbers appear in either file.
  8. Explicitly compare counts before finalizing: if there are N sampled frames, the NPZ must contain mask entries for all indices 0..N-1, and the motion JSON must cover the same sampled-frame index sequence through N-1.
  9. Treat boundary indices as mandatory checks: verify frame 0 and the final sampled frame are both represented in the exported outputs.
  10. Treat file-format validation as necessary but insufficient: inspect representative sampled frames or clips, confirm motion labels match visible camera motion, and confirm masks isolate moving objects rather than camera-motion residuals.
  11. Keep the script or command sequence that produced the outputs until final semantic validation and any protocol-specific completion handoff are complete; do not delete debugging artifacts immediately after the first successful run.

Required Workflow and Done Criteria

  1. Read/sample the video at the target rate.
  2. Infer camera motion for sampled-frame intervals and write /root/pred_instructions.json.
  3. Detect dynamic objects for each sampled frame and write /root/pred_dyn_masks.npz in the required CSR key format.
  4. Treat frame extraction, sampling metadata, and environment inspection as preparation only; they are not task completion.
  5. If a run fails and you identify a fix, rerun after applying the fix; treat outputs from earlier failed runs as stale until regenerated successfully.

Tips

```python

flow = cv2.calcOpticalFlowFarneback(

prev_gray, next_gray, None,

pyr_scale=0.5, levels=3, winsize=15,

iterations=3, poly_n=5, poly_sigma=1.2, flags=0

)

```

Tips

Final Validation

Before declaring completion, open and inspect the deliverables, not just their file paths.

Also verify the interaction contract is complete: if the task required a specific action syntax or exact completion token, ensure your final response uses that exact form rather than a narrative summary.

If either required artifact is missing, unreadable, stale from an earlier failed run, or replaced by preprocessing outputs, do not finalize; resume the pipeline and regenerate the true deliverables first.

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.