AI INSPECTION

AI Quality Inspection in Manufacturing: When It Works and How to Build It

Cameras and trained models find defects that fixed rules miss, but only when the lighting, labels, timing and threshold are right. The decisions in the order you make them.

By EDWartens engineering team 18 November 2025 Updated 5 October 2026 8 min
AI Quality Inspection in Manufacturing: When It Works and How to Build It

AI quality inspection uses cameras and trained models to find defects that fixed rules miss, such as scratches on textured surfaces or varying cosmetic flaws. It works when the imaging is right, the defect standard is written down, and the reject signal reaches the PLC in time. Rule-based vision still does measuring and code reading better.

“How AI Machine Vision Compares to Rule-Based Systems in Complex Inspections” by Cognex Industrial Machine Vision, 2 min. Played from the creator's own YouTube channel; the video belongs to them.

Rules first, then deep learning

In this short lesson by Cognex Industrial Machine Vision, AI-based and rule-based vision are compared on complex inspections. The practical lesson for a project is to make the choice with evidence. Follow along, then check your work against these steps:

  1. List the checks. Break the inspection into separate questions: is the part present, is it the right size, is the label correct, is the surface free of scratches?
  2. Try rule-based tools first on each check (our guide to computer vision for industrial inspection explains them): thresholds, edges, blobs, pattern matching, calipers and code readers. They are fast, need no training images and are easy to explain.
  3. Measure recall on real defects. Run the rules on a set of photos where you know which parts are defective, and count how many defects were caught.
  4. Go deep only where rules fail measurably. If a rule catches too few scratches without rejecting good parts, that check is a candidate for a model. The others stay as rules.
  5. Pick the model type from the question. Classification answers good or bad. Detection says where each defect is. Segmentation outlines its exact shape. Anomaly detection, trained on good parts only, flags anything unusual when real defects are too rare to collect.

That test mirrors the practice task in the free course module this lesson belongs to: run a rule-based pipeline on your own photos, report scratch recall, and decide whether a model is justified.

Rule-based vision or deep learning?
Rule-based vision or deep learning?

Imaging comes before the model

A defect the camera cannot see clearly cannot be learnt. Settle the optics first.

Resolution. Divide the field of view by the sensor's pixel count to get the size of one pixel on the part. A 100 mm field on a sensor 2,448 pixels wide gives about 0.04 mm per pixel. A common rule of thumb is that the smallest defect should span at least three to four pixels, so a 0.2 mm scratch, at about five pixels, is visible here.

Lighting. Choose it for the defect. A backlight gives a sharp silhouette for dimensions and holes. Low-angle dark-field light makes scratches and embossing stand out. A diffuse dome tames glare on shiny or curved parts. Shield the station from ambient light, which changes through the day.

Exposure and motion. Blur equals line speed multiplied by exposure time. At 0.5 m/s, a 100 microsecond exposure blurs by 0.05 mm, about one pixel in the example above. Shorter exposure needs more light, which is why strobed lighting is common.

Triggering. Trigger from a photo-eye or an encoder, so each image catches the part in the same place.

The PLC side: timing and the reject

A correct verdict that arrives after the part has passed the rejector is useless. Build a timing budget from trigger to capture, transfer, inference, result and actuation, and compare it with the time the part takes to travel from the camera to the rejector. Measure inference time on the target hardware, not on a training GPU; edge AI in industrial automation covers choosing that hardware.

The handshake between PLC and vision system needs:

  • a trigger, and an image or part ID so results match the right part;
  • a result with a result valid bit, so the PLC never acts on a stale answer;
  • a heartbeat, so the PLC knows the vision system is alive;
  • part tracking to the rejector, usually with an encoder and a shift register or a FIFO in the PLC;
  • a safe default: if no valid result arrives in time, reject the part.

Recipe changes need the same care: the PLC and the vision system must agree which product is running.

Labels and the threshold

Write the defect standard with quality assurance. Which scratch length is a reject? Is a mark under the label acceptable? Include borderline examples with photos. Labellers who disagree produce a model that disagrees with itself.

Split by batch or by day, not by random image, or near-identical photos end up in both training and test sets and the score flatters the model.

Choose the threshold with QA. Every model trades escapes (defects passed as good) against false rejects (good parts scrapped). Sweep the threshold, show both rates at each setting, and let the people who own quality pick the operating point. Report recall per defect class, not one accuracy figure. If you are choosing a framework for training, see TensorFlow vs PyTorch for engineers.

After go-live

Performance drifts when lighting ages, a lens gets dirty, a supplier changes material or a new product variant arrives. Keep a golden sample set of known good and known bad parts, and run it through the station at the start of every shift. Audit a sample of rejects and passes regularly. Retrain with new images when the audit shows drift, and treat each new model version as a controlled change.

An AI inspection project, in order
An AI inspection project, in order

A free route to learn AI quality inspection

  1. Computer Vision with OpenCV teaches the rule-based tools: thresholds, morphology, edges, contours, measurement in millimetres, template matching and camera choice, in Google Colab.
  2. Deep Learning with TensorFlow and Keras covers CNNs, transfer learning on small datasets, Grad-CAM heatmaps and export for the edge.
  3. Machine Vision and Quality Inspection puts it together: camera, lens, lighting and trigger from the arithmetic, a timing budget and PLC handshake, a written labelling standard, a YOLO detector trained and thresholded with QA, and how to read an integrator's quotation.
  4. AI for Industrial Automation places vision among the other AI uses on a plant and covers the business case.

The Industrial AI engineer path groups these with predictive maintenance and plant data.

Start the courses

Every course is free in full, with lessons from independent creators credited on each course page, EDWartens notes, a practice task per module and one final assessment of 15 questions. Create a free account so your progress is saved.

The optional EDWartens Certificate of Completion is a small one-off fee, US$8.99 for a beginner course such as OpenCV and a little more for an intermediate one such as Machine Vision and Quality Inspection. Anyone can check it at edwartens.com/verification. It is not a Cognex or other vendor certification, and not an accredited qualification.

Take the free course

Questions

What is AI quality inspection?

It is automated visual inspection in which a trained model, usually a neural network, decides whether a part is good or where a defect is, from camera images. It complements rather than replaces rule-based machine vision.

When should I use deep learning instead of rule-based vision?

When rule-based tools have been tried and measurably fail, typically on scratches over textured surfaces, variable cosmetic defects or natural materials. Measurement, presence checks and code reading are usually better done with rules.

How many images do I need to train a defect detector?

There is no fixed number; it depends on how varied the parts and defects are. Transfer learning lets a small, well-labelled set go a long way, and anomaly detection can be trained on good parts only when defects are rare.

What matters more, the model or the lighting?

The lighting and optics. A defect the camera cannot see clearly cannot be learnt. Fix resolution, lens, lighting and exposure before collecting training images.

How does the vision system tell the PLC to reject a part?

Through a handshake: the PLC triggers the camera, the vision system returns a result with a valid bit and a heartbeat, and the PLC tracks the part to the rejector. If no valid result arrives in time, the safe default is to reject.

Sources

Written by the EDWartens engineering team for general education. Product names are trademarks of their owners; mentioning them does not imply endorsement. Prices and terms of other providers were checked on the date shown and can change.