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.


Precise answer: Without knowing the projection model, this is not possible.
An ad-hoc engineer's answer: One may assume the projection model is a pinhole camera model. This is probably a good assumption, because it is the model with least strange distortions and with geometrically beneficial properties. For a virtual game camera with horizontal* 90° opening angle this assumption seems to be reasonable.
Now you can translate your question into simple equations based on intercept and trigonometric theorems:
  (I)  w_1 / f = s / d_1
 (II)  w_2 / f = s / d_2
(III)  w_45 / f = tan(45°)

where
  f = focal length (unknown)
  s = object width (unknown)
  d_1 = object distance in image 1 = 1 m
  d_2 = object distance in image 2 (unknown)
  w_1 = object width in image coordinates in image 1 = 348 px
  w_2 = object width in image coordinates in image 2 = 138 px
  w_45 = 1920 px / 2

What remains is to solve this equation system:
(I) => f * s = w_1 * d_1
(II) => f * s = w_2 * d_2
___
=> w_1 * d_1 = w_2 * d_2
=> d_2 = w_1 * d_1 / w_2 = 348 px / (138 px) * 1 m = 2.52... m

So you do not even need equation (III). You would need it in case you are interested in focal length f = 960 px or object width s = 0.3625 m.
*I assume it is the horizontal opening angle from what is common and from what you drew in your question.
