Calculate the distance to an object in a photo from its real size, its size in pixels and the focal length, or find its size from a known distance.

You need one real measurement of something in the photo, such as a person’s height or a door’s width.

A height or width you know, measured across the line of sight.

The same height or width, counted in pixels on the original photo. An image editor shows pixel positions.

The full, uncropped photo at its original resolution.

Listed in the photo’s details (EXIF). If you only know the lens’s actual focal length, enter it here and add the crop factor below.

Actual focal length
Leave blank for a 35 mm equivalent focal length or a full-frame camera. With an actual focal length, enter the sensor’s crop factor, such as 1.5.

Calculator Functions

The calculator estimates how far an object was from the camera when a photo was taken, in feet and meters, or the real size of an object at a known distance. Select a function to open it in the calculator.

FunctionUse it whenYou enter
Distance to objectYou know the real height or width of something in the photoThe object’s real size and its size in pixels
Object sizeYou know how far the object was from the cameraThe distance and the object’s size in pixels

Both functions also ask for the photo’s width and height in pixels and the lens focal length as a 35 mm equivalent, which phones and most cameras store in the photo’s details. If you only have the lens’s actual focal length, enter it and add the camera’s crop factor under Actual focal length. Measure the object’s pixel size on the original, uncropped photo, along the same direction as its real size.

Distance From Photo Formulas

D = f × S × d ÷ (p × 43.27) [1]
DDistance from the camera to the object, in the same unit as S
fFocal length as a 35 mm equivalent (mm)
SReal size of the object
dPhoto diagonal in pixels, √(width² + height²)
pSize of the object in the photo (px)
43.27Diagonal of a 35 mm film frame (mm) [2]

A camera projects a scene so that an object’s size on the sensor equals the focal length times its real size divided by its distance [1]. A 35 mm equivalent focal length describes the lens as if the photo filled a 35 mm frame, whose diagonal is 43.27 mm [2]. The photo’s diagonal in pixels therefore covers 43.27 mm, so the object covers p ÷ d × 43.27 mm of that frame. Dividing the focal length times the real size by that figure gives the distance.

Distance to object

The formula above applies directly. For a 6 ft person who is 800 px tall in a 4,032 × 3,024 px photo taken at 26 mm, the diagonal is 5,040 px and the person covers 800 ÷ 5,040 × 43.27 = 6.868 mm of the frame. The distance is 26 × 6 ÷ 6.868 = 22.7 ft.

Object size

S = D × p × 43.27 ÷ (f × d)

This is the same relation solved for the real size. The result also gives the scale of the photo at that distance, as the real length that one pixel covers.

Actual focal length

f = factual × crop factor
crop factor = 43.27 ÷ s [2]

Here s is the diagonal of the camera’s sensor in millimeters. A full-frame camera has a crop factor of 1, so its actual and equivalent focal lengths are the same.

Limits of This Estimate

  • The photo must be uncropped and at its original resolution. Cropping or digital zoom changes how many pixels the frame diagonal covers, and the result is then too short.
  • The object should face the camera. A height or width that is tilted toward or away from the camera looks shorter in the photo, which makes the distance come out too long.
  • The formula treats the lens as an ideal pinhole focused far away [1]. Wide-angle lenses stretch or bend objects near the edges of the frame, and at close range the lens moves away from the sensor to focus, so expect larger errors there.
  • Any error in the pixel count, the real size or the focal length carries straight through: a 5% error in one of them changes the result by about 5%. Stored focal lengths are rounded.

Sources

  1. University of Toronto, CSC420 lecture 7, 3D Vision and Stereo I: pinhole camera projection by similar triangles and its assumptions
  2. Camera and Imaging Products Association, Guideline DCG-001, section 2-c: 35 mm equivalent focal length and the 43.27 mm frame diagonal