• Home
  • >
  • Tutorial
  • >
  • Approximate Focal Length for Webcams and Cell Phone Cameras

Approximate Focal Length for Webcams and Cell Phone Cameras

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.

Relationship between Focal Length, Field of View and Sensor Size

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.

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.

Relationship between Focal Length, Field of View and Sensor Size
Relationship between Focal Length, Field of View and Sensor Size

Using basic trigonometry we can conclude that the field of view ( \alpha ) is related to image plane dimension ( w ) and focal length ( f ) using the equation below.

    \[\alpha = 2 \tan^{-1} \frac{w}{2f}\]

which can be rewritten as

    \[f = \frac{w}{2} \cot \frac{\alpha}{2} \newline\]

Based on the above equation if you know the image width w, and the field of view \alpha you can calculate the focal length f 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 \alpha in the above equation we can say the focal length is related to the width of the image by the following bounds.

    \[0.7 w \leq f \leq w\]

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.

hfov-vfov-dfov

So if you are using the FOV specified by your camera manufacturer you gotta use the following formula

    \[f = \frac{d}{2} \cot \frac{\alpha}{2} \newline\]

where, d = \sqrt{w^2 + h^2} 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 ( \alpha ) if you need to find the horizontal FOV ( \alpha_H ) and vertical FOV ( \alpha_V ), you can use the following formula ( courtesy this link )

    \begin{align*}\alpha_H &= 2 \tan^{-1} \Big \lbrack tan ( \alpha ) \cos \Big ( \tan^{-1} \frac{h}{w} \Big ) \Big \rbrack \\\alpha_V &= 2 \tan^{-1} \Big \lbrack tan ( \alpha ) \sin \Big ( \tan^{-1} \frac{h}{w} \Big ) \Big \rbrack\end{align*}



Read Next

VideoRAG: Redefining Long-Context Video Comprehension

VideoRAG: Redefining Long-Context Video Comprehension

Discover VideoRAG, a framework that fuses graph-based reasoning and multi-modal retrieval to enhance LLMs' ability to understand multi-hour videos efficiently.

AI Agent in Action: Automating Desktop Tasks with VLMs

AI Agent in Action: Automating Desktop Tasks with VLMs

Learn how to build AI agent from scratch using Moondream3 and Gemini. It is a generic task based agent free from…

The Ultimate Guide To VLM Evaluation Metrics, Datasets, And Benchmarks

The Ultimate Guide To VLM Evaluation Metrics, Datasets, And Benchmarks

Get a comprehensive overview of VLM Evaluation Metrics, Benchmarks and various datasets for tasks like VQA, OCR and Image Captioning.

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.

Subscribe to receive the download link, receive updates, and be notified of bug fixes

Which email should I send you the download link?

 

Get Started with OpenCV

Subscribe To Receive

We hate SPAM and promise to keep your email address safe.​