# A Video Is a Table

Class 15, Chapter 8: Seeing Movement: Video and Pose Estimation. 30 slides, about 36.5 minutes.

## 1. Title

Slide up while people sit down. Welcome back after the midterm. Today we start Part Three of the book, video. Every app you will use for the rest of the term reads a video, puts dots on the joints and does geometry on the dots. Today's question is how far each dot is from the real joint.

## 2. Reading your midterm back  (2.5 min)

Your midterms are back. Before you look at the score, do one thing with it. For every point you lost, write one line: which step of the pathway the question was about, and which kind of slip it was. Arithmetic or units, like a rate or a missing unit. A concept, the right formula used for the wrong question. Or a claim, a sentence that says more than the data supports. [Pause.] That list tells you what to practise, and it is worth more than the score. The midterm covered Chapters 1 to 7, and the final is cumulative, so this is the cheapest time to close the gaps. The exam guide is at the link.

## 3. Part III starts here: three steps behind every app  (2 min)

Every app in Part Three of the book does the same three things before it shows you a number. It reads the video one frame at a time. It runs a pose model on each frame, which places dots on the joints. Then it does geometry on the dots. This chapter teaches those three steps once, so Chapters 9 and 10 can use them. The running example is a sketched runner, drawn by hand and animated. A drawing is a fair test: it has the outline of a person but none of the texture of skin and cloth. The goal is not to make you distrust video. It is to let you say how good a number is, and why.

## 4. One row per frame; the row number is time  (2 min)

A digital video is a stack of still pictures called frames, and each frame is a grid of pixels. Think of it as a table with one row per frame. The row number is time: frame k starts at k over f. The time between two frames is the finest step in time the video can resolve. Thirty three milliseconds at thirty frames a second, about four at two hundred and forty. Example 8.1: a sprinter's foot leaves the ground in frame one hundred and twelve and lands in frame one hundred and twenty nine. Seventeen frames at sixty is zero point two eight three seconds. Either end can be a frame off, so it is good to about six percent.

## 5. Two clocks: the stored rate and the capture rate  (2 min)

Here is the trap that catches almost everyone once. In slow motion a phone films at a hundred and twenty or two hundred and forty frames a second, then saves the file to play at an ordinary thirty. Nothing is lost: every frame is kept. They are simply shown at thirty a second, so one real second takes four seconds to play. That is what slow motion is. [Point at the dashed lines.] Twelve frames captured in a tenth of a second play over four tenths. So a file has two rates. The stored rate is the playback clock. The capture rate is the real clock, and every time, rate and speed you report uses it.

## 6. The slow-motion error  (2 min)

[Ask the room; take a few answers before you click.] A jumper is in the air for sixty frames, and the header says thirty frames a second. Two seconds in the air, four point nine one metres: higher than a basketball rim. So something is wrong. The clip was filmed at a hundred and twenty. By what factor is the height wrong? [Click.] Sixteen. The real flight is half a second and the height is zero point three zero seven metres. Time is off by four, and height goes with time squared. You met this trap in Chapter 1. Now you know where it lives: in the file header.

## 7. Listing 8.1: read the headers  (1.5 min)

Here is how you read the stored rate yourself. OpenCV opens each clip and asks for the frame rate and the frame count. Part of the output is below. Look at the names: sixty, a hundred and twenty, sixty. Look at the rates: thirty, thirty, thirty. Every clip in the book's set is stored at thirty, whatever it was filmed at. The back flip plays for four point nine three seconds, but the real flip took one point two three. [Point at the code.] Notice what the code can and cannot know. It reads the stored rate. No program can tell from the file alone that a thirty frames a second file was filmed at a hundred and twenty. Only you know.

## 8. A sprint start in slow motion  (1.5 min)

[Thirty seconds; hands up for A, B, C, D.] The answer is C, half a second. File time times stored over capture: four times thirty over two hundred and forty. A is what you get if you turn the ratio upside down; it is a common slip, and a sanity check catches it, because no sprint start lasts thirty two seconds. B reads the playback clock. D is right for a different phone, one that films at a hundred and twenty. The apps read the stored rate, fall back to sixty when they cannot, and let you choose the rate you filmed at. That setting is the one that matters.

## 9. Five choices before you press record  (2 min)

A pose model can only find what the camera recorded, so most errors you can remove at all, you remove before you press record. Five choices. Square to the motion: a runner from the side, a pelvis from the front or behind. Still and far back: zoom with your feet, not the lens. Light: phones lengthen the shutter in dim light, and a foot moving at ten metres a second smears seventeen centimetres in a sixtieth of a second. Framing: whole body, as large as it fits. And clothing and a reference: close-fitting clothes, and a metre stick in the plane of the movement. We will need that stick in part five.

## 10. A video of a person is personal data  (1.5 min)

A video of a person is personal data, more than a heart rate, because it shows a face and a body. Film yourself first. Before you film a teammate, say what the clip is for, who will see it and when it will be deleted, get written consent, and accept a no. For anyone under eighteen, a parent or guardian consents and the athlete assents, and no image of a minor leaves the team. Keep other people out of the frame. And do not hand a clip to an outside AI service without the athlete's agreement. The course apps help: the video is analyzed in the page and never uploaded.

## 11. What a pose model returns  (2 min)

A pose model is a neural network whose millions of coefficients were tuned until its dots landed close to dots that people drew by hand on hundreds of thousands of photographs. The usual set marks seventeen keypoints. Three consequences follow. First, a keypoint is where a person would have clicked, the visible bump of the knee, not its center of rotation; laboratory comparisons put hip and knee points thirty to fifty millimetres from the joint centers. Second, the confidence is the model's own score. It is not a probability that the point is right. Third, it does best on pictures like the ones it learned from. Upside down in a flip is not one of them.

## 12. Listing 8.2: every frame into a table  (2 min)

You can run the same family of models yourself. This is the heart of Listing 8.2, shortened. The model reads the clip frame by frame. If it finds nobody, the frame is skipped. Otherwise it keeps the most confident person and writes one row: the frame number, an x and a y for each of the seventeen keypoints, and seventeen confidences. A video has become a table. The weights file is named in one place, so you change the model size with one line. Run with the nano model, it finds a person in all one hundred and seventeen frames; the small model in one hundred and fifteen. Which one is right? That count cannot tell you.

## 13. Model size against speed  (1.5 min)

Model families come in sizes. A bigger model has more coefficients, scores better on the benchmark, and is slower. Going from nano to small buys five point eight points of accuracy for about five milliseconds a frame. Going from large to extra large buys one point two points for twenty seven milliseconds. That is why the apps offer all five but start at small. Time adds up: a twelve-second clip at two hundred and forty frames a second takes the small model about forty eight seconds on that laptop. In the browser, the apps default to a different model, MoveNet Thunder, with the same seventeen keypoints, and the video never leaves the device. Each report names its model. Record it, because a new model can change the number.

## 14. High confidence, wrong place  (2 min)

Here is the worst kind of disagreement. Frame thirty of the sketched runner, as the runner drives the front knee up. On the left, the nano model loses both legs: its ankles sit mid-shin. Every one of those points has confidence zero point nine four or more. On the right, the small model follows the legs to the feet. The right knee angle is one hundred and thirty seven degrees from one, one hundred and sixty from the other: twenty two degrees, and nothing in the confidence warns you. Over the whole clip the two models' left knee angles differ by more than ten degrees in sixty five frames. Keep the model the same from session to session, and record it.

## 15. A confidence trace: the quickest health check  (2 min)

Plot one keypoint's confidence against frame number. It is the quickest health check of a clip. These are drawn from the book's tables. On the sketched runner, the left ankle sits near one with short dips where the legs cross; those are the frames where left and right swap. On the back flip, the trace starts empty, because neither model finds a person while the athlete swings the arms and leaves the ground. It wobbles while the body is upside down. And it stops again on landing, when the legs vanish into the dark foreground. The dotted line is zero point three, the threshold most of the apps use.

## 16. What does a confidence of 0.97 tell you?  (1.5 min)

[Thirty seconds, then hands.] The answer is A. Confidence is the model's own score of how sure it is that the point is visible and where it put it. It is useful for throwing out bad frames. B turns it into a probability of being within a pixel, which nobody measured. C turns it into an accuracy for an angle, which is a different quantity altogether. D is the dangerous one: we just saw ankles placed mid-shin at zero point nine nine, and swaps happen at high confidence too. Confidence screens out bad frames; it does not prove a point is right.

## 17. A plausible listing with one flaw  (1.5 min)

This one is from a real request. Asked for code to time a jump from a slow-motion clip, an assistant read the frame rate from the file and divided the frame count by it. The code runs, and on an ordinary phone clip it is right. On every slow-motion clip it is wrong by the ratio of the rates, because that property reads the stored rate. The fix is one line: take the capture rate from the person who filmed the clip. Two habits from this. Ask the assistant which rate its code assumes. And test it on a clip whose answer you know, like the sixty-frame jump from ten minutes ago.

## 18. Scale: from pixels to meters  (2 min)

A pose model works in pixels. Angles and times need nothing else. A length or a speed in metres needs a scale: pixels per metre, in the plane of the movement. Example 8.2: a one-metre stick spans four hundred and twelve pixels. A foot that moves three hundred pixels has moved zero point seven three metres. Misplace each end of the stick by four pixels and every distance is off by about two percent. [Point at the box.] The bigger error is usually depth. A stick half a metre nearer the camera than the athlete looks eleven percent too big, so everything on the athlete comes out ten percent short. Put the reference exactly in the plane of the movement.

## 19. Cleaning keypoints, and what each step costs  (1 min)

Raw keypoints are noisy, and four steps clean them. Each has a cost. A threshold: below zero point three, a point is missing, not zero; but no threshold catches a wrong point the model is sure of. Gaps: a metric that needs a missing point returns nothing rather than an invented value. Swaps: the running app fixes which leg is which over the whole clip. And smoothing, with the window set in seconds so thirty and two hundred and forty frames a second are treated alike. The table shows a frame limit still showing through at thirty. Smoothing rounds off foot strike and release, so the apps draw the raw points.

## 20. Four levels of error between a joint and a number  (2.5 min)

Between a real joint and a number in a report, error enters at four levels, and each is reduced by a different means. Landmark: the dot is in the wrong place. Five pixels sideways on a shank a hundred and fifty pixels long turns it almost two degrees. Projection: a camera flattens three dimensions into two. The plot shows a knee angle as the camera turns away from square: small within ten degrees, then growing fast, and different for each knee position. Only camera placement fixes it. Event: every event can be a frame off. And interpretation: a knee angle on a screen is not the angle between the bones, and a movement is not a force. None of the apps measures pain or injury risk.

## 21. Before Class 16  (1.5 min)

There was no homework today, the class after the midterm. Homework sixteen is due at the start of Thursday's class. Tape a printed protractor to a wall, have your partner hold the elbow at ninety, a hundred and twenty and a hundred and fifty degrees, and film it square, then twenty degrees off square. Read the angle in the canvas app and compare with the protractor. Film only the arm, with written consent. Do the range of motion lab on yourself too. Bring a phone, something to prop it on, a metre stick and a bright band for the waist. And read the rest of Chapter 8: three levels of trust, and how to tell an athlete.
