Interactive Vision From Zero · Episode 09
Body Pose: the 33 Landmarks
Body Pose: the 33 Landmarks is Episode 09 of Interactive Vision From Zero, a MasterAllArts free interactive lesson for artists learning creative 3D on the web.
Part of the MasterAllArts Creative 3D Roadmap .
Last season, a hand was 21 dots. You learned to read them, connect them into a skeleton, and puppet them with your own fingers. This season the camera zooms out: your whole body becomes 33 landmarks — head, shoulders, elbows, wrists, hips, knees, ankles, even your feet — and from those 33 points you can rebuild a glowing skeleton that copies how you stand, wave, and walk.
The demo below is alive right now, with no camera and nothing downloaded: a synthetic figure is strolling in place, and a neon skeleton is tracking every joint. Step through the six stages to watch the raw point cloud turn into a labeled, confidence-aware skeleton. Then click use my camera and the exact same skeleton snaps onto you. Wave. It waves back. 🔒 on-device · nothing uploaded.
What you're looking at
Everything on the canvas is driven by one array of 33 objects, each shaped exactly
like MediaPipe's real output: { x, y, z, visibility }. x and
y are normalized to [0,1] in image space
(x → right, y → down, origin top-left), z is a
rough depth hint, and visibility is a [0,1] confidence that the
joint is actually seen. Because the synthetic walker emits that same shape, every line of
drawing code you'll read works unchanged when the camera swaps in real data.
The figure idles and walks via a tiny procedural generator — arms and legs swing out of phase, the torso sways, the head bobs as it "breathes." Move your mouse over the demo to shove the whole body around; the skeleton follows. None of this needed a webcam, a model download, or a single network request.
Stage 1 — The 33 dots
The rawest view: just the landmark cloud. Thirty-three little points floating where the body's joints are. Squint and you can already read a person in it — two points up top for shoulders, a vertical stack for the spine, four points fanning down for the limbs — but it's loose and ambiguous, the same way Episode 01's hand was just 21 scattered dots before we drew a single bone. This is the data in its purest form, and it's the view you drop to when something's wrong and you need to see the skeleton's skeleton.
Stage 2 — + POSE_CONNECTIONS → the skeleton
Now we add edges. A pose has its own connection list — POSE_CONNECTIONS
— that says which landmark indices to join: 11→12 across the shoulders,
11→13→15 down the left arm, 23→25→27 down the left leg, and so
on. Draw a glowing line for each pair and the cloud snaps into a recognizable body. This
is the single most satisfying upgrade in the episode: the same 33 points, but now they
read as a person.
Stage 3 — Labeled key joints
Thirty-three indices is a lot to hold in your head, so this stage numbers the joints
you'll actually use: shoulders 11/12, elbows 13/14, wrists
15/16, hips 23/24, knees 25/26, ankles
27/28 (and the nose at 0). Toggle labels in
the controls to turn the numbers on in any stage. Memorize these six pairs — every pose
project you ever build indexes into them.
Stage 4 — Visibility
Real tracking is uncertain. When a joint is behind your back, off-screen, or just
hard to see, MediaPipe still reports a position — but with a low visibility
score. This stage fades low-confidence landmarks and flags them, and the
synthetic driver deliberately dips one wrist's visibility as it swings behind the body so
you can watch it dim and recover. Toggle visibility to draw the score
next to each joint. The rule that follows is the whole point of this stage: don't
draw a bone to a joint you can't see.
Stage 5 — Normalized → pixel + mirror
Landmarks arrive normalized; your canvas thinks in pixels. The bridge is two
multiplies — but with a twist, because this is a selfie view. We mirror the X
axis so that when you raise your right hand, the on-screen skeleton raises the
hand on your right. This stage picks one joint (the right wrist) and shows the
live math: the normalized x, y, the flip, and the final pixel coordinate,
updating every frame. Mirrored axes are the number-one source of "why is it backwards"
confusion — so we make the flip visible.
Stage 6 — Pose mirror
The payoff. The full glowing skeleton copies the synthetic walk in real time — and when you click use my camera, the synthetic feed is swapped for the real MediaPipe Pose model and the skeleton starts mirroring you. Same skeleton, same code, different input. Wave, lunge, do a star jump; the bones follow. That swap — one function, two sources — is the architectural heart of the whole series.
How the code works
Four pieces carry the whole demo. First, the connection list and the draw loop — joints first, then bones, with the mirror flip baked into the normalized → pixel map. Notice it skips any bone whose endpoints are below a visibility threshold:
// The body's edges: which of the 33 indices to connect.
const POSE_CONNECTIONS = [
[11,12],[11,23],[12,24],[23,24], // torso
[11,13],[13,15],[12,14],[14,16], // arms
[23,25],[25,27],[24,26],[26,28], // legs
[27,29],[27,31],[28,30],[28,32], // feet
[0,11],[0,12], // neck-ish
];
function drawPose(pose) {
// 1) bones first, so the glowing joints sit on top
ctx.lineWidth = 4;
for (const [a, b] of POSE_CONNECTIONS) {
const p = pose[a], q = pose[b];
if (p.visibility < 0.5 || q.visibility < 0.5) continue; // skip invisible bones
const P = toPixel(p), Q = toPixel(q);
ctx.strokeStyle = 'rgba(56,189,248,0.9)';
ctx.beginPath(); ctx.moveTo(P.x, P.y); ctx.lineTo(Q.x, Q.y); ctx.stroke();
}
// 2) then a glowing dot per landmark
for (let i = 0; i < pose.length; i++) {
const { x, y } = toPixel(pose[i]);
ctx.globalAlpha = 0.3 + 0.7 * pose[i].visibility; // fade low-confidence
ctx.beginPath(); ctx.arc(x, y, dotSize, 0, Math.PI * 2); ctx.fill();
}
ctx.globalAlpha = 1;
}
Second, the camera swap. This is the only place MediaPipe is touched, and
it's a lazy dynamic import() wrapped in try/catch — so a load
with no webcam never errors and never hits the network. Note PoseLandmarker
(not HandLandmarker) and numPoses: 1:
const MP_URL = 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.18';
const MP_WASM = 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.18/wasm';
const POSE_TASK = 'https://storage.googleapis.com/mediapipe-models/pose_landmarker/' +
'pose_landmarker_lite/float16/1/pose_landmarker_lite.task';
let landmarker = null, video = null, usingCamera = false;
async function enableCamera() {
try {
const { PoseLandmarker, FilesetResolver } =
await import(`${MP_URL}`); // lazy — never top-level
const fileset = await FilesetResolver.forVisionTasks(MP_WASM);
landmarker = await PoseLandmarker.createFromOptions(fileset, {
baseOptions: { modelAssetPath: POSE_TASK, delegate: 'GPU' },
runningMode: 'VIDEO', numPoses: 1,
});
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } });
video = document.createElement('video');
video.srcObject = stream; video.playsInline = true; await video.play();
usingCamera = true;
setStatus('camera live · on-device, nothing uploaded');
} catch (err) {
setStatus('camera unavailable — staying on synthetic (' + err.name + ')');
usingCamera = false; // graceful fallback
}
}
Third, the one shared path. The render loop chooses a source — real detection or the
synthetic walker — and funnels both into the same onLandmarks(pose),
which guards against null (lost tracking returns no pose) and then draws.
One downstream path means the camera and the synthetic demo can never drift apart:
function tick(t) {
let pose;
if (usingCamera && landmarker && video.readyState >= 2) {
const res = landmarker.detectForVideo(video, performance.now());
pose = res.landmarks?.[0] || null; // null when no body in frame
} else {
pose = syntheticPose(t * 0.001, mouseActive ? mousePos : autoPos(t * 0.001));
}
onLandmarks(pose); // ONE path for synthetic + camera
}
function onLandmarks(pose) {
if (!pose) { drawEmpty(); return; } // guard: don't crash on lost tracking
drawPose(pose);
}
Fourth, the normalized → pixel helper — two multiplies plus the selfie mirror. This is
the only place the 1 - x flip lives, so synthetic and camera modes mirror
identically:
// normalized [0,1] landmark → canvas pixels, with the selfie X-flip.
function toPixel(lm) {
return {
x: (1 - lm.x) * canvas.width, // mirror: your right → screen right
y: lm.y * canvas.height,
};
}
Common pitfalls
- Pose is not Hands. It's 33 landmarks, not 21 — a different model
(
PoseLandmarker), a different task file, and a different connection list. Don't reuseHAND_CONNECTIONS; the indices mean entirely different joints. - Visibility matters. Every joint always has a position, even when
it's invisible — the only signal that it's bogus is a low
visibilityscore. Draw a bone to an unseen joint and you get a limb flailing off into the corner. Gate on visibility (we use0.5). - The mirror. Forget the
1 - xflip and your skeleton moves the wrong way — raise your right hand, the screen raises its left. Apply the flip in exactly one place (toPixel) so it's impossible to half-apply. - Occlusion is jumpy. When a limb crosses your torso or leaves the frame, its landmarks get noisy and low-visibility — joints will twitch. That's the tracker being honest, not a bug; smooth with a lerp / One-Euro filter if it bothers you.
- The first detection lags. The model is downloaded the moment you
click the camera button, so the first frame or two stall while the
.taskfile fetches. Synthetic keeps running underneath, so the demo never goes blank. - Camera needs HTTPS or localhost. Opened from a bare
file://path,getUserMediais silently blocked — thetry/catchcatches it and you stay on synthetic.
Exercises
- Color left vs right. Left-side indices are odd
(
11, 13, 15, 23, 25, 27), right-side are even (12, 14, 16, 24, 26, 28). Tint left-side bones cyan and right-side bones magenta. Suddenly the mirror is obvious — and so are tracking flips. - Torso center + lean. Average the four torso points
(
11, 12, 23, 24) for a center of mass, then compute the angle of the shoulder-midpoint above the hip-midpoint. Print the lean angle — you've built the seed of a posture or fall detector in about ten lines. - High-visibility-only skeleton. Raise the bone threshold to
0.7and watch limbs vanish the instant they're occluded. Then add a fading "ghost" of the last good position so bones decay instead of popping. This is where pose smoothing begins.
What's next
Episode 10 — Puppet an Avatar. We stop drawing dots and start driving a character: map the 33-landmark skeleton onto a rig so a little figure copies your every move. The bones you drew today become the strings; next episode we hang a puppet on them.