Project Slackpose gives me one more excuse for hyperlocal exercise and number crunching in lockdown. Last time, I briefly touched on balance analysis. This time, I look at tracking slackline distance walked with my newly minted *slackometer*.

## Inferring 3D Position

I’m working only with 2D pose data (a set of pixel locations for body joints) from my single camera angle, but I can infer something about my 3D location – distance from the camera (**d**) – using the pinhole camera model and further data such as:

- Camera lens & sensor geometry, plus known real world distance between pose keypoints (geometric approach)
- Consistent pose data (eg same person, similar pose) acquired at known distances from the camera (regression approach)

In this first iteration shown in the notebook, I boil all the pose data down into a single feature: the vertical pixel distance (**v**) between the highest tracked point (eg, an eye) and the lowest tracked point (eg, a toe). I base the calculation of distance **d** on this measure. This measure may be shorter than my full height by crown-to-eye height and a typically lower pose when balancing on a slackline, or an elevated arm joint might make it taller.

### Geometric Approach

The geometric approach uses a similar triangles formula where one triangle has sides lens-sensor distance (known) and object pixel height (**v**) scaled to sensor height (known), the other has lens-object distance (**d**) and object height (roughly known from my height, as above). The equation has the form **d = F / v**, where **F** is determined by those known or estimated factors. These geometry factors will be specific to each physical camera device and slackline walker combination.

### Regression Approach

The regression approach uses pose data collected at known distances from the slackline anchor – 2m, 4m, 6m, and 8m – as shown in the image below. I marked the calibration distances and walked to each point, balancing there for a few seconds, then turned around and walked back through each point to collect data from both back and front views. This approach is consistent across cameras and walkers, and works with varied sets of calibration distances.

Plotting the value of **v** against the reciprocal of distance (**1 / d**), we see a fairly linear relationship. Fitting a line (with 0 intercept) to the data gives a value for **1 / F**, which produces a value for **F** that is very close to that from the geometric approach – a neat result, or convenient choice of parameters!

So we have two methods for calculating distance from pose data, which produce very similar results.

## Does It Work?

The figures you see in the video above match up pretty well with the reality. The video shows approximately 10m accumulated distance, while in reality I started about 2m from the camera, walked to just under 8m from the camera, then returned almost to my starting point (say 11.5m max). The discrepancy is most likely explained by an under-estimate of peak distance (at ~7m) due to decrease in precision of pixel measures for distant objects, and noise/pose-dependence in the vertical extent measure.

So this first iteration of the *slackometer* would be useful for approximating distance walked, and could possibly be improved with higher resolution video and by tracking more body segments, which may also reduce the dependence on smoothing. It would also be useful for comparing distances or speeds. The millimetre precision, however, is misleading, I just chose the unit so it looked better on the odometer display! (I spent some time tuning this for those cascading transitions…)

There are certainly are other ways you could track distance, starting from pacing out the line and keeping count of laps, to using image segmentation rather than pose estimation to calculate **v**, to alternative sensor setups and models, but it was fun to do it this way and helped pass a few more days, and nights, in lockdown.