How to calculate distance to object?

Messages
24
Reaction score
0
Location
Krakow, PL
Hi,

I wonder if it is possible (or rather I know it's possible, but how?) to calculate the real distance from the camera to the photographed object. Let's assume I got the following information:
  • the focus is measured exactly to the object
  • I know the real focal length - from the EXIF
  • I know the camera (Fuji S602), so I know the real CCD size
  • I know the real object size (e.g. its human)
How to calculate the real distance from me to the object?

The second question - does the same method provides good results for photos taken in macro and supermacro modes? I mean, does EXIF contain the real focal length i.e. takes the mode in account?

BTW: what is the real size of CCD in S602? I mean the size that can be used for the above calculation?

Rgrds, Grzes
 
Grzegorz,

As you note later in your post, you are missing some ingredients, but let me give you some of the math needed to derive the calculation you are interested in.

Assuming that we are "in focus":

1/m + 1/b = 1/F

where m is the distance from the lens (the rear principal point of the lens, to be rigorous), b is the distance from the lens to the subject (from the front principal point, to be rigorous), and f is the focal length of the lens.

(This is the fundamental lens equation. Note that if b is much greater than m, it turns out that m approximately equals F; that is, for objects relatively

far from the camera, the distance from the rear principal point of the lens to teh sensor is essentially the same as the focal length. If we know that's the case, we can just use a simplified relationship, "m=F", but since you mentioned macro work, it's best to keep all the ingredients.)

Now:

H/m = T/b

where H is the height of the object on the sensor and T is its height in real life ("in the scene"). All must of course be in consistent units (meters, for example).

(This is because the angular size of a feature on the image, seen from the rear principal point, is the same as the angular size of the feature in the scene, see from the front principal point. H/m is twice the tangent of half the former angle, and T/b is twice the tangent of half the latter angle, so those ratios must be the same since the angles must be the same.)

Since we know F, H, and T, we have two equations in two unknowns (m and b), which can be solved by normal simultaneous equation algebra.

Doing so gives us the formula:

b = F(T/H + 1)

(b is of course the distance to the object, which I believe is what is sought here.)

As you mentioned, you need to know the size of the sensor's active area to be able to determine H from the object's size in the image. And I don't know that size.

I don't know if the reporting of focal length in the exif is valid for macro and supermacro modes.

Best regards,

Doug Kerr
 
Hi Doug,

sorry for late response - I was cut off from the Internet for some time - thank you for you answer!
Assuming that we are "in focus":

1/m + 1/b = 1/F

where m is the distance from the lens (the rear principal point of
the lens, to be rigorous), b is the distance from the lens to the
subject (from the front principal point, to be rigorous), and f is
the focal length of the lens.
m is the distance from the lens to... ? To the sensor, right?
Doing so gives us the formula:

b = F(T/H + 1)

(b is of course the distance to the object, which I believe is what
is sought here.)
That's exactly what I wanted to know :-)
As you mentioned, you need to know the size of the sensor's active
area to be able to determine H from the object's size in the image.
And I don't know that size.
According to the tech. specification the sensor size is 1/1.7" - but the questions are:
  • is it width or height?
  • is it physical of effective size?
Anyone does know the answer?
I don't know if the reporting of focal length in the exif is valid
for macro and supermacro modes.
I'm not sure too - probably not.

Once again - thank you for explanations!

Grzes
 
Hi, Grzegorz,

Glad you're back "on the air".

Regarding the sensor size as "1/1.7 inch", that is not height nor width nor anything else. It comes from a silly old system of defining sensor sizes in Vidicon tubes (for TV cameras) based on the diameter of the tube itself (the glass part!). I suspect it is usedtoday just so they don't really have to tell you the size but it seems that they have! It's even worse than our system of "1/2 inch pipe" in plumbing! Some place I have the size of the sensor in the "2/3 inch" Vidicon, but not handy. Of course neither of the dimensions, nor the diagonal, are 2/3 inch - it wouldn't fit in the bottle.

We can, however, estimate the size of the S602 sensor based on the generally-accepted equivalence of focal length to the corresponding focal length of a lens on a 35 MM camera. What we are really talking about is the same "angular field of view". Based on the geometric concept of "similar triangles", the ratio of actual to equivalent focal length is just the ratio of our sensor size to the fim frame size in a 35 mm camera.

The equivalence usually stated for the S602 is that the "35 mm equivalent" focal length is 4.49 times the actual S602 lens focal length.

This would imply that the dimensions of the S602 sensor (I assume it would be for the actual "image" portion) would be 1/4.49 (0.223) times the dimensions of the 35 mm film frame. Those are 36 mm (W) x 24 mm (H). That would suggest that the dimensions of the S602 sensor would be 8.02 mm (W) x 5.35 mm (H).

But there is a little clinker here - the 35 mm film frame has an aspect ratio (W to H) of 3:2, while the S602 image has an aspect ratio of 4:3. So 8.02 mm x 5.35 mm can't really be the answer for the S602. Maybe it is 8.02 x 6.01, or maybe it is 7.13 x 5.35, or maybe it is something else (depending on what the guy who determined the focal length equivalence was thinking, if anything).

(Thus, for a digital camera with anything other than a 3:2 aspect ratio, the focal length equivalence can't be "exact".)

In any event, you can probably make an arbitrary choice that, for your purposes, will be quite suitable.

Hopoe this is of some help. Good luck on your project.

Doug Kerr
 
Hi, Grzegorz,

I neglected this in my previous reply.

Yes, "m" is the distance from the (rear principal point of the) lens to the sensor. (Editorial lapse on my part!)

Those symbols are of course arbitrary - there aren't standard symbols for these quantities, that I know of.

Doug Kerr
 
Hi, Grzegorz,

Based on some bery quick reasearch and a lot of reading between the lines, it appears thatdigital TV camera sensors referred to "2/3 inch" (following the old Vidicon convention) have an array size of about 8.8 mm x 6.6 mm. But that may be only one manufacturer's take on it - it hardly seems as if there would be a standard for such a bizarre cheme of notation!

Still, if "1/1.7" is to be interpreted the same way, the corresponding sensor size for the S602 would be 7.65 mm x 5.74 mm.

Doug Kerr
 
Hi, Grzegorz,

Here's a link to a handy explanaion of the "Vidicon" sensor size convention. Turns out I was right on the numbers before.

http://ftp.agilent.com/pub/semiconductor/morpheus/docs/choosingthebestlens.pdf

Other intersting stuff in there, too. I don't have timne to read it. I'm supposed to be making an electroinc score of a new hymn our church choir will sing tomorrow so I can learn my tenor part!

Doug Kerr
 
Hi Doug,

once again thanks for research and for such comprehensive explanation :-). I see the problem is not trivial as the real "sensor" size is still unsure (although your last post indicates the most probable value. But we shall not surrender :) and you inspired me to make additional research - now, as I got a mathematical I can make some tests by photographing different objects of different size and distance and in different modes (normal, macro, supermacro) and I'll post the results.

Grzes
 
Hi,

as I promised I made some experiments and calculations but the results are not like I expected :-(

I took 15 photos of the subjects which size I know. I wanted this experiment to be as data rich as possible, to the photos were taken from different distance to the subject, using three different zoom (default, max wide and max tele) and using all possible modes - normal, macro and supermacro.

Then for each photo I read focal length from the EXIF and measured the subject size in pixels (GIMP is great!). Having the distance, real subject size and focal lenght I could calculate the size of subject's image on sensor using the following formula:

H = (T*F) / (b-F)

(the meaning of variables is the same as in your post).

I could also calculate the percentage size of subject comparing to the whole image size as I know the size of subject in pixels and the size of JPG produced by the camera.

Having the two above numbers I can calculate the width of sensor, can I? And if my measurements were correct, the calsulated value should be the same for all photos, right?

I put all data and calculations to the Excel file:

http://www.twins.pk.edu.pl/~grzes/sensor_size_calculations.xls

Take a look on it. The last tabel shows the calculated sensor width. Unfortunalety it varies from 7,49 to 8,38mm for distance photos (almost 2,7m), 7,85 to 8,48mm for average close photos (75cm), not talking about very close photos (20cm).

I wonder what factors caused such big differences? Maybe I should make tests on subjects much more far from the camera - but then there is a problem with exact distance calculation. I calculated distance from the subject to the fron lens, maybe my method was wrong and in different zooms the difference between my assumption and the real distance was significant? I was using a tripod even if the distance calculation for a series of shots was wrong, it was the same for the whole series.

Grzes
 
Hi, Grzegorz,

Based on some bery quick reasearch and a lot of reading between the
lines, it appears thatdigital TV camera sensors referred to "2/3
inch" (following the old Vidicon convention) have an array size of
about 8.8 mm x 6.6 mm. But that may be only one manufacturer's take
on it - it hardly seems as if there would be a standard for such a
bizarre cheme of notation!

Still, if "1/1.7" is to be interpreted the same way, the
corresponding sensor size for the S602 would be 7.65 mm x 5.74 mm.

Doug Kerr
These numbers are very close to the sensor size gven in an earlier post last year given as 5.85 x 7.8 mm. But this does not effect your problem as one has to count how many pixels high the image is, which Grzegorz has done in his tests . We all have no clue as to how much area is taken up for housekeeping and decoding circuitry.
http://forums.dpreview.com/forums/read.asp?forum=1012&message=3479429
Magoo
 
Magoo,

In "2/3 inch" video cameras (whcih are probably quite different than still cameras regarding "active pixels", "retired pixels", "pixels-in-law", and so forth) the 8.8 x 6.6 sensor is all active pixels (the pixel count and pixel spacing that are stated add up (or rather multiply up) precisely.

But for the S602 we couldn't expect a notation like "1/1.7 inch" to lead to a precise result no matter what minor stuff was or was not included.

However, if the reported focal lengths are accurate, then a determination of "magnification" should be valid and should lead to a farily accurate determination of the physical dimensions of the part of the sensor devoted to image pixels.

Grzegorz: I just got in from a concert. I'll look at your results as soon as I can. I'm sure they will shed some light on what I mention above. Thanks for the report.

Doug Kerr
 
Grzes,

I haven't yet had a chance to look at your spreadsheet (and once I do this concern will liklely be answered). Did you meaure the distance to the subject? You would have to in order to calculate the size of the sensor from knowledge of object height, image height as a fraction of image height, and focal length.

I would just assume you had measured the distance to the subject, but it worried me when you said "I calculated distance from the subject to the front lens". Maybe you meant to say "I measured the distance . . ."

I'm also a little confused when you speak of pictures at a distance of "almost 2.7 m" as "distance" , 75 cm as "average close" and 20 cm as "very close". Maybe there was a typo in the "2.7 m".

Keep in mind that we have no idea how accurate the exif indication of focal length is. I wouldn't bet on it being very accurate.

It certainly sounds as if your logic is correct, and your algebra certainly is.

Later. Gotta reprint 40 church bulletins for tomorrow morning I accidentally printed with "Draft A" still on them!

Doug Kerr
 
Grzes,

Never mind about the part of my last post about the "2.7 m" etc. It all makes sense. I don't know what I was thinking about. I'm trying to do too many things at once here!

Doug Kerr
 
Grzes,

I had a look at your spreadsheet. It is very well organized and easy to collow. The equations are all very tidy. Nice work.

I have three thoughts at this point, all "long shots":

1. The discrepancy in calculated sensor size is less between tests at different distances with the same indicated focal length. This could be consistent with teh various focal lengths not being precisely indicated.

2. Your distance measurements were froim the front of the lens. The distance that really counts is to the front principal point (which we don't know, but it is back inside the lens). The discrpancies between the findings for the same focal length but different subject distances are in the direction that could result from this problem. If I assume that the front principal point is 4 cm back from the front of the lens (probably an unreasonable distance), then the discrepancies become very small (for the full wideangle case). (It doesn't work quite that way for the "default" focal length, wltjhough the change is in the right direction.)

3. It might be that barrel distortion could enter into the matter. When there is barrel distortion, the "magnification" differs with distance from the image center - that is, the relationship between the distance of an object point from the object center, and the distance of that point on the image from the image center, is non-linear. This could influence the determinations you are working with

Looking at it in a simplistic way, the ratio of object size to image size would depend on the actual image size. (The S602 exhibits substantial barrel distortion at the shorter focal lengths.)

Well, its time for you to get up and me to go to sleep.

Later.

Doug Kerr
 
Hi Doug,
I had a look at your spreadsheet. It is very well organized and
easy to collow. The equations are all very tidy. Nice work.
Thanks :)
1. The discrepancy in calculated sensor size is less between tests
at different distances with the same indicated focal length. This
could be consistent with teh various focal lengths not being
precisely indicated.
That's possible - but on the other hand although the focal length measurement "in the middle" can really be not accurate, I think it is safe to assume that the value at most wide and most tele ranges should be exact.
2. Your distance measurements were froim the front of the lens. The
distance that really counts is to the front principal point (which
we don't know, but it is back inside the lens). The discrpancies
Yes - that sounds reasonable.

The next problem can be that the camera was not ideally horizontal and not ideally perpendicular to photographed surface. But in such case there could be significant differences between shots from different distances (where camera was moved), but not for the same distance but different focal length, right?
Looking at it in a simplistic way, the ratio of object size to
image size would depend on the actual image size. (The S602
exhibits substantial barrel distortion at the shorter focal
lengths.)
Yes - that can be the reason of such differences for different focal lenghts.

So... It seems that the task was not so easy. I wonder if it makes sense to measure distance to an object at all:
  • a focal length got from EXIF can be different from the real one;
  • barrel distorsion, especially for wider angle can falsify a measurement
of objects size on photo;
  • it is very common that an object seems to be perpendicular
to the axis of lenses, while in fact it's not, so a size of photographed
image is shorted then it's expected...

Grzes
 

Keyboard shortcuts

Back
Top