Calculate Distance to a Object in an Image

This is rather specialized, but people do ask how to determine the distance to an object or subject in an image. The DSLR Exif data may tell you Focus Distance, except you should realize that the focus distance reported is often seriously incorrect, especially for zoom lenses. You surely want to verify what actual focus distance is required for this lens to report that distance at that zoomed value.

Otherwise, the calculator here will do this, but you must know a few things about the situation:

If using a simple compact camera, smart phone camera, or camcorder, you may not know all of the numbers. Especially not the precise size of the sensor in mm, especially not if in movie video mode. And this part may be rather confusing for novices without a basic understanding of digital images.

Calculate Distance of an Object in an Image

First select the dimension to be used here:

Height   Width

  Enter One of these two sensor size options:
Sensor size
Height dimension
Or Crop factor and
Aspect Ratio Width:Height
Lens Focal Length mm
Height size of sensor pixels
Height of Object in image pixels
Height of real Object feet or meters
Distance = Same units

Numbers only.  A NaN result will mean an input is Not A Number. Decimal points are OK.

You can use object size in feet or meters, cubits or whatever... The Distance result will be in the same units.

Example: In this image, the tape on the floor measures 30 feet.

Nikon D800 camera: Sensor 35.9 x 24 mm. 7360x4912 pixels. 60 mm f/2.8 D lens.

The Exif says this Focus distance was 3.76 meters, which is 12.33 feet (when it was actually measured to be 30 feet). And this was a 60 mm lens, not even a zoom lens, so the cameras distance report is a real crap shoot (often worse than useless).

The door measures 80 inches tall, 6.667 feet (or the height or the width might be reasonably estimated, for a distance estimation). The cropped door is 2724 pixels tall (crop it, then look at image size).
So the calculator input specified 24 mm sensor height, 2724 pixel object height, 4912 pixel sensor height, 60 mm lens, and 6.667 feet estimated real object height.

The tape on the floor measures 30 feet, and the calculator computes 30.06 feet (0.2%). That 0.06 foot is 0.7 inches. This distance is computed to the Thin Lens node somewhere in the lens, not really known (but this calculated value here is Not to the focal plane at rear of camera). I guessed the node was at the middle of lens, so that could be an inch error. Still, the accuracy seems very adequate.

The small resampled image copy which is shown here is 450x300 pixels, and it can work too (only because the image is still full frame view, NOT cropped at all).
Then (in this resampled smaller image) the cropped door is 168 pixels tall, sensor height is 300 pixels tall (but still 24 mm in camera), and calculator says 29.76 feet (0.8%). Less precision in a smaller image or object due to less possible cropping accuracy. Still, even this is very near 30 feet.

Note this 168/300 pixels or 2724/4912 pixels is simply computing the size is 56% of the 24 mm height of the camera sensor. Then knowing this height in the camera, and also the real life height, and the focal length distance in camera, it calculates distance to the subject.

Then it is similar triangles, just equal opposite angles, which have equal tangents, which are similar height/distance ratios.
  Object height on image sensor (mm)/ focal length = Real Object height / Distance to Object.

The size of the Object image in mm is:
  sensor height in mm x Object height in pixels / sensor height in pixels.

The calculator will do all of this, but it needs your accurate numbers.

The math the calculator uses is from this diagram:


If we measure that the object size (height or width) is say 10% of the image pixels, then we know it is also 10% of the sensor mm dimension. Then if we know the size of the sensor in mm, and if we know focal length in mm, then trigonometry can compute the distance to the object (Field of view is computed the same way). If we know the actual real life size dimension of the subject, then we can scale the distance accurately too.

Again, three points.

Menu of the other Photo and Flash pages here

Copyright © 2015-2017 by Wayne Fulton - All rights are reserved.

Previous Menu