# Calculate the distance of an object in a picture? [duplicate]

I'd like to know the distance between the camera and the object, just by looking at the object height (pixels) or it's width and the real life dimensions. Here is a formula we can get on the internet: But there is something very wrong with it. The "Sensor height" parameter is wrong and cannot be inversely proportional to distance. It is giving obvious absurd answers.

Let's take a very simple example. If a person is roughly 100 meters away from the camera, with a camera with a "sensor height" of 100 mm from the ground, its size on the image will be of 50 pixels height. If I am 200 mm from the ground I should not get a result of twice less distance... like 50 meters away from the camera... try it, it's wrong !

• I think "sensor height" here is referring to the vertical size of the sensor, not its distance from the ground... – twalberg Nov 12 '18 at 19:17
• The sensor height is the physical dimension of the sensor itself, 24mm for FF sensor – Romeo Ninov Nov 12 '18 at 19:19
• How does this knowledge help you take a better picture? – OnBreak. Nov 12 '18 at 19:23

If a person is roughly 100 meters away from the camera, with a camera with a "sensor height" of 100 mm from the ground, its size on the image will be of 50 pixels height.

As noted in the comments, `sensor height` is not the height from the ground, but the height of the size of the sensor.

• The formula is definitely valid for lenses of simple structure that emulate a plain single lens (50mm prime, for instance) but it it also valid for the more complicated lenses (any zoom, wide angle...)? – xenoid Nov 12 '18 at 21:55
• Well, how is a 50mm prime emulating a single lens if even the cheap ones have like 6 to 7 lens elements? The question boils down to how different a certain lens system is from the optical model of a single lens. Principal planes can be used to describe a lens system in terms of an equivalent focal length. There are also other factors that contribute to the error of the result, e.g. that the focal length written on a lens barrel is usually a rounded number. – null Nov 12 '18 at 22:29
• Using a shot of the moon: 1200px diameter on my EOS 70D, 560mm (from Exif, actually 400mm+1.4 extender), I get 394.000km (should have been 376.000, so this is roughly a 5% error). – xenoid Nov 12 '18 at 22:39
• @xenoid The Moon's distance from the Earth varies from 363,104 km at perigee to 405,696 km at apogee. Your measurement of 394,000 km is well within that range. You also should probably account for the exact focal length of your "400mm" lens. – Michael C Nov 13 '18 at 4:47
• 1) I used actual distance data for that specific date&time&place, and the focal length as reported in the EXIF , and 2) this shows the practical accuracy limit (how can one tell the exact focal length without recalibrating the lens (long process for a zoom, even assuming the focal length doesn't change with the focus distance). – xenoid Nov 13 '18 at 7:45

This is an edit --- I got the math wrong the first time – forgive an 80 ¼ year old for having senior moments. Gentle readers, please feel free to re-check and edit. By the way, this ratio method works!

Suppose the camera you own is categorized as a compact digital. You look up its specifications and find the image sensor measures 16mm height by 24mm length. Further, it is a 16-megapixel sensor. You can calculate the ratio of height to length 24 ÷ 16 = 1.5. Now you can calculate the horizontal and vertical pixel count and find it to be 1,033 vertical and 1,549 horizontal (algebra solves). Further, you calculate the pixel size, and find them to be a square with sides that measure 0.0155mm.

Now you photograph an object and examine the image height; it spans 750 pixels. Thus the image height is 750 X 0.0155 = 11.6mm

When you took the picture you were using a 200mm focal length lens. Now a lens projects an image of the outside world onto the surface of the image sensor. If you know the focal length of the lens, you can use this value as the distance, lens to sensor.

We can draw an imaginary trace of the image forming rays. We trace from the top and from the bottom of the image to the center of the lens. We thus draw a triangle. The height of this triangle is the focal length = 200mm. The base of this triangle is 11.6mm. This is the image triangle.

Now an object triangle can also be traced. The base of this triangle is the actual height of the object. The height of this triangle is the actual distance, object to lens. The angles of the image triangle and the object triangle are identical.

You know the height of the image triangle is 200mm (focal length). The image spans 11.825mm -- thus the ratio is 200 ÷ 11.6 = 17.2 Now if the object being imaged is 100 meters away from the camera. You can calculate the height of this object thus -- 100 ÷ 17.2 = 5.8 meters.

• Your math is off by several orders of magnitude. A 103,280 x 154,920 pixel sensor would be 16,000 megapixels, not 16MP! A 3:2 16MP sensor is roughly 1,033 x 1,549 pixels – Michael C Nov 13 '18 at 5:39
• @ Michael Clark -- It would be a kindness if you edited (corrected) my post - I can't get back to it for a day or two. Thanks in advance - Allan – Alan Marcus Nov 13 '18 at 6:35