Barcode and data-capture optics

Barcode Reading in Machine Vision: A Lens Guide for OCR, Document Scanning, and Biometrics

Pixel coverage, depth of field, and distortion control for reading codes, characters, pages, and faces: the optical margin that decoding software depends on.

By Max Henkart, Commonlands · Updated July 2026 · 10 min read

A board-level Commonlands M12 camera reads 1D barcodes and Data Matrix codes on a conveyor

Barcode reads, OCR, document scans, and biometric captures all fail for the same reason before software ever runs: the optics did not deliver enough pixels, sharp focus, or clean geometry on the feature that matters. The feature differs by task: the narrowest bar for 1D codes, the module for 2D codes, character x-height for OCR, the iris diameter for biometrics. Fix the sampling requirement first, using the decoder vendor's spec and your own read-rate testing. Then verify depth of field, distortion, and illumination against the real working distance.

What data-capture reading needs from the optics

Pixel coverage of the smallest feature

The decoder needs a minimum number of pixels across the narrowest element: the X dimension (narrowest bar or space) for 1D barcodes, the module for 2D Data Matrix and QR codes, character x-height for OCR, iris diameter for biometrics. Under-sampling that feature is one of the most common causes of read failures in new installations.

Contrast transfer at the feature's spatial frequency

Even with enough pixels, poor MTF at the feature's spatial frequency softens edges, so a megapixel rating alone does not qualify a lens. Check MTF at the sensor plane against your read-rate requirement rather than a fixed percentage.

Depth of field across the working-distance range

Conveyor sag, stacked labels, curved packaging, and stand-off variation all create a working-distance range the lens must hold focus across. A circle of confusion of about 1 pixel at the sensor is a geometric proxy, not a measured limit: usable depth of field depends on the lens's through-focus MTF. Use the depth of field calculator to estimate it, the depth of field guide for the derivation, and ask Commonlands for a measured table when fixture tolerance is tight.

Controlled distortion across the usable field

Distortion deforms bars, modules, characters, and geometry near the frame edges. Barrel (negative) or pincushion (positive) displacement is largest there. Near the center, most decoders and matchers tolerate it. A low-distortion lens cuts that risk and the correction burden that otherwise falls on software.

Illumination and exposure matched to the task

At line speed, long exposure smears features across pixels: a 250mm/s conveyor during a 2ms exposure creates 0.5mm of blur, enough to erase a 0.3mm bar. For biometric and document capture the constraint shifts to illumination uniformity and, for iris, a specific NIR wavelength. Size exposure and illumination to the aperture and the feature.

A Commonlands M12 lens images a Data Matrix code etched into a metal part
Low-angle light brings out dot-peen marks for direct part mark reading.

How 1D barcodes, 2D Data Matrix and QR codes, and direct-part-mark codes differ

Different code types make different demands on the optics and illumination, and sorting them out before selecting a lens avoids the mismatched designs Commonlands most often sees in support.

1D barcodes (Code 128, GS1-128, Code 39, ITF-14)

One-dimensional barcodes encode data along a single axis, so the lens only has to resolve along the reading axis. Blur perpendicular to the bars is tolerable. The driving parameter is the X dimension, the narrowest bar width, which runs from 0.25mm on small labels to 1mm or more on pallet codes.

2D Data Matrix and QR codes

Two-dimensional codes store data in both axes, so every module must resolve in both directions. That raises the bar on MTF uniformity across the full field, makes edge distortion a real failure mode, and requires uniform focus across the whole code. QR alignment markers tolerate perspective and rotation a little better than Data Matrix.

Direct-part-mark (DPM) codes

DPM codes are laser-etched, dot-peened, or chemically etched into metal, so contrast comes from surface texture, not ink. That contrast is much lower than on a printed label. MTF at the module frequency has to stay high without an aperture so small that diffraction eats the contrast, and the illumination (angled, dark-field, or coaxial with a polarizer) has to make shallow features visible at all.

A comparison of common failure modes

Failure symptom Likely optical cause First parameter to check Likely fix
Decode fails only near image edges Distortion or off-axis aberrations Distortion spec and edge MTF at the field coverage in use Use a lower-distortion lens; keep the code within the usable image circle
Decode fails at line speed but passes static Motion blur from long exposure Exposure time vs conveyor velocity in mm/s Reduce exposure time; add brighter or strobed illumination
Decode fails across a range of distances Depth of field too shallow Aperture setting vs 1-pixel CoC budget at the sensor Stop down within the diffraction limit; increase illumination to compensate
Intermittent failures on small codes or characters Pixel coverage below minimum threshold Pixels across the narrowest bar, module, or character height Reduce field of view, use a longer focal length, or move the camera closer
Decode fails only on shiny labels or metal DPM Specular glare washing out contrast Illumination angle and specular reflection geometry Switch to diffuse or angled illumination; add a bandpass filter matched to the LED source

How to choose the focal length and working distance for barcode reading

EFL = (WD × sensor dimension) / FOV EFL = effective focal length (mm) | WD = working distance (mm) | sensor dimension and FOV in mm, same axis

This is exact for rectilinear projection (Hecht, Optics, 5th ed., §5.2), not a thin-lens approximation. For distortion-corrected values at wide fields, use the field of view calculator.

A worked example: label reading on a packaging line

A 1/2.3" sensor (6.17mm × 4.55mm active area) reading a 60mm-wide label at 400mm needs an EFL near 400 × 6.17 / 60 = 41.1mm. With 4000 pixels across the 6.17mm width, each pixel covers 60 / 4000 = 0.015mm in the scene, so a 0.25mm X-dimension bar spans 0.25 / 0.015 = 16.7 pixels. Compare that against your decoder vendor's minimum sampling spec.

M12 lenses are typically usable from about 50mm to infinity uncorrected. C-mount lenses run from about 100mm to infinity, both varying by model. For close-range reading on small electronics, check each model's minimum object distance, measured from the front of the lens to the object. Not every datasheet publishes it. See the minimum detectable size guide for how pixel coverage and field of view interact at close range.

Lens selection for OCR and character reading

Pixel density and the 20-pixel rule

A practical threshold is at least 20 pixels across the x-height of the smallest character, the height of a lowercase x. For the all-caps alphanumerics common on industrial labels, x-height equals full character height. For mixed case, it is roughly half. Below about 10 pixels of x-height, accuracy collapses for most engine and font combinations.

To check a design, multiply the sensor pixel count in the relevant axis by x-height as a fraction of the scene dimension and compare to 20. A 1920-pixel axis over an 80mm scene with 4mm x-height gives 1920 × (4/80) = 96 pixels, well clear; at 0.8mm x-height it drops to 19, which is marginal. The fix is a longer focal length or a higher-resolution sensor, not a different engine.

Focal length and mount

Longer focal lengths earn their place when the camera cannot move closer and a shorter lens would render characters too small: license plates, overhead text, serial numbers at a fixed robot stand-off. Where geometry allows, moving closer with a shorter lens is usually better, since depth of field shrinks and vibration sensitivity grows with focal length.

M12 fits most compact OCR, and a low-distortion M12 such as the CIL052 gives -0.1% rectilinear distortion with the system built around its fixed F-number. C-mount wins when depth-of-field control matters, when the sensor exceeds the M12 image circle (typically above 1/1.8 inch, up to 2/3 inch for the largest-coverage designs such as the CIL064), or when it needs a longer focal length.

Lens selection for document scanning

Document scanning is a flat, static imaging problem. The lens must cover the full page at the working distance, resolve enough pixels for the detail required, and keep page geometry accurate enough that straight edges stay straight. A low-distortion fixed-focal lens is the right default. Telecentric optics are not needed here, and they are not a current Commonlands product.

Distortion and rolling shutter

Barrel or pincushion distortion is worst at the corners, exactly where a document's edges sit. Downstream requirements set the tolerance: tighter needs for dimensional accuracy, OCR bounding-box registration, or multi-page alignment call for lower distortion. The CIL052 reaches -0.1% rectilinear distortion for embedded page geometry, with comparable low-distortion C-mount options available. Rolling shutter is usually fine because the scene is static. Steady light avoids banding from pulsed sources.

Lenses for face and iris biometric capture

Iris imaging: NIR illumination on a small feature

The human iris is roughly 11-12mm across, and standards-oriented capture commonly targets on the order of 100 to 200 pixels across that diameter, because recognition depends on fine radial and furrow detail. Hitting that at a workable distance usually means a longer focal length or shorter working distance than face capture, since the iris fills a small fraction of the frame.

Iris also depends on illumination near 850nm, matched to the lens and sensor path: it reveals texture that visible light captures inconsistently and is far less sensitive to ambient lighting and eye color. That needs the standard NIR stack, no IR-cut filter in the path, a bandpass filter matched to the illuminator, and a lens that transmits 850nm. See 850nm vs 940nm for the tradeoff and NIR imaging in machine vision for the full stack.

Face recognition: even illumination and low distortion

Face recognition covers a larger feature, so pixel-coverage pressure is lower, but even illumination and low distortion dominate. A single off-axis source throws shadows that shift with subject position, and barrel or pincushion warps facial geometry (interpupillary distance, jaw width, feature spacing) near the edges where off-center subjects sit. Many systems add 850nm NIR so capture stays consistent day and night, which again needs an NIR-transmitting lens and matched bandpass filter.

Scope note

Commonlands does not publish or validate biometric matching-accuracy figures; those depend on the algorithm, enrollment quality, and population statistics, not the lens. This section covers the optical and illumination requirements the lens and filter stack must satisfy. Verify accuracy claims with the biometric software vendor.

Commonlands lens examples for data-capture applications

6mm Two Thirds Inch Lens

6mm C-Mount Lens 2/3" 5MP

$249.00

CIL530-F1.8-CMANIR — 5 in stock

Download .STPView Product
8mm C Mount Lens Kowa Computar 2/3"

8mm C-Mount Lens 2/3" 12MP

$149.00

CIL531-F2.8-CMANIR — 50 in stock

Download .STPView Product
16mm C-Mount Lens Kowa Computar Lucid Vision Edmund Optics

16mm C-Mount Lens 2/3" 12MP

$149.00

CIL533-F2.0-CMANIR — 14 in stock

Download .STPView Product
25mm C Mount Lens Amazon

25mm C-Mount Lens 2/3" 12MP

$149.00

CIL534-F2.0-CMANIR — 17 in stock

Download .STPView Product

Browse Machine Vision Lenses for Quality Inspection

Top lenses for barcode reading, OCR, and document scanning

Task Recommended lens Mount and EFL Why it fits Link
1D and 2D label reading on a line CIL064 large format M12, 6mm The 11mm image circle covers sensors up to 2/3", including 1/1.6" parts such as the IMX676, so pixel density on the code comes from sensor resolution across a wide 86° field. F/2.9 fixed, rated for 6MP at 3µm pitch. View CIL064
Close-range DPM and small codes CIL052 low distortion M12, 5.2mm A short EFL at a close working distance puts high pixel density on small dense codes, and -0.1% rectilinear distortion keeps modules decodable when they land near the frame edge. F/3.4 fixed, up to 1/1.8" sensors. View CIL052
OCR and document scanning CIL532 C-mount C-mount, 12mm +0.05% distortion across an 11.1mm image circle suits full-page geometry, and the F/2.0-F/16 adjustable iris trades aperture for depth of field on curved labels or uneven documents. Up to 2/3" sensors at 12MP. View CIL532
An overhead Commonlands M12 camera images a printed page for document scanning and OCR
Even flat-field illumination keeps characters sharp from corner to corner.

Frequently asked questions

What lens should I use for OCR in machine vision?

Start with a fixed focal length lens sized to put at least 20 pixels across the x-height of the smallest character. A low-distortion M12 lens such as the CIL052 works well at moderate working distances for embedded OCR and label reading. When the camera must stay back, a longer focal length preserves character size on the sensor. C-mount is preferred when an adjustable iris is needed for depth-of-field control, or when the sensor is larger than the M12 lens's image circle covers, typically above 1/1.8 inch.

What lens should I use for document scanning in machine vision?

Start with document size, working distance, and sensor size, then calculate the focal length so the full page fills the sensor field at that working distance. Choose a low-distortion fixed focal lens matched to those numbers rather than the widest lens that technically fits. For embedded setups, a low-distortion M12 lens such as the CIL052 is practical. For bench or archival scanning, where aperture control and larger sensors matter, a C-mount lens gives more control.

What lens is needed for iris recognition?

Iris recognition needs an NIR-transmitting lens paired with roughly 850nm illumination and a matching bandpass filter, sized to put enough pixels across the iris diameter (commonly cited targets run from about 100 to 200 pixels across the iris for standards-grade capture). The lens and filter stack must pass 850nm efficiently. A standard visible-only IR-cut path blocks the wavelength the sensor needs. See the Commonlands NIR imaging guide for the full filter and illumination stack.

What is different about reading 1D barcodes versus Data Matrix codes?

1D barcodes encode data in bars along one axis and can be decoded from a single scan line, tolerating blur in the perpendicular direction. The driving parameter is the X dimension, the narrowest bar width. Data Matrix and QR codes encode data in both axes, so every module must be resolvable in two directions, which raises requirements on MTF uniformity, distortion, and focus quality across the full field the code occupies.

What is needed for face recognition camera optics?

Face recognition needs even illumination across the capture volume, low distortion so facial geometry is not warped near the frame edges, and enough pixels across the interpupillary distance or face width for the matching algorithm in use. Many access-control and identity systems add NIR illumination around 850nm so capture is consistent regardless of ambient visible lighting, which requires a lens and filter path that transmits that wavelength.

Need help matching a lens to a data-capture application?

Describe the code type, character size, document geometry, or biometric modality, along with working distance, sensor, and line speed. Commonlands engineering can work through pixel coverage, depth of field, distortion, and illumination requirements before you commit to hardware.