MotionTracker

Track background translation between screen frames using native OpenCV multi-patch matching. Construction does not capture a frame; at most 16 trackers may be open per flow. This does not detect a player or locate an atlas. Exclude the HUD and character; handle game zoom externally with template matching and scale. Suspected zoom or rotation produces LOST, not a zoom estimate.

Syntax

MotionTracker(region=None, exclude=None, max_displacement=80, max_gap_ms=850, max_frame_age_ms=250)

Constructor parameters

NameDescription
regionRegion | None
Tracking rectangle in screen pixels, entirely inside the current screen, with finite positive width and height. None selects the full screen. Its coordinates are frozen when constructed. A very small or narrow region raises an error; choose a larger region.
Optional · Positional or named
Default: None
excludelist | tuple | None
Up to 32 Regions to exclude, clipped to the tracking rectangle. Each has finite positive width and height; coordinates are frozen when constructed. None excludes nothing.
Optional · Positional or named
Default: None
max_displacementNumber (1..256)
Maximum finite displacement per axis in screen pixels; default 80.
Optional · Positional or named
Default: 80
max_gap_msNumber (1..5000)
Maximum whole-number gap between frames in milliseconds; default 850.
Optional · Positional or named
Default: 850
max_frame_age_msNumber (1..5000)
Maximum whole-number frame age in milliseconds; default 250.
Optional · Positional or named
Default: 250

Returns

Example

# Track background motion between captured frames
tracker = MotionTracker()
first = tracker.update()
wait(100)
result = tracker.update()
if result.status == "TRACKED":
    print(result.dx, result.dy)
tracker.close()

Methods

3 methods

MotionTracker.update

Read the current captured frame and return its motion result. Screen capture must already have explicit consent and be ready. INITIALIZED establishes a baseline; TRACKED reports accepted translation. STALE means a duplicate, future or already too old frame before processing and leaves the baseline unchanged. LOST clears continuity so the next fresh valid frame initializes again. If a frame becomes too old during processing or Pause occurs before handoff, LOST has reason processing_frame_too_old. Raises an error after close.

Syntax

tracker.update()

Returns

Example

Not documented

MotionTracker.reset

Clear the baseline while keeping the tracker usable. Raises an error after close.

Syntax

tracker.reset()

Returns

None

Example

Not documented

MotionTracker.close

Release the tracker; repeated calls are safe. Handles are also released when the macro or flow ends, stops or fails. A handle can be reused across actions in the same executor and is isolated from other flows.

Syntax

tracker.close()

Returns

None

Example

Not documented