# Q-24: Seventeen keypoints for one frame, as a table

Data-Driven Athletics tutorial · Week 8 · Chapter 8 · about 15 min · workflow steps: Statistics, Visualize

Web page: https://apopt.com/course/tutorials/q24-keypoint-table/ · Data: https://apopt.com/data/tutorials/q24-keypoint-table/

## The decision

A pose model hands you a table of numbers for every frame. Before building a knee angle or a
cadence on it, read one row and decide which of its 17 points you can trust.

## The raw data

- `raw/form3_30fps_yolo26n-pose.csv`: one row per frame of a hand-drawn running animation, 17 keypoints with x, y and confidence from YOLO26n (117 rows) The Chapter 8 example table, also published with the book's data (`book/ch08-pose`). The clip is a drawing, not a person.

A pose model turns each frame of a video into one row of numbers: the frame number, an x and
a y in pixels for each of 17 keypoints, and the model's confidence in each. The file here is
the one Chapter 8 builds from its running example, a hand-drawn runner animated and seen from
the side (`form3_30fps.mp4`, 117 frames), with the smallest YOLO26 pose model. Everything in
this tutorial runs in the page.

*Predict first:* How many columns does one row need for 17 keypoints with x, y and a confidence, plus the frame number?

```python
import pandas as pd

kp = pd.read_csv("raw/form3_30fps_yolo26n-pose.csv")
print(kp.shape, "(rows = frames with a person, columns)")
print("first columns:", kp.columns[:5].tolist())
print("last columns: ", kp.columns[-3:].tolist())
```

Output:

```
(117, 52) (rows = frames with a person, columns)
first columns: ['frame', 'nose_x', 'nose_y', 'l_eye_x', 'l_eye_y']
last columns:  ['r_knee_c', 'l_ankle_c', 'r_ankle_c']
```

117 rows and 52 columns: 1 + 17 × 2 + 17. A row this wide is hard to read. Turn one row into
a short table of its own, one line per keypoint. Frame 30 is the one Chapter 8 (Section 8.4)
draws on the video, because something goes wrong in it.

*Predict first:* In a side view of a runner facing left, which keypoints do you expect the model to be least sure of?

```python
NAMES = ["nose", "l_eye", "r_eye", "l_ear", "r_ear", "l_shoulder", "r_shoulder", "l_elbow", "r_elbow",
         "l_wrist", "r_wrist", "l_hip", "r_hip", "l_knee", "r_knee", "l_ankle", "r_ankle"]
row = kp[kp["frame"] == 30].iloc[0]
one = pd.DataFrame({"x": [row[f"{k}_x"] for k in NAMES], "y": [row[f"{k}_y"] for k in NAMES],
                    "confidence": [row[f"{k}_c"] for k in NAMES]}, index=NAMES)
print(one.round(2).sort_values("confidence").to_string())
print(f"below 0.5: {(one['confidence'] < 0.5).sum()} of 17")
```

Output:

```
                 x        y  confidence
r_ear       463.34   584.76        0.01
r_eye       446.96   579.65        0.30
r_wrist     393.16   635.68        0.42
r_elbow     380.95   678.24        0.66
r_ankle     611.46  1258.12        0.91
l_ankle     515.10  1242.29        0.94
nose        450.78   593.65        0.96
r_shoulder  428.41   657.09        0.98
r_knee      460.09  1108.42        0.98
l_shoulder  571.56   661.54        0.99
l_wrist     750.55   854.32        0.99
l_eye       465.65   581.34        0.99
l_elbow     717.36   716.30        1.00
l_hip       519.57   950.71        1.00
r_hip       453.70   957.56        1.00
l_knee      375.88  1070.72        1.00
l_ear       518.96   587.23        1.00
below 0.5: 3 of 17
```

The least sure points are all on the runner's right side, the side away from the camera:
the right ear, eye and wrist. Those are hidden behind the head and body, and the model says
so. The hips, knees and ankles score 0.91 or more.

### Draw the row

Join the points into a stick figure. Image y grows downward, so the axis is turned over.
Bones with an end below 0.5 are drawn faint and dashed.

```python
import matplotlib.pyplot as plt

BONES = [("l_shoulder", "r_shoulder"), ("l_shoulder", "l_elbow"), ("l_elbow", "l_wrist"),
         ("r_shoulder", "r_elbow"), ("r_elbow", "r_wrist"), ("l_shoulder", "l_hip"), ("r_shoulder", "r_hip"),
         ("l_hip", "r_hip"), ("l_hip", "l_knee"), ("l_knee", "l_ankle"), ("r_hip", "r_knee"), ("r_knee", "r_ankle")]
fig, ax = plt.subplots(figsize=(4.4, 5))
for a, b in BONES:
    low = min(one.loc[a, "confidence"], one.loc[b, "confidence"]) < 0.5
    ax.plot(one.loc[[a, b], "x"], one.loc[[a, b], "y"], color="gray" if low else "black",
            ls="--" if (low or a.startswith("r_")) else "-", lw=1 if low else 2.5)
ax.scatter(one["x"], one["y"], c="black", s=12, zorder=3)
for k in ["nose", "l_knee", "r_knee", "l_ankle", "r_ankle", "r_wrist"]:
    ax.annotate(f"{k} {one['confidence'].round(2)[k]:.2f}", (one.loc[k, "x"], one.loc[k, "y"]), fontsize=7,
                xytext=(5, 0), textcoords="offset points")
ax.invert_yaxis(); ax.set_aspect("equal")
ax.set(xlabel="x (pixels)", ylabel="y (pixels, grows downward)", title="frame 30, YOLO26n")
plt.tight_layout()
```

![Stick figure of frame 30 drawn from the 17 keypoints, left side solid and right side dashed, with the low-confidence right arm faint; each point is labelled with its confidence.](https://apopt.com/course/tutorials/q24-keypoint-table/c05-1.png)

The table says the legs are certain. The drawing on the video says otherwise: in this frame
the nano model put both ankles mid-shin and the right knee in the thigh (Chapter 8, Section
8.4), while the next size up (s) followed the legs to the feet. Nothing in the confidence
column warns you. A confidence is the model's own score, not a check that the point is right;
the only checks are looking at the skeleton on the video and comparing two models, which
CS-10 does.

**For the athlete:** before trusting a knee angle from a clip, look at the skeleton drawn on
the frame it came from.

## With your own data

Build the same table from your own clip with the local cells of CS-10, then run this page's
cells on it, choosing a frame where your foot is on the ground.

## The same method in another field

A wide table with one row per time step and repeated groups of columns is the shape of most
sensor logs: several thermocouples, each with a value and a status flag. Turning one row
into a short table is the first look at any of them.

## Acknowledgements

The keypoint table is from Chapter 8 of *Data-Driven Athletics*, made with Ultralytics YOLO26
(AGPL-3.0).

## Action card

- **Finding:** In frame 30 the model is sure of the legs (0.91 or more) and unsure of the far-side ear, eye and wrist.
- **Evidence:** Three of 17 points are below 0.5, all on the side away from the camera.
- **Sure:** The confidence column alone cannot tell you the legs are placed wrongly in this frame; the video can.
- **Action:** Check the skeleton on the video at the frames you will measure.
- **Retest:** Compare with a second model size (CS-10) whenever a number matters.

## References

- Ultralytics YOLO documentation: [pose estimation](https://docs.ultralytics.com/tasks/pose/).

---
Text CC BY 4.0, code MIT. IRSRI Sports Research Institute.
