nx_motion.nx
buildroot/runtime/nx_motion.nx
about
nx_motion.nx -- frame-to-frame motion (Lucas-Kanade optical flow).
Brightness-constancy + small-motion assumption:
I(x, y, t) = I(x + u, y + v, t + 1)
Taylor expand:
I_x * u + I_y * v + I_t = 0
Over an N-pixel window this is N equations in 2 unknowns; solve
via 2x2 least-squares (normal equations + Cramer's rule).
What this unlocks:
+ motion detection (frame diff)
+ tracking (per-pixel flow vectors)
+ camera-motion estimation (mean flow direction)
+ scene-cut detection (flow magnitude spike)
+ activity recognition substrate
Returns flow in Q8 sub-pixel precision (1 unit = 1/256 pixel).
5x5 integration window default.
genealogy_id: lucas_kanade_1981 + horn_schunck_1981
lineage_id: gradient_based_optical_flow + 2x2_least_squares
dependencies 2 imports · 1 importers
imports: syscalls.nxnx_image.nx
imported by: nx_motion_test.nx
structs
| 90 | struct FlowField |
consts
| 32 | const NX_MOTION_Q: i64 = 256 // Q8 sub-pixel |
| 33 | const NX_MOTION_WIN: i64 = 5 // 5x5 integration |
functions
| 39 | func nx_motion_frame_diff(a: *Image, b: *Image) -> *Image |
| 64 | func nx_motion_temporal_grad(frame1: *Image, frame2: *Image) -> *ImageS64 |
| 95 | func nx_motion_lucas_kanade(frame1: *Image, frame2: *Image) -> *FlowField |
| 163 | func nx_motion_mean_flow(flow: *FlowField, mag_threshold: i64, |