Computer Vision Anomaly Detection: How It Spots Defects
A computer vision anomaly detection system photographs each item and flags the ones that differ from normal. Here is how the pipeline works and how to build one.
On this page
Short answer
A computer vision anomaly detection system is software that inspects images or video and flags anything that differs from what it has learned as normal. It spots defects on production lines, unusual activity on camera feeds and changes in medical scans, and it routes flagged images to a human reviewer.
What is a computer vision anomaly detection system?
A computer vision anomaly detection system is software that looks at images or video and flags anything that differs from normal. It learns what normal looks like from examples, then scores each new image and raises an alert when the score passes a set limit.
The system works on pictures, not on numbers in a table. A camera on a production line photographs each item, and the software compares the photo with the patterns it learned from good items. A crack, a missing part or a wrong label shows up as a visual difference the model can measure.
Teams use these systems where eyes alone are too slow or too tired to check every item. A line that makes thousands of parts an hour cannot be checked by hand, but a camera and a model can look at each one the same way, every time. For the general idea behind this kind of software, what anomaly detection is explains the basic concept.
| Where it is used | What the camera watches | What counts as an anomaly |
|---|---|---|
| Manufacturing | Parts on a production line | Cracks, dents, missing screws |
| Surveillance | Camera feeds in a building | Movement in a closed area |
| Medical imaging | Scans and X-rays | Changes from a healthy scan |
| Retail | Shelves and stock rooms | Empty shelves, misplaced goods |
How does the vision pipeline work?
The pipeline moves in five stages: capture, prepare, score, decide and act. A camera captures the image, the software prepares it, the model scores it, a rule decides whether the score counts as an anomaly, and the system acts on the decision.
Preparation matters because cameras see the world unevenly. The software crops the image to the part that matters, adjusts brightness and size, and removes noise so the model compares like with like. A model trained on clean, centred images will miss defects in a shifted or dark photo.
Scoring is the heart of the system. The model turns the image into a number that says how far it sits from normal. A low score means the image looks ordinary; a high score means something is off. The team sets a limit, and anything above it is flagged for a human to check.
Acting on the flag is a separate step. The system can stop a conveyor, send a photo to a reviewer, or log the event for later review. The best setups keep a human in the loop for the first weeks, so the team learns which flags are real defects and which are harmless changes in light or position.
Which detection methods do teams use?
Three methods cover most systems: reconstruction, feature comparison and supervised classification. Each one suits a different kind of defect and a different amount of labelled data.
Reconstruction models learn to rebuild normal images. The model is trained only on good examples, so when it sees a cracked part it rebuilds it badly, and the size of the error becomes the anomaly score. This method needs no examples of defects, which is useful because defects are rare by definition.
Feature comparison works by measuring how far a new image sits from the normal group. The model turns each image into a set of features, such as edges, textures and shapes, and compares the new image with the range seen in training. Images that fall outside that range are flagged.
Supervised classification needs labelled examples of both good and bad items. It works well when a team has a library of known defect types, such as scratches, dents or missing screws, and wants the system to name the defect as well as find it. The cost is the labelling work, which can take weeks on a large product range.
How do you train a model on normal images?
Training starts with a set of normal images that show the full range of acceptable variation. A good set includes different lighting, small shifts in position and the normal wear that appears on real products, so the model does not flag ordinary change as a defect.
The size of the set matters less than its coverage. A few hundred well-chosen images that show every normal variation often beat thousands of near-identical photos. Teams usually start with what they have, test the model, and add images for the cases it gets wrong.
Labelling is light for this kind of system because most methods train on normal images only. The team checks that each training image really is normal, removes blurred or misframed shots, and keeps a separate test set of normal and defective images to measure how well the model works.
Retraining is part of running the system, not a one-off job. When a product changes shape, a camera moves, or a new normal variation appears, the team adds fresh images and retrains. A model that is never updated slowly drifts away from the line it is meant to watch.
How do you set thresholds and cut false alarms?
A threshold is the score above which an image counts as an anomaly, and setting it is a trade-off. A low threshold catches more defects but also flags more good items, while a high threshold misses defects that sit close to normal.
The practical way to set it is to run the model on a test set with known good and bad images, then pick the threshold that catches the defects that matter while keeping false alarms at a level the team can handle. A line that stops every few minutes for false alarms will soon have its alerts ignored.
Teams reduce false alarms by checking the image before the model sees it. A photo taken at the wrong angle or with a shadow across the part will score high for reasons that have nothing to do with the product. Fixing the camera mount, the lighting or the crop often cuts false alarms more than tuning the model does.
It also helps to sort flags by score instead of treating every flag the same. High-score images go to a reviewer at once, while borderline images are logged and reviewed in a batch. This keeps the line moving while the team still sees the cases that might matter.
How to build your first system
A first system should be small: one camera, one product, one defect type. A narrow pilot proves the idea and teaches the team what the images really look like before they spend on a full rollout.
- Pick one defect that costs money. Choose a fault that causes rework, returns or complaints, so the pilot has a clear value to measure.
- Fix the camera and lighting first. Mount the camera firmly, light the part evenly, and check that every photo frames the part the same way.
- Collect normal images. Photograph several hundred good items across shifts and lighting changes, and remove any blurred or misframed shots.
- Train a first model on normal images only. Use a reconstruction or feature-comparison method, since it needs no defect examples.
- Test on known good and bad items. Run the model on a held-out set, set the threshold, and count how many defects it catches and how many good items it flags.
- Put a human in the loop. Route flags to a reviewer for the first weeks, log every decision, and retrain with the images the model got wrong.
Once the pilot catches the target defect with few false alarms, the team can add more defect types or more cameras. Each addition follows the same pattern: collect images, retrain, test, and watch the flags. A staged guide for the wider topic is covered by how to implement anomaly detection.
Example (hypothetical): a factory checks bottle caps
Example (hypothetical): a drinks factory fills 12,000 bottles an hour and checks each cap with a camera. Before the system, two inspectors sampled 200 bottles an hour and missed most faulty caps, so about 90 faulty bottles a day reached customers.
The team mounts a camera over the line and trains a model on 800 photos of good caps. In the first week the system flags 140 bottles a day. Reviewers confirm 96 are real faults and 44 are false alarms caused by glare, so the team fixes the lighting and the false alarms fall to 12 a day.
The arithmetic is simple: 96 real faults caught out of about 100 faulty bottles a day means the system catches 96 in 100, while the old sampling caught about 2 in 100. Customer complaints about faulty caps fall from 90 a day to 4, and the two inspectors move to checking the flagged bottles instead of sampling at random.
What are the common mistakes?
The most common mistakes in computer vision anomaly detection are training on too narrow a set of normal images, skipping the camera setup, and setting the threshold once and never revisiting it.
- Training on identical images. A model trained on photos from one shift will flag normal change from another shift as defects.
- Ignoring the camera and lighting. A loose mount or a shadow can create more false alarms than any model error.
- Setting the threshold by guesswork. Without a test set of known good and bad images, the threshold is a guess, and the team learns it is wrong only after defects slip through.
- Expecting the model to name the defect. Most anomaly systems only say that something is off; naming the fault needs labelled examples and a different model.
- Never retraining. Products change, cameras move and lighting ages, so a model left alone slowly stops matching the line it watches.
Teams that avoid these mistakes treat the system as a loop: collect images, train, test, watch the flags and retrain. The model is only one part; the camera, the threshold and the review process matter just as much. For the wider picture, what computer vision is explains how cameras and models work together.
Key takeaways
- A vision anomaly system flags images that differ from learned normal patterns
- The pipeline is capture, prepare, score, decide and act
- Reconstruction and feature comparison need only normal images to train
- Camera setup and lighting cause more false alarms than model errors
- Start with one defect, a human reviewer and a small pilot
Frequently asked questions
What is a computer vision anomaly detection system?
It is software that inspects images or video and flags anything that differs from the normal patterns it learned during training. Cameras capture each item or scene, the model scores it, and anything above a set threshold goes to a human reviewer.
How is it different from normal anomaly detection?
Normal anomaly detection works on numbers, such as sensor readings or transaction amounts. A vision system works on pictures, so it can spot cracks, missing parts, wrong labels and other faults that only show up visually.
Do I need examples of defects to train it?
Not for most methods. Reconstruction and feature-comparison models train on normal images only, which is useful because defects are rare. You only need defect examples if you want the system to name the fault as well as find it.
How many images do I need to start?
A few hundred well-chosen photos of normal items are usually enough for a first pilot, as long as they cover the normal variation in lighting, position and wear. Add images for the cases the model gets wrong, rather than collecting thousands of near-identical shots.
What causes most false alarms?
Camera and lighting problems cause most of them: a shifted camera, a shadow, glare or a misframed photo will score high for reasons that have nothing to do with the product. Fixing the setup usually cuts false alarms more than tuning the model does.
Can it replace human inspectors?
No, it changes their job. The system checks every item and routes only the suspicious ones to a person, so inspectors spend their time on real decisions instead of watching thousands of identical parts pass by.