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.
- All Physics Calculators
- Angle of View Calculator
- Image Distance Calculator
- GSD (Ground Sample Distance) Calculator
- Pixel Size Calculator
- Hyperfocal Distance Calculator
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.
| Function | Use it when | You enter |
|---|---|---|
| Distance to object | You know the real height or width of something in the photo | The object’s real size and its size in pixels |
| Object size | You know how far the object was from the camera | The 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 | Distance from the camera to the object, in the same unit as S |
| f | Focal length as a 35 mm equivalent (mm) |
| S | Real size of the object |
| d | Photo diagonal in pixels, √(width² + height²) |
| p | Size of the object in the photo (px) |
| 43.27 | Diagonal 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
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
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
- University of Toronto, CSC420 lecture 7, 3D Vision and Stereo I: pinhole camera projection by similar triangles and its assumptions
- Camera and Imaging Products Association, Guideline DCG-001, section 2-c: 35 mm equivalent focal length and the 43.27 mm frame diagonal
