AI Visual Inspection for Defect Detection: How It Works
AI visual inspection watches products with cameras and flags defects a human eye would miss. Here is how the station works, what it catches, and how to build one.
On this page
Short answer
AI visual inspection for defect detection uses cameras and a trained model to check every product on a line and flag scratches, cracks, missing parts and mislabels in real time. It catches faults that tired eyes miss, but it needs good lighting, clear defect definitions and a way to handle the parts it is unsure about.
What is AI visual inspection for defect detection?
AI visual inspection for defect detection is a system that photographs every product on a production line and uses a trained model to decide whether each one passes or fails. A camera takes a picture at a fixed point, the model looks for scratches, cracks, missing parts, wrong labels and other faults, and the line either lets the product through or sends it to a reject bin.
The point is not to replace people but to check what people cannot check well: every single item, at line speed, without getting tired. A person can inspect a sample; a camera system can inspect all of them, and it applies the same standard to the first item of the shift and the last.
| Defect type | What the camera sees | How the AI judges it |
|---|---|---|
| Scratch or crack | A thin dark or bright line | Shape and contrast against good parts |
| Missing part | An empty space or hole | Expected feature not found |
| Wrong label | Text or code that does not match | Reading the label and checking it |
| Wrong size or shape | Edges in the wrong place | Measuring against the design |
| Colour or finish fault | A patch that looks different | Comparing colour and texture |
The table shows the common fault types. Most factories start with one or two of them and add more once the first checks run well. For the detection method behind these checks, computer vision anomaly detection explains how models spot faults they were never shown.
Which defects can a camera actually catch?
A camera can catch any defect that changes how a product looks: scratches, cracks, dents, missing parts, wrong labels, bad print, wrong colour and parts in the wrong place. If a fault is visible in a photo, a model can usually learn to find it, provided it has enough examples of good parts and of the fault itself.
Some faults are hard. A defect inside a sealed product cannot be photographed, and a fault that looks identical to a normal variation will be missed or flagged wrongly. A scratch on a shiny surface can also hide from a camera if the light hits it the wrong way, which is why lighting matters as much as the model.
The practical test is simple: take photos of the fault and of good parts, and check whether a person can tell them apart in the photo. If a person cannot see the difference, the model probably cannot either, and the fix is better lighting or a different camera angle, not a better model.
What does an inspection station need?
An inspection station needs a camera, lighting, a trigger and a computer, all set up so every product is photographed the same way. The camera must be fixed in place, the product must pass through the same spot each time, and the light must fall the same way on every item, or the model will learn the lighting instead of the product.
Lighting is the part teams underestimate. A bright, even light from the right angle makes a scratch stand out; a glare makes it vanish. Many stations use a ring light or a dome light to spread the light evenly, and some use a dark background so the product edges are easy to find.
The trigger tells the camera when to take the photo, usually a sensor that sees the product arrive or a signal from the line itself. The computer runs the model and must answer fast enough that the line never waits: if a product passes every two seconds, the model must decide in well under two seconds, including the time to take and move the photo.
How does the AI decide pass or fail?
The AI decides pass or fail in one of two ways. A classification model learns from labelled examples of good and bad parts and sorts each new photo into pass or fail. An anomaly detection model learns only what good parts look like and flags anything different, which suits faults that are rare or hard to describe in advance.
Classification works best when the fault types are known and there are enough examples of each. Anomaly detection works best when new fault types appear and the team wants to catch them without waiting to collect examples. Many stations use both: anomaly detection to catch anything odd, and classification to name the fault it found.
Every decision also needs a threshold, the line between pass and fail. Set it too strict and good parts get rejected; set it too loose and faults slip through. The threshold is set by testing on real production photos and counting both kinds of error, then moving the line until the balance fits what the product needs.
How does inspection fit into the production line?
Inspection fits into the line at the point where the fault is cheapest to fix, which is usually right after the step that causes it. A scratch found at the end of the line means the whole product is wasted; the same scratch found right after polishing means only one step is redone.
The station must keep up with the line. If the line moves faster than the model can decide, products queue up or pass unchecked, and the system becomes a bottleneck instead of a help. Teams either speed up the model, add a second camera, or move the check to a slower part of the line.
Rejected parts need a clear path too. A reject bin, a rework station or a second check by a person all work, but the path must be planned before the system goes live, or rejected parts pile up beside the line. The data from rejections is also useful: it shows which faults appear most and where the process needs fixing, not just which parts to throw away.
How to build your first visual inspection system
Building a first visual inspection system is a small project, not a factory rebuild. Start with one product, one fault type and one camera, and prove the check works before adding more.
- Pick one fault. Choose the defect that costs the most when it reaches a customer, and check it first.
- Photograph good and bad parts. Collect several hundred photos of each, taken at the real station with the real lighting.
- Label the photos. Mark each photo pass or fail, and name the fault where you can, so the model learns the difference.
- Train and test on separate photos. Train on one set and test on photos the model has never seen, so the result is honest.
- Run it beside the line first. Let the system flag faults without rejecting anything, and compare its calls with a person's.
- Switch on rejection slowly. Start with the clearest faults, watch the false alarms, and widen the net as trust grows.
Teams that follow this order learn cheaply and keep control. Teams that try to check every fault on every product at once learn the same lessons at a much higher cost. For the wider method, how to implement anomaly detection covers the training and threshold steps in detail.
Example (hypothetical): a bottling line checks every bottle
Example (hypothetical): a bottling line fills 10,000 bottles per shift and wants to catch cracked caps before the bottles are packed. The team sets up one camera above the line, a ring light, and a model trained on 400 photos of good caps and 300 photos of cracked ones.
In the first week the system flags 120 bottles. A person checks each one and confirms 96 are really cracked, while 24 are fine bottles the model flagged wrongly. The team also finds 4 cracked caps the system missed, so out of 100 real cracks in the week, the system caught 96 and missed 4.
The numbers tell the team what to fix: the 24 false alarms cost a few minutes of re-checking, while the 4 missed cracks are the real risk. They add more photos of the missed crack type, retrain, and the misses fall to 1 in the next week. The point is not the numbers themselves, but that the team can measure the system and improve it one fault at a time.
What are the common mistakes?
The most common mistakes in AI visual inspection are bad lighting, too few training photos, and switching on automatic rejection before the system is proven.
- Bad lighting. A model cannot see what the light hides, so fix the lighting before blaming the model.
- Too few photos. A model trained on 50 photos of a fault will guess; one trained on 500 will decide.
- Testing on training photos. A model always looks good on photos it has already seen, so test only on new ones.
- Rejecting too early. Automatic rejection before the false-alarm rate is known throws away good products and trust.
- No plan for new faults. A new fault type will appear one day, so the system needs a way to collect its photos and retrain.
The teams that do this well treat inspection as a measurement system, not a magic box: they photograph, count, test and improve. For the vision basics behind it, what computer vision is explains how machines read images.
Key takeaways
- A camera system can check every product, where a person can only sample
- Lighting and a fixed camera position matter as much as the model
- Classification names known faults; anomaly detection catches new ones
- Set the pass-fail threshold by counting both kinds of error
- Start with one fault, run beside the line, and switch on rejection slowly
Frequently asked questions
What is AI visual inspection for defect detection?
It is a system that photographs every product on a line and uses a trained model to flag scratches, cracks, missing parts and mislabels in real time. It checks all of the products, not just a sample, and applies the same standard all shift.
Can AI visual inspection replace human inspectors?
Not fully. It replaces the repetitive checking of every item, but people are still needed for new fault types, borderline calls and the final say on rejected parts. Most factories use the system to shortlist, and people to decide.
How many photos does a visual inspection model need?
Several hundred photos of good parts and of each fault type is a practical starting point. Fewer photos lead to guessing, and the photos must come from the real station with the real lighting, not from a lab.
What is the difference between classification and anomaly detection?
Classification learns from labelled examples of good and bad parts and sorts each new photo into pass or fail. Anomaly detection learns only what good parts look like and flags anything different, which suits rare or new fault types.
Why does lighting matter so much for visual inspection?
A defect that the light hides cannot be seen by the camera or the model. Even, well-placed lighting makes scratches and cracks stand out, while glare or shadows can hide them completely, so lighting is fixed before the model is tuned.
What should I check first when building a visual inspection system?
Pick the single fault that costs the most when it reaches a customer, and prove the check on that one fault first. Add more fault types only after the first check runs well beside the line without rejecting anything.