Computer vision
Real London traffic cameras, analysed in your browser: road users detected, tracked with ids and counted across a line, by type and direction.
~900
Live cameras
6
Road-user types
≈10 s
Clip length
1 relay route
Server code
Overview
Counting vehicles and people is one of the most common real-world jobs for computer vision: city planning, road works, shop footfall. The hard part isn't seeing a car in one frame, it is knowing that the car in the next frame is the same one, so it is counted once.
This project takes the newest clip from any of Transport for London's open traffic cameras, detects road users in every frame with EfficientDet-Lite0, links them into tracks with ids and trails, and counts each track once when it crosses a line you place, by type and direction. A small route on this site relays the clip so the browser is allowed to analyse it.
How it works
From raw file to prediction.
Every number below comes from the training run.
- 01
Camera
~900 in London
TfL JamCams, open data
- 02
Relay
one route
Same-origin clip, so pixels can be read
- 03
Detect
6 road-user types
EfficientDet-Lite0 (COCO)
- 04
Track
ids + trails
Overlap matching with predicted motion
- 05
Count
once per track
Line crossing, with direction
- 06
Show
live dashboard
Counts by type, in view now
Inside the model
From boxes to a count.
A detector finds road users in every frame; my tracker decides which boxes are the same car and counts each one once. The street is simulated; the tracker is the real code.
The data
Nearly 900 live London cameras, in your browser.
Transport for London publishes its traffic cameras as open data: a short clip from each camera, refreshed every few minutes. This page picks one, detects every road user in it and counts them across a line you place.
TfL JamCams
Open data from Transport for London, used under TfL's Transport Data Service terms (based on the Open Government Licence v2.0). Powered by TfL Open Data. The clips are low resolution, as traffic cameras are, and this project is not affiliated with or endorsed by TfL. The detector is Google's EfficientDet-Lite0, trained on COCO and also used in Live Object Detection.
~900
cameras
≈10 s
clip length
6
road-user types
one relay
server work
Column dictionary
● used by the model
| Column | Type | What it means |
|---|---|---|
| clip | ≈10 s video | Each camera's newest clip, replaced by TfL every few minutes |
| camera | id · name · position | From TfL's Places API (type JamCam), with an 'available' flag |
| boxes | x · y · w · h · class · score | Found in every frame by EfficientDet-Lite0 in your browser |
| tracks | id · path · direction | Built on this page by matching boxes from frame to frame |
01
TfL camera
A real London junction, newest 10-second clip
02
This site's route
Relays the clip from TfL so your browser is allowed to read its pixels
03
Detector
EfficientDet-Lite0 finds cars, buses, trucks, motorbikes, bikes and people
04
Tracker
Boxes are linked frame to frame into tracks with an id and a path
05
Line counter
Each track counts once, with its direction, when it crosses your line
Try it
Count London's traffic, right now.
Pick a junction or search any camera. The newest clip plays, every road user gets a box, an id and a trail, and the counter ticks when they cross the dashed line. Move or turn the line to count other lanes; switch to your own camera to count your street.
Live demo
runs in your browser
Pick a London camera above
Each camera's newest 10-second clip, from TfL's open data. Counting runs in your browser.
Crossed the line
0 in view now
0
| Type | ↓ | ↑ |
|---|---|---|
| 🚗 car | 0 | 0 |
| 🚌 bus | 0 | 0 |
| 🚚 truck | 0 | 0 |
| 🏍️ motorcycle | 0 | 0 |
| 🚲 bicycle | 0 | 0 |
| 🚶 person | 0 | 0 |
Counting line
Place the line across the lanes you want to count; each tracked object counts once, with its direction.
Powered by TfL Open Data. Clips from Transport for London's JamCam cameras, relayed by this site so your browser may analyse them; this project is not affiliated with or endorsed by TfL.
How the counting works
Detection finds things. Tracking makes them countable.
A detector only sees one frame at a time: the same car in the next frame is just another box. Counting needs identity, so every box is linked to the box it was a moment ago. This tracker is written for this page, in the spirit of SORT (Bewley et al., 2016) without the Kalman filter.
01
Predict
Each track's box is moved by its recent speed, so a fast car is still matched next frame.
02
Match by overlap
New boxes join the track they overlap most (IoU ≥ 0.2); cars, buses and trucks can match each other because the detector often swaps those labels.
03
Confirm and coast
A track counts as real after 2 frames, and coasts on its speed for up to 8 missed frames (a lorry hiding a car).
04
Count once
When a confirmed track's centre crosses the line segment, it is counted with its direction and never again.
Honest notes
Counts from a clip, not a traffic census.
Each clip is about ten seconds of one junction, so the numbers describe that moment. Real traffic counters run continuously, often with cameras placed and calibrated for the job.
TfL's open cameras, Google's detector, my tracker, counter and relay, all visible in the Code section below.
| Here | |
|---|---|
| Data | TfL JamCam clips, open data under TfL's Transport Data Service terms; Powered by TfL Open Data; not affiliated with or endorsed by TfL |
| Detector | Google's EfficientDet-Lite0 (COCO, Apache-2.0), pretrained and used as published |
| Built here | The clip relay route, the tracker, line counting with direction, the camera picker and the dashboard |
| Accuracy | Not measured against hand counts. Low-resolution clips mean small or distant vehicles are missed, and heavy overlap can merge or split tracks |
| Server | The site is static except one route that fetches a TfL clip for a TfL camera id and passes it on; it accepts nothing else and stores nothing |
| Privacy | Traffic cameras are low resolution and nothing is stored: frames are analysed in your browser and discarded |
Build notes
How it's built, step by step.
The real code behind this demo, taken from the repository when the site is built. Copy any piece.
In your browser · TypeScript
- 1
Server: the camera list, cached for an hour
Reads TfL's Places API for JamCams and keeps only valid camera ids; 'use cache' with the hours profile, as Next.js 16 recommends.
src/lib/jamcams.ts:15 · 18 lines
/** The camera list changes rarely: cache it for an hour (Cache Components' 'hours' profile). */ export async function jamCams(): Promise<JamCam[]> { "use cache"; cacheLife("hours"); const res = await fetch("https://api.tfl.gov.uk/Place/Type/JamCam", { headers: UA }); if (!res.ok) throw new Error(`TfL camera list: HTTP ${res.status}`); const places = (await res.json()) as Place[]; return places .map((p) => ({ id: p.id.replace(/^JamCams_/, ""), name: p.commonName, lat: p.lat, lon: p.lon, available: p.additionalProperties?.find((a) => a.key === "available")?.value === "true", })) .filter((c) => JAMCAM_ID.test(c.id)) .sort((a, b) => a.name.localeCompare(b.name)); } - 2
Server: relay one camera's newest clip
Accepts only a TfL camera id, streams the MP4 from TfL's bucket and returns it from this site, so the browser may read its pixels.
src/lib/jamcams.ts:34 · 15 lines
/** The latest 10-second clip of one camera, straight from TfL's public bucket. Never cached on the server. */ export async function jamCamClip(id: string): Promise<Response> { if (!JAMCAM_ID.test(id)) return new Response("Unknown camera", { status: 400 }); const res = await fetch(`https://s3-eu-west-1.amazonaws.com/jamcams.tfl.gov.uk/${id}.mp4`, { headers: UA, cache: "no-store" }); if (!res.ok || !res.body) return new Response("Clip unavailable", { status: 502 }); return new Response(res.body, { headers: { "Content-Type": "video/mp4", // TfL refreshes clips every few minutes: let browsers and the CDN reuse one for a minute "Cache-Control": "public, max-age=30, s-maxage=60, stale-while-revalidate=120", "X-Clip-Modified": res.headers.get("last-modified") ?? "", "X-Data-Credit": TFL_CREDIT, }, }); } - 3
How much two boxes overlap
Intersection over union: the score used to decide which new box belongs to which track.
src/lib/tracker.ts:27 · 8 lines
export function iou(a: Box, b: Box) { const x0 = Math.max(a.x, b.x); const y0 = Math.max(a.y, b.y); const x1 = Math.min(a.x + a.w, b.x + b.w); const y1 = Math.min(a.y + a.h, b.y + b.h); const inter = Math.max(0, x1 - x0) * Math.max(0, y1 - y0); return inter / (a.w * a.h + b.w * b.h - inter || 1); } - 4
Did a track cross the line?
The step from the last centre to the new one must cross the counting segment itself; the sign gives the direction.
src/lib/tracker.ts:40 · 10 lines
/** Do segments p→q and the counting line intersect? (so crossings beyond the line's ends don't count) */ function crosses(l: Line, p: { x: number; y: number }, q: { x: number; y: number }) { const s1 = side(l, p); const s2 = side(l, q); if (s1 === 0 || s2 === 0 || s1 === s2) return 0; const m: Line = { x1: p.x, y1: p.y, x2: q.x, y2: q.y }; const a = side(m, { x: l.x1, y: l.y1 }); const b = side(m, { x: l.x2, y: l.y2 }); return a !== b ? (s2 > s1 ? 1 : -1) : 0; }
Notes
The decisions behind it.
Approach
- 1
Checked public CCTV sources: TfL's JamCams and Singapore's traffic images are open data, but their files can't be read by a web page's AI without a relay; Indonesian city feeds publish no reuse terms, so they weren't used.
- 2
Added two Next.js routes: the camera list (cached for an hour) and a relay for one camera's newest clip that only accepts TfL camera ids.
- 3
Ran EfficientDet-Lite0 on every frame for six road-user classes and wrote a tracker: predicted boxes, greedy IoU matching, confirmation, coasting and a class vote.
- 4
Counted each confirmed track once when its centre crosses the counting segment, with direction, and built the camera picker, movable line and dashboard; the same counter runs on a visitor's own camera.
Honest note
Counts describe one ten-second clip of one junction, not traffic volume. They haven't been checked against hand counts: the clips are low resolution, so small or distant vehicles are missed and heavy overlap can merge or split tracks. The detector is Google's, used as published; the tracker, counter and relay are mine. Data: Powered by TfL Open Data; this project is not affiliated with or endorsed by TfL.
Reproduce: src/lib/tracker.ts · src/lib/jamcams.ts · src/components/demos/traffic-demo.tsx
dataset sourceNext project
Head & Blink Keyboard