3D visionHow-to

Camera calibration with a known distance: fix the Z translation

With the known camera-to-target distance, hold Z at your measurement and run a constrained least-squares calibration solve so focal length stops trading off.

LumaSpec Vision9 min read Share on LinkedIn

On this page 10 sections
  1. 01Why does the same image give a different focal length every run?
  2. 02Can you fix Z inside the usual calibration tool?
  3. 03What stays fixed and what stays free?
  4. 04How do you measure the camera-to-target distance on the bench?
  5. 05What are the steps of a fixed-Z solve?
  6. 06What numbers come out when Z is pinned?
  7. 07How accurate does the measured distance have to be?
  8. 08When does a pinned Z still give a wrong focal length?
  9. 09What comes after the intrinsics are right?
  10. 10Questions

Run one calibration image through an unconstrained estimator twice and you can get two different focal lengths, each with a different camera-to-target Z behind it. Nothing in the rig moved: with a single view of a plane, focal length and distance are nearly the same knob. This guide shows you how to measure the distance once, hold it fixed in a constrained least-squares solve, and get a focal length that stays put, plus the error budget that tells you how accurate your measurement has to be.

Why does the same image give a different focal length every run?

With one view of a planar target, the pixels pin only the ratio of focal length to distance — f/Z — so a 12.0 mm lens at 300.0 mm and a 13.2 mm lens at 330.0 mm project the identical 2,000-pixel-wide target image.

Every corner lands on the same pixel in both worlds, so the reprojection residual cannot tell them apart. Tilted views break the tie only weakly, and the optimizer stops wherever pixel noise pushes it along the shallow valley. Same image in, different focal length out, run after run.

The fix is to remove one axis of that valley. You know Z, so hold it and let the solve own everything else.

Can you fix Z inside the usual calibration tool?

No: the standard single-call intrinsics estimators, estimateCameraParameters among them, take no fixed-translation argument, so you keep their calibration-object and camera-model definitions but move the optimization into your own constrained least-squares solve with lsqnonlin.

lsqcurvefit reaches the same result; lsqnonlin is the natural pick because the reprojection residual is already a vector of pixel errors. Reuse the estimator's corner detection and calibration-object handling, and feed your own residual: detected corners minus corners projected with t_z replaced by a constant. A plain Levenberg–Marquardt step does the rest.

What stays fixed and what stays free?

Hold only the Z component of the camera-to-target translation at the measured value; every other unknown — the three rotation angles, X and Y, focal length, principal point and distortion — stays free for the solver to fit.

Keep distortion free even on few views: distortion comes from straight lines curving in the frame and carries no scale information, so it cannot re-open the f–Z valley. Model one focal length for square pixels unless you have measured a reason to split f_x and f_y.

How do you measure the camera-to-target distance on the bench?

Measure from the target plane to the sensor plane, not to the front of the lens: a C-mount sensor sits 17.526 mm behind the flange face, and skipping that offset adds about 6% error to a 300 mm distance.

Lock the focus ring and the iris before you measure. Refocusing afterwards moves the lens package and changes the distance you just wrote down; focus and iris locks exist for exactly this reason. A depth gauge from the flange face plus 17.526 mm gives the sensor-plane number, and on a slide-table stand the column scale does most of the work.

Choose the board with the same care — the checkerboard target size guide sizes squares and corner count for your resolution — and keep it inside the lens coverage with margin as in the calibration target field of view guide. Square the board to the optical axis with a rotation stage so the pose Z matches the number on your tape.

The camera stands category holds the slide-table types that make this measurement routine. The LS-MNT-0040 machine vision camera stand is a slide-table type with a 700 mm working height, and the LS-MNT-0220 manual XY + rotation stage adds 60 mm of travel for squaring the target.

What are the steps of a fixed-Z solve?

Six steps take you from a taped distance to a stable focal length, and the only new code is the residual function with one parameter removed.

  1. Lock focus and aperture, then measure the sensor-plane distance and write it down with its uncertainty, for example 300.0 mm ±1 mm.
  2. Capture 10–20 views of the board at varied tilts and off-centre positions, moving the board rather than the camera — the move the camera or the chessboard guide explains why the camera stays put on a fixed rig.
  3. Detect corners with the estimator's own routines and store each view's image points together with the board's metric corner grid.
  4. Build the parameter vector: focal length, principal point, distortion, and per view the rotation and X, Y translation. Leave t_z out entirely — it lives in a constant.
  5. Project every board corner with t_z set to the measured constant, subtract the detected pixels, and minimize the residual vector with lsqnonlin, starting at the lens's marked focal length and near-zero X, Y.
  6. Check the result: a well-run planar solve lands near or under half a pixel RMS, with targets in the calibration residual values guide. Re-run once with Z freed — if f jumps by more than your distance uncertainty allows, the measured distance was off.

Any of the shop's area scan cameras can sit on such a rig; the LS-CMR-0166 captures 4000 × 3000 frames over USB3, which is ample corner count for this solve.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

What numbers come out when Z is pinned?

The solve returns focal length straight from image scale, with no valley left to wander: a 100.0 mm-wide target spanning 2,000 pixels at a pinned 300.0 mm distance forces f = 12.0 mm, and no other value reproduces those pixels.

With w the target's projected width on the sensor, W the board width and Z the pinned distance, all in millimetres:

w = f × W / Z f = w × Z / W df / f = dZ / Z

Check it end to end. A sensor with 2.0 µm pixels and 4,000 columns is 4,000 × 0.002 mm = 8.0 mm wide. A 100.0 mm target at Z = 300.0 mm with a 12.0 mm lens projects to 12.0 × 100.0 / 300.0 = 4.0 mm, which is 4.0 / 0.002 = 2,000 pixels. Free the pair and the solver can just as well return 13.2 mm and 330.0 mm: 13.2 × 100.0 / 330.0 = 4.0 mm, the same 2,000 pixels, both numbers 10% wrong. Pin Z at 300.0 mm and the same 2,000 pixels give back f = 4.0 × 300.0 / 100.0 = 12.0 mm, exactly.

The pinned focal length also fixes the field of view at that distance: 8.0 mm × 300.0 / 12.0 = 200 mm across. In solver units that is 12.0 / 0.002 = 6,000 — the focal length in pixels guide untangles that unit. Pick the lens with the lens focal length calculator so the target fills a good fraction of the field.

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

How accurate does the measured distance have to be?

Error moves across one-to-one in relative terms: df/f = dZ/Z, so a ±3 mm distance error at 300.0 mm becomes a ±1% focal length error, ±0.12 mm on a 12 mm lens.

A steel rule read to ±1 mm gives ±0.33% at 300 mm — ample for lens selection and most gauge set-ups. Sub-0.1% focal accuracy wants slip gauges or a calibrated depth micrometer, and it wants a re-measure after anything on the rig is disassembled. Watch the sign too: a distance read short inflates f by the same relative amount, since f = w × Z / W.

When does a pinned Z still give a wrong focal length?

The failures are mechanical, not mathematical: refocus after measuring, a zoom ring that creeps, a mount that warms up, and the constant you pinned is no longer the distance the images actually saw.

  • Refocusing after the tape invalidates it. Re-measure whenever focus moves, and log the focus position as part of the calibration record.
  • Fix zoom lenses mechanically at one marked stop. Focal length changes with every zoom move, so the constraint holds for one position only.
  • Shop temperature moves focus on long-throw rigs; the camera focus drift with temperature guide shows how to catch daytime drift before it eats your distance.

The damage a wrong pair does is quiet scaling: every pose the camera reports inherits the error, so a part reads 10% small and 10% closer at the same time. That symptom — pose right in angle, wrong in range — is worked through in the fiducial pose wrong distance guide. If anything on the rig is later bumped or remounted, the static camera calibration accuracy guide is the reminder that a moved part recalibrates from scratch.

What comes after the intrinsics are right?

Hand the pinned camera model onward the same way any calibrated model is handed over: intrinsics into the hand-eye step, poses into the robot, and the distance budget into the maintenance plan for the cell.

The next integration step is usually camera intrinsics for hand-eye calibration, because a wrong focal length there turns into a wrong tool transform, and no amount of robot-side tuning hides it. Keep the measured Z and its uncertainty in the calibration record so the next engineer knows what the model is standing on; the 3D vision topic collects the guides that follow, from pose to point clouds.

To equip a measured-distance bench, pick the stand and stage at the configurator step below, or send your working distance and board size through the contact page and we will spec the rig with you.

Build the whole station

The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.

Start with the mounting

Questions

Can I fix focal length instead and let the solver find the distance?

Yes — the constraint is symmetric. Pinning f and freeing Z answers how far away the target is, which is what pose-only applications need. It is the weaker choice for intrinsics, though: marked focal lengths routinely sit a few percent off their nominal value, while a taped distance is read to a millimetre. Trust the measurement you made, not the one printed on the barrel.

How many images does a fixed-Z calibration need?

One view carries complete scale information once Z is pinned, so a single frame can return a usable focal length. Keep capturing 10 to 20 varied poses anyway: tilt and off-centre positions are what give the distortion coefficients and the principal point their leverage. If you move the target between shots, record a fresh distance for each pose or return it to the same stand height.

Does holding Z fixed also determine the distortion coefficients?

No. Distortion bends straight lines near the frame edges and has nothing to do with image scale, so it is invisible to the f–Z trade-off. Leave every distortion coefficient free in the solve. With few views they will be weakly estimated, which is one more reason to capture varied poses rather than repeats of one frame.

My target is tilted, not square to the camera — which distance do I enter?

Enter the distance along the camera axis to the board origin, because that is the translation component the pose uses. A tape held perpendicular to the board reads the shorter perpendicular distance: at 10° of tilt, 300.0 mm perpendicular is 300.0 / cos 10° = 304.6 mm axial, and entering the smaller number biases focal length by about 1.5%. Square the board or convert.