STI hublaser labcolor challenge ↗
Summer Teacher Institute · a lab you can run today

Optical flow — how does a computer know something moved?

Four stages, on your own webcam. Each one works, each one breaks, and each one's breakage picks the next. At the end the motion is a grid of numbers your turtles can read.

↩ this lesson is a chip from the laser page, cashed in The laser lab ends on a map of what a webcam question opens. Two of its branches were marked “still open · nobody built this yet.” This page is those two, built: frame difference and tracking things over time.
“Keep the previous frame and show me only the pixels that changed. Could we find the laser by its movement instead of its color?”
That's the student prompt from the laser page's frame difference chip. The answer turns out to be yes — and then to get very interesting, very fast.
Camera off. Nothing is running. 🔒 nothing leaves this laptop

Where did something change?

The cheapest possible motion detector: keep the last frame, subtract it from this one, and look at what's left. Anything that didn't move cancels to zero.

Drag to 0 to see the raw |Δ|, including sensor noise.
moving pixels: 0 (0.0% of frame)
mean |Δ| this frame: 0.0
processing at: 160 × 120, upscaled

Try it: hold still — the screen goes black. The camera only exists where something changes.

The proof that this cannot see direction

Not an opinion. Below are the same two frames of a bar. On the left they play in order; on the right, in the opposite order. Same frames, opposite motion. Watch what the frame difference does.

Frame 1 → Frame 2 · the bar moves right →
its frame difference |F1 − F2|
Frame 2 → Frame 1 · the bar moves ← left
its frame difference |F2 − F1|
Largest difference found anywhere between those two results: 0. They are the same image. Because |a − b| = |b − a| — the absolute value throws away the sign, and the sign was the only record of which way time ran.
⚡ The flaw that chooses the next stage

It tells you where something changed. It does not tell you which way it went.

A hand moving left and a hand moving right light up identically. Do it now, in front of the camera: wave left, then wave right. You cannot tell the two apart on screen, and neither can the computer — the proof above is why. To get direction we have to stop asking “did this pixel change?” and start asking “where did this patch go?”

Honest limit · brightness constancy

Flick the lights, or cover the lens. The whole frame lights up and the “moving pixels” readout jumps toward 100%. Nothing moved. Every method on this page — all four stages — assumes brightness constancy: that a point on an object keeps the same brightness from one frame to the next. When the lights change, that assumption is false, and the flow lies.