# Why does calculated distance of an object in an image vary when zooming?

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

-
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"! – Matt Grum Oct 25 '12 at 10:23
@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 – user1767798 Oct 25 '12 at 10:27
@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. – user1767798 Oct 25 '12 at 10:28
can you upload the images to imgur.com and post a link? – Matt Grum Oct 25 '12 at 10:32
n.b. the exif stated focal length probably isn't very accurate! – Matt Grum Oct 25 '12 at 10:34

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

``````distance to object (mm) = focal length (mm) * real height of the object (mm) * image height (pixels)
---------------------------------------------------------------------------
object height (pixels) * 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.

-
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. – user1767798 Oct 25 '12 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.

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