How to calculate the distance of an object I have two screenshots (1920x1080) of a game, one with a 348-pixel-tall object that is 1 meter distant from the camera, and the other with a 138-pixel-tall version of the same thing. Given that the camera's field of vision is 90 degrees in the second screenshot, how can I precisely measure the object's distance from the camera?
I tried using a formula to determine the object's distance from the camera based on the object's height and camera distance, but the results were inaccurate.


This might be of interest. I don't think this approach is entirely accurate due to perspective distortions, but in this case, I think a fair estimate of Distance D from the camera can be obtained by assuming constant pixels-per-unit-angle near the centre of the picture. Assume the object are poles of height h and the camera is pointing at their centre. Suppose the angle from the centre of the camera view to the top of the pole at 1m is Theta_1 and for the other object it is Theta_2. Then
tan Theta_1 = h/2

tan Theta_2 = h/2D

(tan Theta_1) / (tan Theta_2) = D

Taking a first order approximation,
D approx1.= Theta_1 / Theta_2

If we also assume 348 Theta_2 = 138 Theta_1, then we get the answer posted. For a 2nd order approximation, which hopefully should be more accurate, particularly for more distended cases,...
D = (sin Theta_1)(cos Theta_2) / ((sin Theta_2)(cos Theta_1))

approx2.= Theta_1(1 - Theta_2^2/2) / (Theta_2(1 - Theta_1^2/2)) 

approx2.= (Theta_1/Theta_2)(1 - Theta_2^2/2)(1 + Theta_1^2/2)

approx2.= (Theta_1/Theta_2)(1 - Theta_2^2/2 + Theta_1^2/2)

So if 348 Theta_2 = 138 Theta_1
D approx2.= (348/138)(1 + Theta_1^2(1/2 - (138/348)^2/2))

If 1920 pixels is pi/2 radians, then estimate
Theta_1 approx.= 348*pi/(2*2*1920) = 0.142353417

giving
D approx2.= (348/138)(1.008538919)

which suggests a less than 1 percent difference from the 1st order approximation in this case.
