Pick the lens before anything else in a machine-vision station: the focal length decides how much of the part the camera sees from where it can be mounted. Choose what to solve for, pick the camera's sensor (or type its size), and enter the numbers you know. The calculator returns the focal length, the field of view on both axes, the working distance, the angle of view and the size of one pixel on the part, draws the set-up at its true angle and compares every standard focal length at your distance.
Three ways to solve it
- Focal length: you know where the camera can go and what it must see. Enter the working distance and the field of view; the calculator returns the focal length and the nearest standard lenses.
- Field of view: you already have a lens. Enter its focal length and the working distance to see what it covers and how large one pixel is on the part.
- Working distance: the lens and the field are fixed. The calculator returns how far from the part the lens must sit, which tells you whether the station has room.
The lens table below the results works in all three modes. Each row is a standard focal length at your working distance, with the field it covers, the pixel size on the part and the distance at which it would cover exactly your target field. The highlighted row is the closest match. Switch to inches with the mm / in buttons; the link button copies the numbers so a colleague opens the same calculation.
How the focal length calculation works
The calculator uses the thin-lens model, which is accurate enough for choosing a fixed-focal-length lens at normal working distances:
Here m is the optical magnification, WD the working distance from the lens to the part, and f the focal length, all in millimetres. The third line runs the calculation backwards: it gives the field of view a lens of known focal length covers at a given distance. Use it to check each standard lens you are considering.
Worked example: a 100 mm field at 300 mm
A 5 MP camera (2448 × 2048 pixels of 3.45 µm, so 8.45 mm wide and 7.07 mm high, a 2/3-inch format) must see a part 100 mm wide, and the machine leaves 300 mm between the lens and the part. These are the calculator's starting values.
- Magnification: m = 8.45 / 100 = 0.0845.
- Focal length: f = 300 × 0.0845 / 1.0845 = 23.4 mm.
- Nearest standard lenses: 25 mm and 16 mm.
- With a 25 mm lens: field of view = 8.45 × (300 − 25) / 25 = 93.0 mm wide. That is 7 % short of the 100 mm target.
- With a 16 mm lens: field of view = 8.45 × 284 / 16 = 150 mm wide. The part fits easily, but it fills only 67 % of the image width.
There are two good answers. Keep the 25 mm lens and move the camera back: the distance for a 100 mm field is WD = f × (1 + 1/m) = 25 × 12.83 = 321 mm, if the machine has room for the extra 21 mm. Or take the 16 mm lens and accept fewer pixels on the part, then check that the camera resolution calculator still gives enough pixels across the smallest feature.
Sensor sizes and their widths
Sensor formats are named after old vidicon tubes, so the inch size is not a measurement. Use the width and height in millimetres.
| Format | Nominal width × height | Diagonal |
|---|---|---|
| 1/3 inch | 4.8 × 3.6 mm | 6.0 mm |
| 1/2 inch | 6.4 × 4.8 mm | 8.0 mm |
| 1/1.8 inch | 7.2 × 5.4 mm | 9.0 mm |
| 2/3 inch | 8.8 × 6.6 mm | 11.0 mm |
| 1 inch | 12.8 × 9.6 mm | 16.0 mm |
| 4/3 inch | 17.3 × 13.0 mm | 21.6 mm |
Real sensors differ from these nominal sizes. Multiply the pixel count by the pixel size for the exact value: 2448 × 3.45 µm = 8.45 mm, 4096 × 3.45 µm = 14.1 mm. The lens must also cover the sensor: its image circle, printed as the largest supported format, must be at least the sensor diagonal, or the corners go dark.
Check the height as well as the width
The calculator works on the width because most parts are wider than they are tall. The vertical field follows from the same magnification: height of field = sensor height / m. In the example above, a 25 mm lens at 300 mm has m = 25 / 275 = 0.0909 and gives 7.07 / 0.0909 = 77.8 mm of height. If the part is taller than that, size the lens on the height instead and let the width grow.
A sensor with a 4:3 shape and one with a 1:1 shape can need different lenses for the same part. Square parts, round parts and code-reading windows often fit a square sensor better.
When the simple estimate is not enough
The thin-lens formula assumes the working distance is measured from the lens's principal plane, which sits somewhere inside the barrel. For long distances the difference is negligible. Below about 150 mm, or at magnifications above about 0.2, the result can be several percent off.
- Minimum object distance. Every lens has a closest focus distance. If the calculated working distance is shorter, the lens will not focus without an extension tube, which also changes the magnification.
- Short focal lengths. Lenses under about 8 mm show visible barrel distortion, so the field of view and any measurement near the image edge drift from the formula. Calibrate the camera if you measure.
- Gauging. When parts move closer to or further from the lens, a standard lens changes their apparent size. Use telecentric lenses for measurement on parts that are not at one exact height; the telecentric lens guide explains when that matters.
- Small cameras. Board-level cameras use M12 lenses, which come in the same focal length steps but with smaller image circles.
Next steps
With the focal length settled, check the other two numbers that decide a lens. The depth of field calculator shows how far parts can vary in height and stay sharp at your aperture. The camera resolution calculator shows whether the sensor has enough pixels for the field. The longer guide to choosing a machine vision lens focal length walks through mounts, formats and a worked station. To see matching parts, open the lens finder or start the configurator at the lens step.
Questions
How do I calculate the focal length for a machine vision camera?
Find the magnification first: sensor width divided by the field of view width. Then focal length equals working distance times magnification divided by one plus magnification. For an 8.8 mm wide sensor, a 100 mm field and a 300 mm working distance, the magnification is 0.088 and the focal length about 24 mm. Pick the nearest standard lens and recheck the field it gives.
Should I pick the shorter or the longer standard focal length?
The shorter lens shows a wider field at the same distance, so it never cuts off the part; the longer lens gives more pixels on the part but may not fit it in. When the calculated value falls between two lenses, take the shorter one and keep the margin, or move the camera slightly further away with the longer one.
Does the formula work for telecentric lenses?
No. A telecentric lens has a fixed magnification printed on its data sheet, and its field of view is the sensor size divided by that magnification at any distance within its depth of field. Choose a telecentric lens by magnification and field size, not by focal length or working distance.
Which sensor width should I enter?
Use the real active width: horizontal pixel count times pixel size. A 2448 pixel sensor with 3.45 micrometre pixels is 8.45 mm wide, slightly less than the nominal 8.8 mm of a 2/3-inch format. The nominal value is fine for a first estimate; the real width gives the field you will actually see.