Most AI visual inspection projects do not fail on the model. They fail around week ten of the pilot, when a system that scored well on a folder of photos meets the real line: a part every second, lighting that slowly drifts, a reject gate that fires a fraction late, and a quality team that cannot agree whether a 0.3 mm scratch on a hidden face is a defect at all.
This guide covers how AI visual inspection systems for manufacturing are actually built: when rule-based vision is still the better tool, anomaly detection versus supervised models, the acquisition chain, defect data, setting the threshold from the cost of errors, PLC integration, and a pilot plan that ends in a decision rather than a demo.
Rule-Based Vision, Supervised Deep Learning or Anomaly Detection
Three families of technique sit behind an inspection station. The choice follows from the defect and the data you can realistically collect.
| Approach | How it decides | Training data | Strong at | Weak at |
|---|---|---|---|---|
| Rule-based machine vision | Configured tools: edges, blobs, pattern match, calipers | A few reference images | Dimensions, presence checks, alignment, code reading | Cosmetic defects with no fixed shape |
| Supervised detection or segmentation | Learns the defect classes it was shown | Hundreds of labelled examples per class | Known, recurring defects; naming the defect type | Defects absent from training |
| Anomaly detection | Models normal appearance and scores deviation | Good parts only; defects for validation | Rare or unpredictable defects; new lines | Acceptable variation that looks unusual, such as reflections |
For a bore diameter within 0.02 mm, a connector in a fixed location or a readable date code, rule-based tools are faster to commission, deterministic and easier to document for an auditor. Many good systems are hybrids: rules locate and gauge the part, a learned model judges the surface. Smart cameras such as Cognex’s In-Sight 3800 combine both kinds of tool in one device.
The usual starting points are PaDiM (Defard et al., 2020) and PatchCore (Roth et al., CVPR 2022). Both reuse features from a network pre-trained on ImageNet. PaDiM fits a distribution to the features at each patch position; PatchCore keeps a subsampled memory bank of normal patch features and scores each patch by distance to its nearest neighbour. Both output a heat map and both are in the open-source Anomalib library.
The standard benchmark, MVTec AD, has 5,354 images across 15 categories, and leading methods report image-level AUROC above 99 percent on it. The benchmark is nearly solved; your line is not. On the harder MVTec AD 2 (2025), with transparent parts, backlit and dark-field scenes and tiny defects, its authors report state-of-the-art methods below 60 percent average AU-PRO. Both datasets are licensed for non-commercial use only: use them to compare methods, not to train a product.
The Image Acquisition Chain for AI Visual Inspection
The general case for fixing optics before the model is set out in the guide to embedded computer vision hardware. For inspection, lighting geometry matters most, because it decides whether a defect produces any contrast.
- Bright-field ring or bar light: print, labels and colour on matt surfaces
- Low-angle dark-field: scratches and dents, which catch the light against a dark surface
- Diffuse dome or coaxial: shiny, curved or machined surfaces where direct light causes glare
- Backlight: silhouettes, hole positions and fill levels in translucent containers
- Laser line or structured light: warp, sink marks and other height defects invisible in 2D
Test them on real limit samples before buying anything else.
Suppose parts move at 0.5 m/s and the camera images a 100 mm field across 2,000 pixels, so each pixel covers 0.05 mm. A 1 ms exposure gives 0.5 mm of movement: 10 pixels of blur, enough to erase a fine scratch. Holding blur to one pixel needs a 100 µs exposure and strobed lighting many times brighter than continuous light. Use a global shutter sensor, trigger from a photo-eye or encoder, and use an encoder-driven line-scan camera for continuous material such as film.
At 3,600 parts an hour the takt time is one second, but distance sets the deadline. With the reject gate 300 mm downstream at 0.5 m/s, the result must reach the PLC within 600 ms of the trigger, minus the actuator’s measured response time. Exposure, transfer over GigE Vision or USB3 Vision, inference and messaging all come out of that budget.
Defect Data, Labelling and Golden Samples
Defects are rare, which is what a capable process looks like. A line making 3,600 parts an hour at a 0.3 percent defect rate produces about 11 bad parts an hour across perhaps ten defect types. The dangerous types may appear monthly, so 200 real examples can take a year, which is why teams stage defects on scrap parts.
The harder problem is agreement between inspectors, covered in which computer vision problems are actually suitable. Once people agree, turn the standard into something a model can be held to.
Setting the Operating Threshold From the Cost of Errors
Every inspection model outputs a score, and the threshold trades two errors. A false reject is a good part rejected; an escape is a defective part passed. Choose it from what each error costs.
An illustrative example: a line makes 400,000 parts a month at a 0.5 percent defect rate, so 398,000 good and 2,000 defective. A false reject costs $2 in manual re-inspection. An escape costs $150 once complaints, sorting at the customer and returns are counted. Rates were measured on a validation set.
| Threshold | False reject rate | Escape rate | False rejects | Escapes | False reject cost | Escape cost | Monthly total |
|---|---|---|---|---|---|---|---|
| Lenient | 0.2% | 8% | 796 | 160 | $1,592 | $24,000 | $25,592 |
| Moderate | 0.5% | 3% | 1,990 | 60 | $3,980 | $9,000 | $12,980 |
| Tight | 1.5% | 1% | 5,970 | 20 | $11,940 | $3,000 | $14,940 |
| Strict | 4% | 0.3% | 15,920 | 6 | $31,840 | $900 | $32,740 |
At $150 per escape, moderate is cheapest. Now suppose the part goes into a safety-relevant assembly and an escape costs $1,500. Moderate becomes $93,980, tight $41,940 and strict $40,840. Strict now wins, and the re-inspection station must absorb about 16,000 parts a month, so staff it. The threshold depends on the cost of being wrong, not on the model; the same arithmetic drives human-in-the-loop AI automation, and a re-inspection station is exactly that pattern. In practice, set thresholds per defect class: strict for cracks and contamination, lenient for cosmetic marks the customer accepts.
If a model misses none of n defective samples, the 95 percent upper bound on its true escape rate is roughly 3/n. With 50 defects and no misses, you can only claim below about 6 percent. Claiming below 1 percent needs at least 300, and the strict row’s 0.3 percent needs about a thousand. Anomaly detection trains without defects, but it cannot be validated without them.
Accuracy is not a specification. A false reject rate and an escape rate, each at a stated threshold, for each defect class, is.
Edge Hardware and PLC Integration for Inspection Systems
The decision must arrive within milliseconds, so inspection runs at the edge on one of three hardware options.
- Smart camera with on-board deep learning: one station, simplest wiring, limited model choice and throughput
- Embedded GPU module: the NVIDIA Jetson Orin family on an industrial carrier board, or the newer Jetson Thor modules (T4000, T5000) for many cameras or large models; sustained thermal performance in the enclosure must be tested
- Industrial PC with a GPU: several cameras, the largest models and the easiest development; needs cabinet space, and a consumer GPU’s product life may be shorter than the line’s
Hitting the time budget on a module is mostly quantisation and operator work, covered in edge AI optimisation techniques. Packaging, versioning and remotely updating models across stations is standard edge AI development work.
Never fire the reject from a timer. Tag each result with the trigger count, track the part in the PLC by encoder position or shift register, and actuate when that part reaches the gate. Add a sensor confirming the part entered the reject bin. If no result arrives in time, or the heartbeat between vision system and PLC stops, reject the part or stop the line; never pass by default.
Use digital I/O or the line’s fieldbus, such as PROFINET or EtherNet/IP, for the time-critical reject signal, and OPC UA for slower data: results, recipe changes at changeover and counters for the MES. The OPC UA for Machine Vision companion specification (OPC 40100) defines a standard information model for this. Store images of every reject and a sample of passes, linked to serial or batch, for the traceability described in IoT in manufacturing.
Drift, Retraining and an AI Visual Inspection Pilot Plan
Inspection systems degrade quietly as LEDs dim, lenses collect dust and suppliers change surface finish. Monitor image brightness and sharpness, the score distribution of passed parts, reject rate per defect class and the share of rejects overturned at re-inspection. A rising overturn rate is usually the first sign.
Retrain only from reviewed labels, score candidates on the frozen test set at the current false reject rate, run them in shadow before switching and keep the previous version for rollback. In regulated production, a new model is a process change and goes through change control like a new fixture.
Most pilots stall because nobody wrote down what success looks like, so they cannot end. A plan that ends in a go or no-go decision:
The same discipline carries over to counting, OCR and guidance, the other common factory tasks in computer vision development services.
Frequently Asked Questions
Conclusion
A working inspection system is a chain: lighting that creates contrast, an exposure that freezes the part, a defect standard people agree on, a threshold set from the cost of each error, a PLC handshake that fails safe, and an owner who watches for drift. The model is one link, and rarely the one that breaks. Pilots that fix acceptance criteria and failure modes before the first image is captured are the ones that reach production.
We build AI visual inspection from camera and lighting selection through to PLC and MES integration; see our computer vision development services.
