The mathML formulae

The width of the field the camera captures is relative to how far away any object is, more precisely:

tan(fov/2) = viewwidthcm/2 distancecm

which gives us:

distancecm = ( viewwidthcm/2 ) tan(fov/2)

So what's the view width at the point where the face is? We know that the proportion of the screen the face will fill is given by:

proportion = facewidthcm viewwidthcm

However, this is the same for pixels, so:

proportion = facewidthpx viewwidthpx = facewidthcm viewwidthcm

And this gives us:

viewwidthcm = ( facewidthcm * viewwidthpx ) facewidthpx

Inserting this, we get:

distancecm = (facewidthcm*viewwidthpx) (facewidthpx* 2 * tan(fov/2))

In our case viewwidthpx is the width of the canvas, facewidthpx is the width of the face on the canvas, and we assume facewidthcm is around 17 cm.