3D visionExplainer

Focal length from camera calibration: accuracy you can trust

The focal length from camera calibration is the right number for stereo triangulation; its accuracy comes from baseline, points and reprojection error.

LumaSpec Vision10 min read Share on LinkedIn

On this page 8 sections
  1. 01Can you use the calibrated focal length as the exact value?
  2. 02Why does the intrinsics matrix give focal length in pixels?
  3. 03What decides the accuracy of the calibrated focal length?
  4. 04How much depth error will your stereo rig have?
  5. 05How do you check the calibration before trusting it?
  6. 06When are webcams the wrong choice for stereo triangulation?
  7. 07What should you check before ordering the parts?
  8. 08Questions

You calibrated each camera against a checkerboard and the solver handed you an intrinsics matrix with a focal length in pixels. Before you hang distance measurements on that number, you need to know what it is, how close it sits to the truth, and what in your set-up moves it. This explainer is for stereo triangulation rigs — webcam prototypes and machine-vision pairs alike — in tasks such as parcel dimensioning or pallet positioning. You will see why the calibrated focal length is the right value to triangulate with, what reprojection error and baseline do to the depth you compute, and which checks separate a rig you can trust from one that only looks calibrated. A worked example puts millimetres on the depth error so you can size the baseline before you order a single part.

Can you use the calibrated focal length as the exact value?

Yes — for triangulation the calibrated value is the exact value, because the solver fitted it to your camera as built: your lens's true focal length, your focus setting and your pixel pitch folded into one scale factor. The pinhole model behind the fit looks like this:

K = [ fx 0 cx ] [ 0 fy cy ] [ 0 0 1 ]

fx and fy are the focal lengths in pixels; cx and cy place the principal point. Triangulation compares measured pixel positions against this same scale, so a fitted fx stays self-consistent with your pixel data in a way a datasheet millimetre value never is. The datasheet figure is nominal: two lenses with the same part number differ slightly from each other, and refocusing shifts the effective focal length. Calibration absorbs all of it, which is why the calibrated value is what your triangulation code should consume. Even with no datasheet at all, finding the sensor size and focal length from the camera itself only produces a starting estimate for lens selection; the fit then replaces it. For the same reason, calibrate each camera yourself rather than loading generic defaults — factory intrinsics versus your own calibration is a comparison the per-camera measurement wins whenever accuracy matters.

Why does the intrinsics matrix give focal length in pixels?

Because the solver never sees millimetres: it fits how image position scales with viewing angle, and on a sensor the natural unit of that scale is the pixel, set by the pixel pitch. The conversion is one division:

fx [px] = f [mm] / pixel size [mm/px]

Say the solver returns fx = 1250 px on a sensor with 4.8 µm pixels: f = 1250 × 0.0048 = 6.0 mm. Put the same 6 mm optic in front of 3.45 µm pixels and the calibration reports fx = 6.0 / 0.00345 ≈ 1739 px. Same lens, same field of view, different number — which is why comparing your calibrated fx with a datasheet millimetre value is meaningless until you divide by pixel pitch. Depth code wants the pixel value. The full story, including why 3D libraries quote focal length in pixels everywhere, is in why focal length is expressed in pixels.

What decides the accuracy of the calibrated focal length?

Three things you control: the number and placement of detected corners, the sharpness of those corners, and the solver's residual — the RMS reprojection error, which sits between 0.1 and 0.5 px on a healthy rig. That residual is your accuracy budget made visible: it says how well one focal length, one principal point and the distortion model explain every corner you showed the solver.

A small residual comes from:

  • 20 to 40 board poses, more for wide-angle lenses.
  • Corners spread across the whole frame, edges and corners included — not a board hovering near the centre.
  • The board tilted roughly 30 degrees in most poses, so the solver can separate focal length from distance.
  • Sharp, evenly lit corners on a board printed flat and mounted on glass or aluminium sheet.
  • Focus set and locked before the first pose, with exposure short enough to freeze the board.

Accept a calibration below 0.5 px RMS; above 1 px, reshoot instead of trusting it. With sub-pixel corner refinement — standard in the OpenCV routine and in every equivalent solver — a careful set-up lands in that band, and a residual stuck near 1 px almost always means blurry corners or coverage gaps rather than a bad camera.

How much depth error will your stereo rig have?

Depth error grows with the square of distance and falls in direct proportion to baseline and focal length, so doubling the baseline halves the error at every distance you measure. The pair of equations to keep on the wall:

Z = f · B / d σ_Z = Z² · σ_d / (f · B)

Z is distance, f the focal length in pixels, B the baseline, d the disparity in pixels, and σ_d the disparity error of your matcher.

Worked example with webcam-class inputs: fx = 800 px from each calibration, a 100 mm baseline with two webcams on a rail, and a matcher good to σ_d = 0.25 px on textured targets.

  • A target at Z = 2 m shows disparity d = f·B/Z = 800 × 100 / 2000 = 40 px.
  • Depth error there is σ_Z = Z²·σ_d/(f·B) = 2000² × 0.25 / (800 × 100) = 1,000,000 / 80,000 = 12.5 mm.
  • At Z = 4 m it is 4000² × 0.25 / 80,000 = 4,000,000 / 80,000 = 50 mm — twice the distance, four times the error.

Sizing a baseline inverts the formula: B = Z²·σ_d/(f·σ_Z). For 10 mm at 4 m with the same camera and matcher, B = 16,000,000 × 0.25 / (800 × 10) = 500 mm.

Baseline σ_Z at 2 m σ_Z at 4 m
100 mm 12.5 mm 50 mm
200 mm 6.25 mm 25 mm
500 mm 2.5 mm 10 mm

The table holds f = 800 px and σ_d = 0.25 px fixed. Treat it as a floor: the formula assumes matching error stays constant, and once the baseline is a large fraction of the distance the two views differ more, occlusions widen and real σ_d rises. Measure your own disparity residual on a known flat surface and rerun the arithmetic before trusting wide-baseline numbers.

How do you check the calibration before trusting it?

Run four checks: RMS reprojection below 0.5 px on each camera, fx within about 1 percent of fy on a square-pixel sensor, epipolar residuals under about half a pixel once the pair is calibrated, and one end-to-end test against a tape measure.

  • Per camera: the reprojection gate above, evaluated separately for both calibrations.
  • fx versus fy: on a square-pixel sensor the true ratio is 1:1; a gap beyond about 1 percent points at thin corner coverage or blurred corners, not at exotic optics.
  • Camera versus camera: two samples of the same model, same lens and same focus should agree on fx within 1 to 2 percent. A wider gap means one calibration is bad — reshoot it, never average the two.
  • As a pair: after the stereo calibration, matched points should sit on their epipolar lines to about 0.5 px, and rectified corresponding rows should align within a pixel.
  • End to end: place a high-contrast target at a taped-off 2 m and triangulate it. Landing inside the σ_Z the formula predicts means the rig is trustworthy; landing several times outside it means a sync fault, a moved focus ring or a warped board.

Reprojection error alone is a weak witness — extrinsic accuracy beyond reprojection error explains why the number you minimize is not the number you use. The same discipline as hand-eye calibration accuracy verification applies here: test against a known quantity before production depends on the output. And each camera keeps its own numbers — read the depth scale per camera rather than sharing one matrix across the pair.

When are webcams the wrong choice for stereo triangulation?

Webcams stop being good enough the moment the scene moves or the driver quietly changes settings: rolling shutter, autofocus, auto exposure and compressed streams each add error that no calibration can absorb. A static target, every automatic disabled and the highest-quality stream the driver offers is fine for a prototype; even then, plastic barrels and focus mechanisms drift with temperature and knocks, so a webcam pair needs recalibration more often than a logistics line tolerates. Rolling shutter also smears anything that moves, and a smeared corner is a shifted corner.

The production answer is a matched pair of area scan cameras with fixed lenses and locked settings. The MV-CU020-90GC is a 2.5 MP GigE camera with a global shutter, a 1/1.7" sensor and a C-mount, so one model covers static and moving targets; the camera finder narrows to mono sensors if you want to skip demosaicing and keep every pixel sharp.

Area scan camerasHikrobot MV-CU020-90GC 2.5 MP Area Scan Camera, GigE, GMAX4002, ColorMV-CU020-90GC
Sensor format
1/1.7"
Lens mount
C-mount
Interface
GigE
Resolution
Up to 3 MP
$309.00View partBuild a system with it

What should you check before ordering the parts?

Match the cameras, lock the optics and size the baseline from the depth formula before you buy: with fx = 800 px and 0.25 px matching, 10 mm at 4 m needs a 500 mm baseline, and that number decides the mounting bar. The short list:

  • Two identical camera models, so sensor, pixel pitch and lens behaviour match.
  • A fixed-focal-length machine vision lens on each — the LS-FFL-0679 is a 35 mm, 2/3", 6 MP C-mount design — with focus set at the working distance and locked.
  • Global shutter plus a shared hardware trigger if anything in the scene moves.
  • A baseline from B = Z²·σ_d/(f·σ_Z), on a bar stiff enough to hold it: 0.5 mm of flex on a 500 mm bar is 0.1 percent of scale, which is 4 mm of depth error at 4 m on top of the matching error.
  • A focal length chosen from coverage, not habit.
Machine vision lenses35 mm, 2/3", 6 MP, C-mount machine vision lens (LS-FFL-0679)LS-FFL-0679
Type
Machine vision fixed
Sensor format
2/3"
Mount
C-mount
Resolution
6-10 MP
$219.00View partBuild a system with it

For coverage, scale the field of view to the sensor: a 600 mm wide scene at a 3 m working distance on a sensor roughly 7 mm wide gives magnification m = 7 / 600 ≈ 0.0117 and f = WD × m / (1 + m) = 3000 × 0.0117 / 1.0117 ≈ 35 mm — a 35 mm class lens. The lens focal length calculator runs this for any sensor in the catalogue, and the lens finder filters by mount and format.

How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.
Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

The decision, one line each: prototype on webcams with every automatic off; move to a matched global-shutter pair with locked fixed lenses the day the scene moves or the line depends on the numbers; buy the baseline the formula asks for, not the one that fits the shelf. When the parts are settled, start the configurator at the camera step to build the pair. More calibration and depth work is indexed under the 3D vision topic.

Questions

Does refocusing the lens change the calibrated focal length?

Yes. Focusing moves lens elements relative to the sensor, and the effective focal length the calibration measures moves with it — a click of the focus ring invalidates fx. Set focus with a target at the working distance, then tape, clamp or set-screw the ring before calibrating, and recalibrate any camera whose ring has been touched.

Does temperature change the calibrated focal length?

It can. A plastic webcam barrel expands enough to shift elements and move fx between a cold start and a warmed-up rig, so calibrate after warm-up and expect slow drift over weeks. Metal-housed machine-vision cameras with fixed lenses hold the value far better, which matters more the tighter your depth budget is.

Why are fx and fy different, and when is that a problem?

On a square-pixel sensor the true ratio is 1:1, so a healthy fit puts fx and fy within about 1 percent of each other. A larger gap usually means thin corner coverage or blurred corners rather than a real optical difference. Let the solver estimate both, then reshoot with the board spread wider across the frame if they disagree.

Where in the calibration file is the focal length?

Read the 3 × 3 intrinsics matrix the calibration wrote: fx is the element at row 1, column 1, fy at row 2, column 2, and the principal point cx, cy fills the last column of the same matrix. The file also stores the distortion coefficients — keep them with the intrinsics, because triangulation runs on undistorted points.

Can I calibrate one camera and copy the numbers to the second?

No. Two cameras of the same model differ in sensor seating, lens sample and focus, so each needs its own intrinsics. Calibrate both, then run the pairwise stereo calibration for the rotation and translation between them. Copying one matrix across both hides a real scale difference, which surfaces later as depth error you cannot trace.

What baseline gives 10 mm depth accuracy at 4 m?

About 500 mm, with fx = 800 px and disparity matched to 0.25 px: B = Z² · σ_d / (f · σ_Z) = 16,000,000 × 0.25 / (800 × 10). Halving to 250 mm works only if the matcher holds 0.125 px, which is optimistic away from the bench; a longer baseline with ordinary matching is the cheaper win.