Assuming a standard lens, standard camera, i.e. the setup can be modelled as a pin-hole camera. This doesn't work with tilt/shift, and maybe not with wide-angle lenses (if you want to know about those, we could work it out).
In computer vision, often the intrinsic properties of cameras are calculated. Intrinsic because they refer to settings of the camera within the camera. Extrinsic properties are orientation and position. Intrinsic properties are several, among them the magnification. My solution is:
- Use a standard tool from Computer Vision (CV) to calibrate the camera and lens at the given settings.
- Look up the pixel size for your camera.
- Ask someone else to convert magnification to focal length. (I don't know yet how this works)
Calibrating in CV is mostly done using a chess board pattern. You take several (~10) photos of that pattern from various positions and distances. The algorithm works then in the following way:
Pretend that you know the position of each vertice on the board, find a set of parameters to the camera model that best explain seeing all the points on the board in the images.
In theory I would recommend OpenCV for this, it has an example code for that. But this is maybe not too practical (you'll need to install OpenCV for this, and possibly change a bit of code.). There are probably other solutions out there that do this.
Calculating focal length
The result of the calibration step is the K matrix (called the intrinsic matrix). It maps 3-space points in the camera's coordinate system to homogeneous 2-space points on the image plane.
$ \alpha 0 p_x
K = 0 \alpha p_y
0 0 1 $ (Multiple View Geometry, p. 157, 2nd Ed, 2003, Hartley & Zisserman)
We only care about \alpha here. p_x is about half the sensor width in pixel, similarly for p_y, it relates to where the principal ray intersects the image plane. Interestingly my cheap phone camera violates that much more than a good DSLR, or even an expensive webcam, or an Iphone 4 camera.
\alpha is then related to the focal length.
\alpha = f m.
m is the number of pixels per unit distance in image coordinates.
f is the focal length. But note: this is in the pinhole camera model, so the distance between image plane and pin-hole of the camera. I am not sure how to find the focal length photographers think of to it.
Someone posted a link about a different approach: http://www.bobatkins.com/photography/technical/measuring_focal_length.html
Down at "The Easy Way" in the article a different method is proposed. Given two stars, look up the positions of the stars and calculate the angle between them. Then see how your camera setup measures that angle. Read the link for a complete run-through.
The downside of that is that it won't work with any focal distance but only focus at infinity. On the other hand, my approach won't work at infinity. Or treat 500m as infinity, buy a corn field and mow a chess board pattern into it, rent plane and take photos from 500m up...