In this post I will explain how to find a crude approximation to the focal length of a webcam or cell phone camera ( i.e. fixed focal length cameras ) if calibration is not an option or if you are too lazy to take a few pictures of a checkerboard.
Recently I was working on a project where I needed to know the focal length of a webcam. I thought I could just look up the specs of the webcam included in my macbook pro. Turns out Apple doesn’t publish the specifications like ( focal length, sensor size etc. ). I did not need the exact value of the focal length, an approximate value in pixel dimensions was all that I was looking for.
Of course I could simply use a checkerboard pattern, take a few images with different orientations and find the internal parameters ( focal length, center, lens distortion coefficients ) of the camera. But I was working out of a local Starbucks, sipping coffee on a beautiful San Diego summer day, and locomotion was not an idea I was excited about at that time. Physical laziness is a creative force that helps mental activity.
So I started thinking about the best approximation one can make given an image from a webcam. Before I explain my approximation, I need to explain a tiny bit of theory.
OpenCV For Beginners available at a discounted launch price of $87 (Standard Retail Price: $117).
Focal length, Field of View (FOV) and Sensor Size
The image below shows the relationship between focal length of the camera, the field of view and the size of the sensor.
Using basic trigonometry we can conclude that the field of view ( ) is related to image plane dimension ( ) and focal length ( ) using the equation below.
which can be rewritten as
Based on the above equation if you know the image width , and the field of view you can calculate the focal length in pixels.
Calculate focal length using image width by assuming field of view
If you think about it, the field of view of most webcams should be similar because they expect you to be at a certain distance from the camera ( say a foot and a half ), and they would want the face to be a certain size ( not too large, not too small ).
The horizontal field of view of many webcams and cell phones is 50 to 70 degrees.
Now plugging the range of in the above equation we can say the focal length is related to the width of the image by the following bounds.
That is a crude approximation and should not be used in applications where accurate focal length is required, but it does give you a rule of thumb that is useful even if you use accurate calibration. For example, if your webcam has a resolution of 1280×720, and using a calibration procedure you found the focal length to be between 1100 and 1300, your measured focal length it is probably right. But if the focal length you found is 12500, you probably have calibrated incorrectly or have an unusual lens.
Horizontal Field of View ( HFOV ), Vertical Field of View ( VFOV ) and Diagonal Field of View ( DFOV ).
Now let’s say you have additional information about your camera. For example, Logitech c920 camera specification states that it has a field of view of 78 degrees. You rush to plug that number into the equation you just learned but you are a bit confused.
It is obvious to you that since the aspect ratio is 16:9, the horizontal field of view is larger than the vertical field of view. Which one does the specification refer to ? Neither. The specification refers to the Diagonal Field of View ( DFOV ). The DFOV (see figure below) is the angle subtended by the diagonal of the camera sensor onto the center of the lens.
So if you are using the FOV specified by your camera manufacturer you gotta use the following formula
where, is the length of the diagonal.
How to find Horizontal Field of View (HFOV) and Vertical Field of View (VFOV) from Diagonal Field of View (DFOV)
Given the DFOV ( ) if you need to find the horizontal FOV ( ) and vertical FOV ( ), you can use the following formula ( courtesy this link )