Skip to content

Focal Length & Distance

Liam Lawrence edited this page Mar 16, 2017 · 1 revision

Distance calculation from a static image is a very complicated thing, but it doesn't have to be too bad. Here I will give a basic explanation of how we do it and what some things such as focal length really are.


Explaining Focal Length and Formulas

Focal Length is a number, usually in mm, that represents the distance from the lens of our camera to the actual light sensor itself. This can be seen in the diagram below.

FocalLength

The basic formula for finding Focal length is

Focal Length = (Perceived Size) x (Distance) / (Real Size)

Focal length for each camera is a constant, so once we know that we can then start solving for distance in the equation

Distance = (Real Size) x (Focal Length) / (Perceived Size)


Choosing a Side and Finding Distance

Noise is always an issue when it comes to cameras, this can cause lots of issues if the object your measuring isn't very big, you should try to choose a feature that has the largest area compared to your other options. This year I decided to use the height of the goal as the value for "Real Size" in the equation above.

Now I know that using the the total area of the goal (Width x Height) would yield a larger feature to work with, however because of the curvature of the retro reflective tape, the light doesn't reflect on the far side of the curves causing it to think the width is smaller than it actually is. For this years game, stick to height.

Since we are using height, our perceived height would be the difference between the top of the tape, and the very bottom. I calculate the location of these points and they can be seen in debug mode as the yellow and purple dots.

example

Now we take the height in pixels, or the absolute value of the difference between the Y coordinates of those points, and we can plug that into our equation. We have all of the variables and now we can solve for distance!

Note: You can use any unit you like as long as you stay consistent, I like to use inches but you could use centimeters, meters, or even nautical miles if you want.