I would like to calculate the distance of an object from my camera, so i used the formula given in this question and I got a very good answer, but I've found that when I zoom and take the picture and try to re-calculate, the answer always varies.

Is there something I have to change in the equation other than the focal length? object in my image is a table tennis ball which is 40mm size

  • \$\begingroup\$ provided you don't crop/scale the image the only variable you need to change when zooming is the focal length. If you could post the images and your calculations it might be possible to figure out what went wrong. Otherwise, the answer to your question is a simple "no"! \$\endgroup\$
    – Matt Grum
    Oct 25, 2012 at 10:23
  • \$\begingroup\$ @MattGrum sorry due to my reputaion i cannot post any image. from the Exif data i found that the focal length varies each time i zoom. and in the above equation i changed that everytime and expecting a same answer but unfortunatly am getting different values for different amount of zoom \$\endgroup\$ Oct 25, 2012 at 10:27
  • \$\begingroup\$ @MattGrum i have mentioned the equation am using in the question , each time i focus the focal length and the object height varies am including that. \$\endgroup\$ Oct 25, 2012 at 10:28
  • \$\begingroup\$ can you upload the images to imgur.com and post a link? \$\endgroup\$
    – Matt Grum
    Oct 25, 2012 at 10:32
  • \$\begingroup\$ n.b. the exif stated focal length probably isn't very accurate! \$\endgroup\$
    – Matt Grum
    Oct 25, 2012 at 10:34

2 Answers 2


Theoretically the only factor you should need to adjust for in the following equation when zooming is the focal length:

$$\text{Distance to object [mm]} = \frac{f\,[\text{mm}] \times \text{real height [mm]} \times \text{image height [px]}}{\text{object height [px]}\times \text{sensor height [mm]}}$$

There is one factor to be aware of, the distance to object in this equation is actually the distance from the object to the centre of projection of the lens (usually somewhere in the middle of the lens on the optical axis).

However, the centre of projection will usually move when you zoom or focus a lens. The original question was about finding the distance to a windmill, so if the centre of projection moved a few cm it would have a negligible effect on the answer. But if you are attempting to measure very close objects it could skew the result.

What is more likely though is the EXIF reported focal length is only approximate, most lenses only supply about 8 different values for focal length. Not only that but the focal length written on the lens is also inaccurate (it's usually rounded to the nearest 5mm for marketing purposes), and the lens focal length will likely change when focussing also.

In short a camera is a poor tool for measuring distances, especially at close range where a far more accurate solution is possible using a tape measure.

  • \$\begingroup\$ you are right my entire approch is for measurement, and using the formula you have mention i could calculate with a very good accuracy till within 1m without zooming, even tested my result with a laser i could come up with an accuracy of close to that, 5mm difference was there. \$\endgroup\$ Oct 25, 2012 at 11:01

Are you sure you are changing the "height in pixels" value as well? When you zoom, the focal length and the height in pixels change, while everything else stays the same. If the height in pixels stays the same when zooming, then the subject distance is changing.

  • \$\begingroup\$ you mean the "image height " or "object height " ?? \$\endgroup\$ Oct 25, 2012 at 12:09
  • \$\begingroup\$ if you were talking about object height in pixels yes each time it changes and am changing in the equation too. \$\endgroup\$ Oct 25, 2012 at 12:11
  • \$\begingroup\$ You said you're only changing the focal length in your question... object height (pixels is what I'm talking about. \$\endgroup\$
    – BBking
    Oct 25, 2012 at 12:26
  • \$\begingroup\$ when the focal length increase the object height also increase, sorry i forgot to mention that in the question. \$\endgroup\$ Oct 25, 2012 at 12:29
  • \$\begingroup\$ How much of a difference are the the results? \$\endgroup\$
    – BBking
    Oct 25, 2012 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.