Lenses & opticsHow-to

Build a lens distortion profile for a board camera without an LCP file

Shoot a checkerboard with your board camera and M12 lens, fit the distortion, reach RMS under 0.5 px and apply the profile yourself — no LCP file needed.

LumaSpec Vision11 min read Share on LinkedIn

On this page 10 sections
  1. 01What do you lose by having no LCP file?
  2. 02What hardware do you need to build the profile?
  3. 03How big should the calibration target be for your field of view?
  4. 04How many images does a good profile take?
  5. 05How do you turn the images into coefficients?
  6. 06What RMS reprojection error should you accept?
  7. 07How do you apply the profile in your pipeline?
  8. 08When is a distortion profile the wrong fix?
  9. 09What checks catch a bad profile before it ships?
  10. 10Questions

An M12 board lens almost never ships with a lens profile. LCP files, the kind raw converters load, are written per camera-and-lens pair, and nobody publishes them for a 2.85 mm board lens on a 1.6 MP sensor, so the geometry work lands on you. The fix is a standard checkerboard calibration: shoot a target, fit the distortion model, keep the coefficients, and apply them from then on. This guide walks the whole sequence on real hardware — target sizing, capture poses, the fit, the acceptance number and how to apply the result — so your board camera measures in millimeters the day it arrives.

What do you lose by having no LCP file?

Less than you fear. An LCP file only stores a geometry model — a distortion polynomial against field radius, plus tangential terms and vignette data — and you can measure that geometry from your own target to well under a pixel.

The file also names a camera body and lens, and that pairing is why board lenses never get one. A board camera ships into hundreds of lens, sensor and focus combinations, and every focus setting changes the answer. A published profile would be wrong for your module anyway. What you must replace is only the numbers.

The number that matters: on a sensor 1456 pixels wide, the frame corner sits √(728² + 544²) ≈ 909 px from the center. A 2.85 mm wide M12 lens carries roughly 5-10% barrel distortion, which drags that corner point 45-90 px off its true position. Straight edges bow visibly at that level, and any pixel-to-mm scale that assumes a pinhole camera is wrong by the same proportion. The profile you are about to build removes it; lens distortion correction for accurate pixel-to-mm measurements shows what that buys downstream.

What hardware do you need to build the profile?

You need the exact camera and lens you will ship, one rigid target, diffuse light and a locked focus ring. Budget an hour, because any refocus after the fit invalidates it.

Build the profile on production hardware: the coefficients belong to one lens-plus-sensor-plus-focus state. The board-level cameras finder filters by M12 mount and interface so the pairing starts right. For the worked example this guide uses the MV-CB016-10GM-M-W, a 1.6 MP GigE board-level camera with an M12 lens mount and a 1/2.9" global-shutter sensor, with the LS-MBL-0090, a 2.85 mm M12 board lens rated for 1/2.9" sensors:

Board-level camerasHikrobot MV-CB016-10GM-M-W 1.6 MP GigE board-level camera, IMX296, Mono, M12 lens mount, WTB GigE portMV-CB016-10GM-M-W
Sensor format
1/2.9"
Lens mount
M12
Interface
GigE
Resolution
Up to 3 MP
$559.00View partBuild a system with it
M12 board lenses2.85 mm, 1/2.9", 2 MP, M12 board lens (LS-MBL-0090)LS-MBL-0090
Type
M12 board
Sensor format
1/2.9"
Mount
M12
Resolution
Up to 3 MP
$59.00View partBuild a system with it

Print the pattern on paper and the paper's own curl enters your lens model as fake distortion. A machined or anodized plate holds the reference flat, which is the flatness class your fit assumes. The LS-LXR-0029 calibration board has 0.5 mm dots in a grid on a 76 x 76 mm plate; a dot grid calibrates exactly like a checkerboard, with a circle finder in place of the corner finder. More targets and mounts sit in lens accessories.

Lens accessoriesCalibration boards and depth-of-field rulers, dot diameter 0.5 mm, dot grid, 76 x 76 mm (LS-LXR-0029)LS-LXR-0029
Type
Calibration targets
$189.00View partBuild a system with it

Focus once at the working distance, then lock it: M12 lens focusing: adjust, check corners and lock covers the corner check that proves focus, and lens locking screws covers the hardware that holds it.

How big should the calibration target be for your field of view?

Size it so one square spans 15-25 pixels and the pattern covers at least a third of the frame width — enough points per pose, without printing a table-sized board.

Work the numbers for the example pair. Take the sensor as 1456 x 1088 pixels on a 3.45 µm pitch, the common 1/2.9" global-shutter class: sensor width = 1456 x 3.45 µm = 5.02 mm. The thin-lens estimate for the field of view at a 200 mm working distance is 200 x 5.02 / 2.85 = 352 mm across, so one pixel covers 352 / 1456 = 0.24 mm. Print squares between 15 x 0.24 = 3.6 mm and 25 x 0.24 = 6.0 mm; 5 mm squares land at 5 / 0.24 = 21 px each.

FOV = working_distance x sensor_width / focal_length pixel_scale = FOV / pixels_across square_size = 20 x pixel_scale

The 76 mm dot plate fills 76 / 352 = 22% of the frame at 200 mm, which suits the tilted poses; bring the flat poses to 120 mm, where the field shrinks to 120 x 5.02 / 2.85 = 211 mm and the plate covers 36%. Margins like these are the subject of calibration target field of view and lens coverage margins, and picking the lens itself is the job of M12 lens selection for board cameras.

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 many images does a good profile take?

Fifteen to twenty-five poses, at least a third of them tilted 20-35°; ten flat-on shots will fit a scale but leave the distortion terms trading against each other.

Run the shoot like this:

  1. Bolt the camera down and put the target on a stage you can tilt and slide; a hand-held target adds blur you will later blame on the lens.
  2. Light the pattern diffusely from the side and keep exposure under 10 ms so edges freeze.
  3. Focus at the working distance, lock the ring and mark it.
  4. Capture 4-6 front-on poses with the pattern centered and filling at least a third of the frame.
  5. Tilt the target 20-35° left, right, up and down; tilted views are what separate tangential error from radial error.
  6. Place the pattern fully inside each of the four frame corners in turn.
  7. Vary the distance about ±20% so scale is constrained at more than one magnification.
  8. Scroll the set and delete any frame with glare on the pattern or a missed point detection.

That list lands you at 15-25 usable frames: 4-6 flat, 8-10 tilted, 4 in the corners. Below ten total, refits of the same images move fx by several pixels — the sign that distortion and focal length are unconstrained against each other.

How do you turn the images into coefficients?

Feed every pose into a monocular camera-calibration routine; it returns five distortion terms plus fx, fy, cx and cy, and for this 2.85 mm lens fx comes out near 826 px.

Every mainstream vision library ships this routine; OpenCV's camera calibration tutorial walks it in Python and C++. You supply the grid geometry, the detected points per frame and the image size. The routine returns the intrinsics, the distortion terms and an RMS you can gate the fit on.

x_d = x(1 + k1 r² + k2 r⁴ + k3 r⁶) + 2 p1 x y + p2(r² + 2x²) y_d = y(1 + k1 r² + k2 r⁴ + k3 r⁶) + p1(r² + 2y²) + 2 p2 x y fx = focal_length / pixel_pitch

The profile stores focal length in pixels because the sensor has already turned millimeters into a grid: fx = 2.85 mm / 0.00345 mm = 826 px. The distortion terms are normalized instead, which is why they survive binning and cropping while fx does not. For this lens class expect k1 around -0.05 to -0.15 (barrel, negative), p1 and p2 two orders of magnitude smaller, and k3 only resolvable once tilted poses are in the set. What each term does to an image is unpacked in unrectified camera image: interpreting distortion coefficients.

What RMS reprojection error should you accept?

Accept anything under 0.5 px, expect 0.1-0.3 px from a careful shoot, and treat a larger fit as a capture problem — the images are the variable, not the lens.

RMS reprojection error Verdict
0.10-0.30 px Ship it; recheck at commissioning
0.30-0.50 px Usable; hunt the weak frames first
0.50-1.00 px One capture rule is broken; retake the set
above 1.00 px Focus, target flatness or point detection is wrong

When the number lands high, the causes come in this order: the target is not flat (paper on a wall adds tenths of a pixel on its own), the point finder locks one pixel off on glare, focus drifted between poses, or every shot is front-on. Most libraries print a per-view error; discard a bad calibration image or retake the pose shows how to use it, and retiring the worst two or three frames commonly halves the total. Heat is the slow cause: the drift covered in camera focus drift with temperature shifts fx a little at a time, so a station that runs hot deserves a recheck after its first week.

Proving the correction works is a separate measurement — how to measure barrel distortion correction accuracy gives the method with a straight edge or a re-measured grid.

How do you apply the profile in your pipeline?

Build one undistortion pixel map from the coefficients and remap every frame before measurement; on a 1.6 MP frame the remap costs on the order of a millisecond on an industrial host.

Store the result as a single record — fx, fy, cx, cy, the five distortion terms, image size, lens model, focus note, date — keyed to the camera serial number and versioned alongside your code. When the pipeline bins or crops, rescale the intrinsics and keep the distortion terms; cropping at the source, as in camera ROI cropping at the source, moves cx and cy by the crop offset. Apply the map before anything that assumes straight lines or a stable pixel scale: edge fitting, calliper reads, robot offsets.

When is a distortion profile the wrong fix?

Three cases: when you can buy the distortion out, when you only need detection rather than measurement, and when the lens is too wide for the polynomial model above.

Buying it out: a lens sold as low-distortion holds the corner error to a few percent — call it 10-30 px on this sensor instead of 45-90 — so both the correction and the interpolation it costs shrink. Filter M12 board lenses by the low-distortion type, or open the lens finder and compare:

M12 board lenses2.8 mm M12 board lens, 8 MP, F2.8 (LS-MBL-0018)LS-MBL-0018
Sensor format
1/2.5"
Mount
M12
$50.00View part
M12 board lenses3.3 mm, 1/2.3", 16 MP, M12-mount Low-Distortion M12 lens (LS-MBL-0159)LS-MBL-0159
Type
Low-distortion M12
Sensor format
1/2.3"
$109.00View part

Detection only: a presence check, a counting job or a classifier trained on production frames needs no geometric correction at all. Correcting those images adds a resample and buys nothing.

Too wide: the LS-MBL-0041 is a 1.45 mm M12 fisheye lens for 1/2.3" sensors. Past roughly 120° of field the polynomial model above stops describing the geometry, so a lens in that class calls for the equidistant fisheye model that ships in the same libraries. And when the job is true dimensional measurement at tight tolerance, the answer is not a better correction but telecentric depth of field — a telecentric lens removes the perspective you were about to correct, and the limits of that route are laid out in vision guided positioning accuracy limits.

What checks catch a bad profile before it ships?

Run these six checks before the profile touches production; together they take ten minutes and catch every failure mode in this guide, from a warped target to a focus ring that crept between the shoot and the fit.

  • Target flat against a straightedge, with no visible gap at any corner.
  • Focus ring locked and marked, and the paint mark unbroken.
  • Points landed in all four frame corners across at least four poses.
  • RMS under 0.5 px, with no single view above twice the mean.
  • A machined straight edge imaged across the frame stays within ±1 px of a straight line after correction.
  • The coefficient record carries the camera serial, lens model, focus note and date.

Ready to assemble the pair? The lens step of the system configurator runs the same focal-length arithmetic from your sensor and working distance, free expert support comes with every order if you want the capture plan reviewed, and the lenses topic page collects the related guides.

Questions

Can I turn my fitted coefficients into an LCP file for a photo raw converter?

Not directly. LCP files store geometry as a polynomial in field radius tied to a named camera and lens pair, while your fit yields normalized radial and tangential terms. For a machine-vision pipeline there is no reason to convert: keep fx, fy, cx, cy and the five distortion terms in your own configuration file and apply them with a remap. If a raw converter must load LCP files, its own profile-creation tool is the supported path, run on Windows or macOS.

Do the distortion coefficients change when I bin the sensor or crop an ROI?

The distortion terms are normalized to the sensor, so they carry over unchanged. The intrinsics do not: at 2x2 binning halve fx, fy, cx and cy; for a crop, subtract the crop offset from cx and cy before anything else. A full refit is only needed when the lens, the focus setting or the optical band changes.

How often should a board camera distortion profile be rechecked?

Recheck after any mechanical event: a refocus, a lens swap, a fall, a remounted locking screw, or shipping vibration that turned the M12 thread. Focus also drifts with temperature, which quietly shifts the effective focal length. A five-image spot check on a rigid target at a known distance catches a drifted profile in minutes. If the refitted fx moves more than about 0.5 percent, refit the full set.

Does undistorting the image make it softer?

Yes, by a fraction of a pixel: correction resamples every pixel, and the interpolation costs a little sharpness at the frame edges where the displacement is largest. Use a precomputed pixel map with a cubic interpolation and the loss stays well under a pixel. If edge sharpness is itself the product requirement, buy the low-distortion lens instead of correcting a standard one.

Why is my RMS stuck above one pixel even though the images look sharp?

Work down this order: the target is not flat (paper on a wall adds tenths of a pixel), the point finder is locking one pixel off on glare or on squares under about 10 pixels, focus was touched between poses, or every shot is front-on so the tangential terms are unconstrained. Retire the worst two or three frames by per-view error and refit; that alone commonly halves the RMS.

Is one profile valid at every working distance?

Only while the focus ring does not move. Distortion and focal length in pixels both shift as focus breathes, by roughly a percent between a far and a near station on a wide M12 lens. If the station focuses once and never moves, one profile holds. If operators refocus between jobs, keep one stored profile per focus setting and load it with the recipe.