cleoanka

an interactive page · computer vision

From pixels to kilometres

Four points that undo perspective, a tracker that does not lose what it cannot see, and a tiny language that reads traffic rules.

canvas & code, no dependencies · panoptes on GitHub


1

Four points undo perspective

A camera sees the road at a slant: a metre far away covers far fewer pixels than a metre up close. Speed in pixels is therefore meaningless; the same car seems to slow down as it heads for the horizon. But the road is a flat plane, and the relation between two images of a plane is captured exactly by a single 3×3 matrix, a homography. To find it you only need to mark the four corners of a rectangle of known size on the road.

FIG. 1 — Left, the camera image; right, the bird’s-eye view rectified by the homography. The golden handles are the corners of a road patch 7 m wide and 30 m long. Drag them: when the calibration goes wrong the bird’s-eye view warps and speed estimates drift from the truth.

With a correct calibration the estimated speeds sit within a few percent of the truth. Moving a handle by only a few pixels already inflates the errors, because distant pixels carry many more metres. That is why panoptes does not leave calibration to hand clicks alone; it cross-checks against known measures like lane width and reports with a confidence range.

2

A tracker that keeps what it cannot see

The detector produces boxes and confidence scores every frame. The tracker’s job is to link those boxes to the same car across frames. The hard moment is when a car passes behind a pole or another vehicle: the detector either misses it or sees it with low confidence. A naive tracker throws low-confidence boxes away, loses the track and hands the car a new identity when it reappears.

ByteTrack’s idea is simple and strong: first match high-confidence boxes to existing tracks, then try matching the leftover tracks to the low-confidence boxes too. Meanwhile tracks are carried forward by a motion model even while invisible. panoptes implements this from scratch, with a clean licence.

FIG. 2 — Cars pass behind a grey occluder, where the detector sees them with low confidence or not at all. Box colour is the track identity. Switch methods and compare the number of identity switches.
3

A tiny language that reads rules

Detection and tracking are just raw material. The real question is “what happened?”: who broke the speed limit, which truck is in the left lane, which car stopped in a no-stopping zone. panoptes has these rules written in a declarative language instead of buried in code; changing a rule needs no rebuild. The editor below is a miniature of the same idea: every line is a rule and the events change as you type.

FIG. 3 — Syntax: when <condition> -> <label>. Fields: speed (km/h), lane (1 right, 2 left), type (car, truck, bus), zone (A or B). Operators: > < >= <= == !=, and, or. Bad lines are flagged in red.
homography
The 3×3 matrix turning the road plane’s image into metres; found from four points.
bytetrack
Two-stage matching that also uses low-confidence detections; identities survive occlusion.
rule dsl
Defining events with declarative rules; changing a rule changes no code.