Sunday, April 1, 2012

Calculating focal length from photograph

Question

I posted this question over on Stack Overflow, but someone suggested this site might be of more help to me.

I'm doing a college project where I'm trying to calculate the focal length of a camera from a photo. The project is part of my final year computing course (that's why I assumed Stack Overflow would be the best place to ask)

I'm using vanishing lines identified by the user to try and calculate the focal length. say you have a cube, the user can select 3 sides to intersect. For each side, 2 lines are drawn to infinity. Where 2 lines intersect = intersection point. This is done for all 3 sides giving 3 intersection points. These points are then used to draw a new triangle and from this triangle to focal length can be calculated as shown in this Research research. But my values are way off. For this image the focal length is known as 18mm but the value I get is 478.634....

enter image description here

Would anyone have any experience with this type of problem?

I have also come across this formula on this website. Does anyone know what

alphaX (fx = (imageWidth)2*tan(alphaX))

would represent.

Any help would be appreciated

UPDATE:.

Ive made a few pics to show how I calculate the focal length (images not to scale or size). Starting with a photo of a cube Cube I extend each one of the 3 sides till they intersect (shown by the green dots). Then using those intersection points I construct a rectangle as shown here Intersecting points. Then I calculate the ortho-centre of the triangle. Then using the formula here I calculate the focal length as shown here enter image description here. In my application the focal length is simply a value (integer) that is calculated from the square root of the length of the intersecting points (IP1) to the centre, multiplied by the length from the centre to the opposite midpoint (MP2)

Asked by Hans Moolman

Answer

(1) By inspection it is "clear" [tm] that a relatively wide angle lens is in use. In a 35mm full frame system a guesstimate far far far closer to 18mm than 480 mm would be arrived at.

(2) Without having got my brain fully around the triple vanishing point method described in a reference, I would think that for vanishing points to be relevant you would need to deal with lines which were parallel in reality but rendered apparently not so by perspective OR perhaps wit lines whose actual interposing angle was known and which were rendered at another apparent angle in the image. However, in the example photo given, the actual angle between the two walls on either side of the island seems to be arbitrary and unknown (except to their builders) and that changing this angle changes the answer you would get. HOWEVER, I may just be wholly missing the point :-).

(3) I am reasonably certain that the formula quoted by the original poster in your reference as

  • fx = (imageWidth)2*tan(alphaX))

Is intended to read

  • fx = (imageWidth) / (2 * tan(alphaX) )

Where:

fx = focal length
imagewidth = sensor width
alphaX = HALF angle of view

This is consistent with the diagram below whose precision of rendition will hopefully be excused or ignored. The above formula then reduces to a simple geometric statement.
I have used slightly different terms to assist and/or confuse the mental process :-)

enter image description here

HALF the angle of view = alpha has tan(alpha) = Y/X = height/distance.
The identical tan is produced by half the image height on the sensor / focal length.
So
(sensor_height/2) / focal_length = height/distance = tan (alpha)
so
(IW/2) / fx = tan_alpha
invert
fx / (Iw/2) = 1/tan_alpha
fx = Iw/(2 x tan_alpha)

Answered by Russell McMahon

No comments:

Post a Comment