When an inspection system misses a defect, the camera usually takes the blame. More often the result was decided earlier, by a lens picked from a catalogue after the camera — and no software can recover detail the optics never delivered.
In most machine vision projects the camera is chosen first. It carries the impressive specification — the megapixels, the frame rate, the interface — and it is the part that appears in the quotation as a line item with a brand name. The lens is picked afterwards to fit the mount and the budget, and the lighting is often left to commissioning. Then the system goes live, a defect that is plainly visible to the human eye slips through, and the camera is blamed. In our experience the camera is rarely the problem. The inspection was decided by the lens and the light before a single line of image-processing code was written, and software cannot recover detail that the optics never put on the sensor.
Start from the defect, not the camera
The right order runs backwards from the part. What is the smallest feature the system must detect or measure, how large is the area it must see, and how far away can the camera sit? Those three numbers, plus the sensor, decide almost everything else. Take a common 5-megapixel sensor with 2448 × 2048 pixels of 3.45 µm. Its active area is about 8.4 × 7.1 mm. If the field of view has to be 100 mm wide, each pixel covers roughly 41 µm of the part. A 0.1 mm scratch will then land on two or three pixels — enough to notice on a good day, not enough to detect reliably across variations in lighting, part position and surface finish.
Useful rules of thumb follow from that arithmetic. For reliable detection, the smallest defect should cover at least three to four pixels. For measurement, sub-pixel algorithms improve repeatability, but the old metrology rule still applies: the resolution of the measurement should be about a tenth of the tolerance being checked. A ±0.05 mm tolerance therefore wants something like 10 µm per pixel, which on the same sensor means a field of view of about 25 mm, not 100 mm. The conclusion is uncomfortable but important: sometimes the correct answer is not a better camera but two cameras, or a smaller field of view with the part presented more precisely.
Magnification, focal length and working distance
Once the field of view is fixed, the lens has a clear job: to map that field onto the sensor. The ratio between the two is the optical magnification — in the example, 8.4 mm of sensor over 100 mm of part, about 0.084. The focal length that achieves it depends on the working distance, and a thin-lens approximation is close enough for a first choice: the focal length is roughly the object distance multiplied by the magnification, divided by one plus the magnification. A 25 mm lens therefore gives our 100 mm field at a little over 300 mm from the part; a 12 mm lens gives it at around 150 mm; a 50 mm lens needs more than 600 mm. Real lenses deviate from the thin-lens model, so the figures are confirmed against the lens maker’s data, but the direction never changes. Short focal lengths mean compact cells and more distortion; long focal lengths mean more space and flatter perspective.
Two constraints are easy to overlook. The lens must be designed for the sensor format, because its image circle has to cover the whole diagonal: a lens intended for a 2/3-inch sensor fitted to a larger 1.1-inch sensor will darken and blur the corners, and the corners are exactly where parts tend to sit when a conveyor wanders. And the mount must match. C-mount lenses sit 17.526 mm from the sensor and CS-mount lenses 12.526 mm, so the wrong combination will not focus at all, or will focus only with a spacer ring somebody fitted late one night and never documented.
The lens has a resolution too
Megapixels describe the sensor. The lens has its own resolving power, usually shown as an MTF curve: how much contrast it preserves at a given number of line pairs per millimetre. A sensor with 3.45 µm pixels has a Nyquist frequency of about 145 line pairs per millimetre. A lens designed for the larger pixels of an older sensor may deliver only half the contrast at those frequencies, which means the expensive 5-megapixel camera is effectively recording a softened image worthy of a 2-megapixel one. Fine edges spread across neighbouring pixels, a hairline crack loses its contrast, and the threshold that worked on the bench fails on the line. The fix is to choose a lens rated for the pixel size of the sensor, and to check its MTF at the edge of the field, not only in the centre.
Aperture is the next trade-off, and it is governed by physics rather than by quality of manufacture. Closing the iris increases depth of field, which is tempting when parts arrive at slightly different heights. But every aperture diffracts light into a small disc rather than a point, and the diameter of that disc grows with the f-number. For green light at f/8 it is about 11 µm — three pixels wide on a 3.45 µm sensor. At f/4 it is about half that. Stopping down for depth therefore costs sharpness, and beyond a certain point no lens can avoid it. The better answer to height variation is often mechanical: present the part at a consistent height, or accept a shallower depth of field and focus precisely.
Distortion, perspective and telecentric lenses
Every ordinary lens — the kind called entocentric — sees the world in perspective. Objects closer to the lens look larger, and the sides of a tall part become visible at the edge of the field. For presence checks this rarely matters. For measurement it matters a great deal: if a part sits 1 mm higher than it did during calibration, a 25 mm lens at 300 mm will report it about a third of a percent larger, which on a 100 mm dimension is more than 0.3 mm — far outside most tolerances. Lens distortion adds to this, bending straight lines towards the corners, usually as barrel distortion at short focal lengths.
Distortion can be corrected in software with a calibration target, and it should be. But the calibration is only valid for the exact focus and aperture settings at which it was taken, which is why we lock both rings with their set screws and mark them before a system is signed off. Perspective error cannot be corrected the same way, because the software does not know how high each part sits. That is the job of a telecentric lens, which accepts only rays parallel to its axis, so magnification stays constant across a defined depth range and the size of the part no longer depends on its height. Telecentric lenses are larger, heavier and more expensive — the front element must be at least as wide as the field of view — and they are the correct choice for precise dimensional gauging, not for every inspection.
Light and lens work as one system
The lens also decides what the lighting has to achieve. A backlight turns a part into a sharp silhouette for edge measurement; a dome light removes reflections from shiny, curved surfaces; a low-angle ring light makes a scratch or an embossed character stand out against a flat face. Whatever the light, a bandpass filter on the lens matched to the LED wavelength blocks ambient light from windows and neighbouring machines, and working at a single wavelength also removes chromatic aberration, since a lens can focus only one colour perfectly at a time. A pair of polarisers can suppress glare on metal and plastic. These are small optical components costing a fraction of the camera, and they are often the difference between an algorithm that needs constant retuning and one that is still running unchanged a year later.
What to ask for in a vision proposal
When we review or quote an inspection system, the optical layout comes before the software. A proposal worth trusting states the smallest feature and the tolerance, the field of view and the resulting size of one pixel on the part, the sensor format and pixel size, the lens focal length, working distance, aperture and depth of field, whether a telecentric lens is needed, and the lighting geometry with its wavelength and filter. It also states what happens when the part moves: the position tolerance of the presentation, and how much of the field is reserved for it.
None of this is exotic. It is a page of arithmetic and a few datasheets. But it is the page that decides whether a vision system becomes a dependable part of the line or a camera that operators learn to bypass. The camera captures the image. The lens decides what there is to capture.
— GANI Engineering engineering team
