5

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

user1767798
  • 151
  • 1
  • 5
  • 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
  • (This question is really a comment on the answer there, isn't it? In any case I've voted this up; one more upvote and you will be able to post images.) – mattdm Oct 25 '12 at 10:35
  • @mattdm No this thing i need for my current project and i found that equation and i was quite happy until i found the problem with the zooming. Did lot of searches but no result thats why i asked here. – user1767798 Oct 25 '12 at 10:37
  • true the Exif data i got it from windows photoviewer and other exif applications vary . – user1767798 Oct 25 '12 at 10:39
  • @MattGrum one more detail am using a table tennis ball as the objrct , because it comes with an accurate size of 40mm – user1767798 Oct 25 '12 at 10:43

2 Answers2

4

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.

scottbb
  • 32,685
  • 12
  • 104
  • 188
Matt Grum
  • 118,892
  • 5
  • 274
  • 436
  • 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
3

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.

BBking
  • 2,765
  • 1
  • 16
  • 27